#include<stdlib.h> #include<stdio.h> #include<algorithm> #include<iostream> #include<set> #include<string.h> #ifdef DEBUG #include<unistd.h> #endif typedef long long LL; typedef unsigned long long ULL; using namespace std; LL kasa[1000100]; LL kasa2[1000100]; char cykl[1000100]; int main() { LL n,m; scanf("%lld",&n); for (int i=0;i<n;i++) { scanf("%lld",kasa+i); kasa2[i]=kasa[i]; } scanf("%lld",&m); scanf("%s",cykl); LL i=0; while(true) { for (LL j=0;j<n*m;j++,i++) { if(cykl[i%m]=='W') { kasa[i%n]+=1; } else { kasa[i%n]-=1; if (kasa[i%n] == 0) { printf("%lld\n",i+1); return 0; } } } int flag=0; for (int i=0;i<n;i++) { if (kasa2[i]>kasa[i]) { flag=1; break; } } if (flag==0) { printf("-1\n"); return 0; } } return 0; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 | #include<stdlib.h> #include<stdio.h> #include<algorithm> #include<iostream> #include<set> #include<string.h> #ifdef DEBUG #include<unistd.h> #endif typedef long long LL; typedef unsigned long long ULL; using namespace std; LL kasa[1000100]; LL kasa2[1000100]; char cykl[1000100]; int main() { LL n,m; scanf("%lld",&n); for (int i=0;i<n;i++) { scanf("%lld",kasa+i); kasa2[i]=kasa[i]; } scanf("%lld",&m); scanf("%s",cykl); LL i=0; while(true) { for (LL j=0;j<n*m;j++,i++) { if(cykl[i%m]=='W') { kasa[i%n]+=1; } else { kasa[i%n]-=1; if (kasa[i%n] == 0) { printf("%lld\n",i+1); return 0; } } } int flag=0; for (int i=0;i<n;i++) { if (kasa2[i]>kasa[i]) { flag=1; break; } } if (flag==0) { printf("-1\n"); return 0; } } return 0; } |