Last active
August 29, 2015 14:13
-
-
Save Vicfred/3e0b27763130e23bf74b to your computer and use it in GitHub Desktop.
IOI06 The Deciphering of Mayan Writing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //http://www.spoj.com/OI/problems/DMAYA/ | |
| #include <cstdio> | |
| #include <cstdlib> | |
| #include <cstring> | |
| #include <queue> | |
| using namespace std; | |
| int main () { | |
| int g, sz; | |
| char W[3001], S[3000001]; | |
| scanf("%d %d\n", &g, &sz); | |
| scanf("%s %s\n", W, S); | |
| int buw[128],bus[128]; | |
| memset(buw,(0),sizeof(buw)); | |
| memset(bus,(0),sizeof(bus)); | |
| for(int i = 0; i < g; i++) | |
| buw[W[i]-'0']++; | |
| queue<char> q; | |
| int count = 0; | |
| char c; | |
| for(int i = 0; i < sz; i++) { | |
| q.push(S[i]); | |
| ++bus[S[i]-'0']; | |
| while(bus[S[i]-'0'] > buw[S[i]-'0']) { | |
| c = q.front(); | |
| q.pop(); | |
| --bus[c-'0']; | |
| } | |
| if(q.size() == g) count++; | |
| } | |
| printf("%d\n", count); | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment