#include #include #include #include // Yukicoder №78 クジ付きアイスバー ★★☆ // https://yukicoder.me/problems/no/78 // *********************** #define PRINCR do{printf("\n");fflush(stdout);}while(0) #define GETLINE(str) do{char *p;fgets(str,sizeof(str),stdin);p=strchr(str,'\n');if(p)*p='\0';}while(0) #define REP(a,b) for(int a=0;a<(int)(b);++a) static char *GETWORD(char* str) {char c;char *cp;cp=&str[0];c=fgetc(stdin);while( c != EOF ){if((c==' ')||( c=='\n')) break;*cp++=c;c=fgetc(stdin);}*cp='\0';return &str[0];} #define GETINTS(a,b) {char s[34];int *ap=a;REP(i,b){GETWORD(s);sscanf(s,"%d", ap);ap++;}} static int GETLINEINT(void) {char s[34];GETLINE(s);return atoi(s);} static int GETWORDINT(void) {char s[34];GETWORD(s);return atoi(s);} static long GETWORDLONG(void) {char s[34];GETWORD(s);return atol(s);} #define SWAP(type,a,b) do{type _c;_c=a;a=b;b=_c;}while(0) int main( void ) { char str[258]; int box; int eat,atari; int idx; long want; long buyed = 0; int tada = 0; int buy1box; int end; box = GETWORDINT(); want = GETWORDLONG(); GETLINE(str); idx = -1; while( eat < want ) { if( atari ) { atari--; tada++; } else { buyed++; } idx++; if( idx >= box ) idx = 0; atari += str[idx] - '0'; eat++; } if( atari ) { idx = -1; tada = 0; while( eat < want ) { if( atari ) { atari--; tada++; } else { buyed++; } idx++; if( idx >= box ) idx = 0; atari += str[idx] - '0'; eat++; } if( tada != box ) { // 買う必要がある buy1box = box - tada; end = want / box; end = end * box; while( eat < end ) { eat += box; buyed += buy1box; } while( eat < want ) { if( atari ) { atari--; tada++; } else { buyed++; } idx++; if( idx >= box ) idx = 0; atari += str[idx] - '0'; eat++; } } } else { // 当たりは継続しない buy1box = box - tada; end = want / box; end = end * box; while( eat < end ) { eat += box; buyed += buy1box; } while( eat < want ) { if( atari ) { atari--; tada++; } else { buyed++; } idx++; if( idx >= box ) idx = 0; atari += str[idx] - '0'; eat++; } } printf("%ld\n", buyed ); return 0; }