Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- ifstream fin("rumbal.in");
- ofstream fout("rumbal.out");
- int n, m, k;
- char ch, depl;
- char s[200005];
- int x[200005];
- int main()
- {
- fin >> n >> m;
- for (int i = 1; i <= n; i++)
- {
- fin >> ch;
- s[i] = ch;
- x[i] = 1;
- }
- for (int i = 1; i <= m; i++)
- {
- fin >> ch >> depl;
- if (depl == 'D')
- {
- for (int j = 1; j <= n; j++)
- {
- if (s[j] == ch)
- {
- if (j == n)
- {
- k += x[j];
- x[j] = 0;
- }
- else if(x[j])
- {
- x[j+1] += x[j];
- x[j] = 0;
- }
- }
- }
- }
- else
- {
- for (int j = 1; j <= n; j++)
- {
- if (s[j] == ch)
- {
- if (j == 1)
- {
- k += x[j];
- x[j] = 0;
- }
- else if (x[j])
- {
- x[j-1] += x[j];
- x[j] = 0;
- }
- }
- }
- }
- }
- fout << n - k;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement