Submission #3094392
Source Code Expand
#include <iostream> #include <vector> #include <stack> #include <queue> #include <algorithm> #include <cmath> #include <string> #include <map> #include <set> #include <list> #define ll long long #define fornum(A,B,C) for(A=B;A<C;A++) using namespace std; int i,j,k,l,m,n; ///////////////////////////////////////////////////// #define INF 999999999 #define DUB 21 //>log2_505050 char s[505050]; int Q; int sl; int nextc[505050][30]; int nextdb[505050][DUB]; int main(){ //文字列入力 cin>>s; //データ作成 for(sl=0;s[sl]!='\0';sl++); int C[30]; //cout<<sl<<" "<<endl; for(j=0;j<27;j++){ nextc[sl][j]=INF; C[j]=INF; } for(i=sl-1;i>=0;i--){ for(j=0;j<27;j++){ nextc[i][j]=INF; } int cc=s[i]-'a'; nextc[i][cc]=i+1; int ci=nextc[nextc[i][cc]][cc]; while(ci!=INF&&cc<26){ cc++; nextc[i][cc]=ci; ci=nextc[nextc[i][cc]][cc]; } if(cc==26){ int idx=nextc[i][26]; int cci=s[i]-'a'; cc=0; while(cc<cci){ nextc[i][cc]=nextc[idx][cc]; cc++; } } /* cout<<"\n"<<i<<":"<<endl; for(j=0;j<27;j++){ if(nextc[i][j]==INF) cout<< " ["<<j<< "]:-"; else cout <<" ["<<j<< "]:" << nextc[i][j]; } */ } //ダブリング for(i=0;i<=sl;i++){ nextdb[i][0]=nextc[i][26]; } for(k=1;k<DUB;k++){ for(i=0;i<=sl;i++){ if(nextdb[i][k-1]!=INF){ nextdb[i][k]=nextdb[nextdb[i][k-1]][k-1]; }else{ nextdb[i][k]=INF; } //cout<<" "<<k<<":"<<i<< nextdb[k][i]<<endl; } } //検索 cin>>Q; int l,r,lr; for(i=0;i<Q;i++){ cin >> l >> r; l--; for(k=DUB-1;k>=0;k--){ if(r>=nextdb[l][k]){ l=nextdb[l][k]; if(r==l) break; } } if(l==r){ cout<< "Yes"<<endl; }else{ cout<<"No"<< endl; } } return 0; }
Submission Info
Submission Time | |
---|---|
Task | C - Robot and String |
User | hig98ingro |
Language | C++14 (GCC 5.4.1) |
Score | 1300 |
Code Size | 2368 Byte |
Status | AC |
Exec Time | 456 ms |
Memory | 101504 KB |
Judge Result
Set Name | Sample | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 1300 / 1300 | ||||
Status |
|
|
Set Name | Test Cases |
---|---|
Sample | 0_00.txt, 0_01.txt, 0_02.txt |
All | 0_00.txt, 0_01.txt, 0_02.txt, 1_00.txt, 1_01.txt, 1_02.txt, 1_03.txt, 1_04.txt, 1_05.txt, 1_06.txt, 1_07.txt, 1_08.txt, 1_09.txt, 1_10.txt, 1_11.txt, 1_12.txt, 1_13.txt, 1_14.txt, 1_15.txt, 1_16.txt, 1_17.txt, 1_18.txt, 1_19.txt, 1_20.txt, 1_21.txt, 1_22.txt, 1_23.txt, 1_24.txt, 1_25.txt, 1_26.txt, 1_27.txt, 1_28.txt, 1_29.txt, 1_30.txt, 1_31.txt, 1_32.txt, 1_33.txt, 1_34.txt, 1_35.txt, 1_36.txt, 1_37.txt, 1_38.txt, 1_39.txt, 1_40.txt, 1_41.txt, 1_42.txt, 1_43.txt, 1_44.txt, 1_45.txt, 1_46.txt, 1_47.txt, 1_48.txt, 1_49.txt, 1_50.txt, 1_51.txt, 1_52.txt, 1_53.txt, 1_54.txt, 1_55.txt, 1_56.txt, 1_57.txt, 1_58.txt, 1_59.txt, 1_60.txt, 1_61.txt, 1_62.txt, 1_63.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
0_00.txt | AC | 2 ms | 2304 KB |
0_01.txt | AC | 2 ms | 2304 KB |
0_02.txt | AC | 2 ms | 2304 KB |
1_00.txt | AC | 196 ms | 2560 KB |
1_01.txt | AC | 196 ms | 2560 KB |
1_02.txt | AC | 423 ms | 101376 KB |
1_03.txt | AC | 409 ms | 101376 KB |
1_04.txt | AC | 419 ms | 101504 KB |
1_05.txt | AC | 442 ms | 101504 KB |
1_06.txt | AC | 453 ms | 101504 KB |
1_07.txt | AC | 450 ms | 101504 KB |
1_08.txt | AC | 389 ms | 101376 KB |
1_09.txt | AC | 388 ms | 101376 KB |
1_10.txt | AC | 384 ms | 101376 KB |
1_11.txt | AC | 384 ms | 101376 KB |
1_12.txt | AC | 381 ms | 101376 KB |
1_13.txt | AC | 386 ms | 101376 KB |
1_14.txt | AC | 387 ms | 101376 KB |
1_15.txt | AC | 392 ms | 101376 KB |
1_16.txt | AC | 387 ms | 101376 KB |
1_17.txt | AC | 387 ms | 101376 KB |
1_18.txt | AC | 393 ms | 101376 KB |
1_19.txt | AC | 397 ms | 101376 KB |
1_20.txt | AC | 394 ms | 101376 KB |
1_21.txt | AC | 396 ms | 101376 KB |
1_22.txt | AC | 402 ms | 101376 KB |
1_23.txt | AC | 402 ms | 101376 KB |
1_24.txt | AC | 408 ms | 101376 KB |
1_25.txt | AC | 409 ms | 101376 KB |
1_26.txt | AC | 428 ms | 101376 KB |
1_27.txt | AC | 433 ms | 101376 KB |
1_28.txt | AC | 416 ms | 101376 KB |
1_29.txt | AC | 430 ms | 101504 KB |
1_30.txt | AC | 424 ms | 101504 KB |
1_31.txt | AC | 426 ms | 101504 KB |
1_32.txt | AC | 456 ms | 101504 KB |
1_33.txt | AC | 376 ms | 101376 KB |
1_34.txt | AC | 383 ms | 101376 KB |
1_35.txt | AC | 390 ms | 101376 KB |
1_36.txt | AC | 384 ms | 99328 KB |
1_37.txt | AC | 393 ms | 101376 KB |
1_38.txt | AC | 401 ms | 101376 KB |
1_39.txt | AC | 402 ms | 101376 KB |
1_40.txt | AC | 402 ms | 101376 KB |
1_41.txt | AC | 403 ms | 101376 KB |
1_42.txt | AC | 405 ms | 101376 KB |
1_43.txt | AC | 413 ms | 101376 KB |
1_44.txt | AC | 409 ms | 101376 KB |
1_45.txt | AC | 415 ms | 101376 KB |
1_46.txt | AC | 414 ms | 101376 KB |
1_47.txt | AC | 427 ms | 101376 KB |
1_48.txt | AC | 436 ms | 101376 KB |
1_49.txt | AC | 412 ms | 101504 KB |
1_50.txt | AC | 428 ms | 101504 KB |
1_51.txt | AC | 400 ms | 101376 KB |
1_52.txt | AC | 429 ms | 101504 KB |
1_53.txt | AC | 391 ms | 101376 KB |
1_54.txt | AC | 428 ms | 101504 KB |
1_55.txt | AC | 400 ms | 101376 KB |
1_56.txt | AC | 420 ms | 101504 KB |
1_57.txt | AC | 393 ms | 101504 KB |
1_58.txt | AC | 407 ms | 101376 KB |
1_59.txt | AC | 438 ms | 101504 KB |
1_60.txt | AC | 407 ms | 101504 KB |
1_61.txt | AC | 398 ms | 101376 KB |
1_62.txt | AC | 377 ms | 101376 KB |
1_63.txt | AC | 410 ms | 101504 KB |