Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * author: raghuvanshraj
- * created: 18.02.2020 06:54:07 PM
- **/
- #include <bits/stdc++.h>
- #define MOD 1000000007
- #define init_arr(arr,n,val) for (int i = 0; i < n; ++i) arr[i] = val
- #define init_arr2d(arr,n,m,val) for (int i = 0; i < n; ++i) for (int j = 0; j < m; ++j) arr[i][j] = val
- #define init_arr3d(arr,n,m,l,val) for (int i = 0; i < n; ++i) for (int j = 0; j < n; ++j) for (int k = 0; k < l; ++k) arr[i][j][k] = val
- #define input_arr(arr,n) for (int i = 0; i < n; ++i) cin >> arr[i];
- #define input_arr2d(arr,n,m) for (int i = 0; i < n; ++i) for (int j = 0; j < m; ++j) cin >> arr[i][j];
- #define input_arr3d(arr,n,m,l,val) for (int i = 0; i < n; ++i) for (int j = 0; j < n; ++j) for (int k = 0; k < l; ++k) cin >> arr[i][j][k];
- #define print_arr(arr,n) for (int i = 0; i < n; ++i) cout << arr[i] << ' '; cout << endl
- #define print_arr2d(arr,n,m) for (int i = 0; i < n; ++i) { for (int j = 0; j < m; ++j) cout << arr[i][j] << ' '; cout << endl; }
- #define all(v) v.begin(), v.end()
- #define dec(a,t,n) t *a = new t[n]()
- #define dec2d(a,t,n,m) t **a = new t*[n](); for (int i = 0; i < n; ++i) a[i] = new t[m]()
- #define pb push_back
- #define mp make_pair
- #define ff first
- #define ss second
- using namespace std;
- typedef long long ll;
- typedef unsigned long ul;
- typedef unsigned long long ull;
- typedef long double ld;
- typedef vector<int> vi;
- typedef vector<string> vs;
- typedef queue<int> qi;
- typedef priority_queue<int> max_heap;
- typedef priority_queue<int, vector<int>, greater<int>> min_heap;
- typedef pair<int,int> pii;
- typedef pair<string,int> psi;
- typedef map<string,int> msi;
- typedef map<int,int> mii;
- typedef unordered_map<string,int> umsi;
- typedef unordered_map<int,int> umii;
- typedef set<int> si;
- typedef unordered_set<int> usi;
- template <
- typename T,
- typename = typename enable_if<is_arithmetic<T>::value, T>::type,
- typename U,
- typename = typename enable_if<is_arithmetic<T>::value, T>::type
- >
- pair<T,U> operator+(const pair<T,U> &a, const pair<T,U> &b) {
- return {a.first + b.first, a.second + b.second};
- }
- template <
- typename T,
- typename = typename enable_if<is_arithmetic<T>::value, T>::type,
- typename U,
- typename = typename enable_if<is_arithmetic<T>::value, T>::type
- >
- pair<T,U> operator-(const pair<T,U> &a, const pair<T,U> &b) {
- return {a.first - b.first, a.second - b.second};
- }
- int main(int argc, char const *argv[]) {
- ios::sync_with_stdio(false);
- cin.tie(0);
- int n,k;
- cin >> n >> k;
- string s;
- cin >> s;
- set<char> available;
- while (k--) {
- char ch;
- cin >> ch;
- available.insert(ch);
- }
- vector<int> end_here(n);
- init_arr(end_here, n, i+1);
- int curr_minus = 0;
- for (int i = 0; i < n; ++i) {
- end_here[i] -= curr_minus;
- if (available.find(s[i]) == available.end()) {
- end_here[i] = 0;
- curr_minus = i+1;
- }
- }
- long ans = 0;
- for (int i = 0; i < n; ++i) {
- ans += (long)end_here[i];
- }
- cout << ans;
- return 0;
- }
Add Comment
Please, Sign In to add comment