Submission #6493479
Source Code Expand
Copy
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int N=1e6+6; const int k=4; char s[N]; int dp[N][3][k][k][k]; int nxt[N][3]; int main() { scanf("%s",s); int n=strlen(s); for(int i=0;i<n;++i) s[i]-='A'; memset(nxt,-1,sizeof(nxt)); for(int i=n-1;i>=0;--i){ for(int j=0;j<3;++j) nxt[i][j]=nxt[i+1][j]; nxt[i][s[i]]=i; } for(int l=0;l<3;++l) for(int a=0;a<k;++a) for(int b=0;b<k;++b) for(int c=0;c<k;++c) dp[n][l][a][b][c]=a+b+c==0?0:-1e9; for(int i=n-1;i>=0;--i) for(int l=0;l<3;++l){ for(int a=0;a<k;++a) for(int b=0;b<k;++b) for(int c=0;c<k;++c){ if(a*b*c!=0) continue; int &ret=dp[i][l][a][b][c]; ret=dp[i+1][l][a][b][c]; for(int t=0;t<3;++t){ if(t==l || nxt[i][t]==-1) continue; int A=a,B=b,C=c; if(t==0){++A;} else if(t==1){++B;} else{++C;} int x=min(A,min(B,C)); A-=x;B-=x;C-=x; if(A>=k || B>=k || C>=k) continue; ret=max(ret,dp[nxt[i][t]+1][t][A][B][C]+1); } } } int ret=0,t; for(int T=0;T<3;++T){ if(ret<dp[0][T][0][0][0]){ ret=dp[0][T][0][0][0]; t=T; } } if(ret==0){ puts(""); return 0; } string sol; int a=0,b=0,c=0,l=t; for(int i=0;i<n;++i){ int &ret=dp[i][l][a][b][c]; if(ret==dp[i+1][l][a][b][c]) continue; for(int t=0;t<3;++t){ if(t==l || nxt[i][t]==-1) continue; int A=a,B=b,C=c; if(t==0){++A;} else if(t==1){++B;} else{++C;} int x=min(A,min(B,C)); A-=x;B-=x;C-=x; if(A>=k || B>=k || C>=k) continue; if(ret==dp[nxt[i][t]+1][t][A][B][C]+1){ i=nxt[i][t]; l=t; a=A; b=B; c=C; sol+=t+'A'; break; } } } cout<<ret<<endl; cout<<sol<<endl; return 0; }
Submission Info
Submission Time | |
---|---|
Task | E - ABC String |
User | Hasan0540 |
Language | C++14 (GCC 5.4.1) |
Score | 0 |
Code Size | 1841 Byte |
Status | WA |
Exec Time | 1622 ms |
Memory | 765060 KB |
Compile Error
./Main.cpp: In function ‘int main()’: ./Main.cpp:10:15: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result] scanf("%s",s); ^
Judge Result
Set Name | Sample | All | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 0 / 1500 | ||||||||
Status |
|
|
Set Name | Test Cases |
---|---|
Sample | sample-01.txt, sample-02.txt, sample-03.txt, sample-04.txt |
All | 01-01.txt, 01-02.txt, 01-03.txt, 01-04.txt, 01-05.txt, 01-06.txt, 01-07.txt, 01-08.txt, 01-09.txt, 01-10.txt, 01-11.txt, 01-12.txt, 01-13.txt, 01-14.txt, 01-15.txt, 01-16.txt, 01-17.txt, 01-18.txt, 01-19.txt, 01-20.txt, 01-21.txt, 01-22.txt, 01-23.txt, 01-24.txt, 01-25.txt, 01-26.txt, 01-27.txt, 01-28.txt, 01-29.txt, 01-30.txt, 01-31.txt, 01-32.txt, 01-33.txt, 01-34.txt, 01-35.txt, 01-36.txt, 01-37.txt, 01-38.txt, 01-39.txt, 01-40.txt, 01-41.txt, 01-42.txt, 01-43.txt, 01-44.txt, 01-45.txt, 01-46.txt, 01-47.txt, 01-48.txt, 01-49.txt, 01-50.txt, 01-51.txt, 01-52.txt, 01-53.txt, 01-54.txt, 01-55.txt, 01-56.txt, 01-57.txt, 01-58.txt, 01-59.txt, 01-60.txt, 01-61.txt, 01-62.txt, 01-63.txt, sample-01.txt, sample-02.txt, sample-03.txt, sample-04.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
01-01.txt | AC | 5 ms | 14592 KB |
01-02.txt | AC | 5 ms | 14592 KB |
01-03.txt | AC | 5 ms | 14592 KB |
01-04.txt | WA | 8 ms | 16640 KB |
01-05.txt | WA | 7 ms | 16640 KB |
01-06.txt | WA | 7 ms | 16640 KB |
01-07.txt | WA | 5 ms | 14592 KB |
01-08.txt | WA | 8 ms | 16640 KB |
01-09.txt | WA | 7 ms | 16640 KB |
01-10.txt | WA | 7 ms | 16640 KB |
01-11.txt | WA | 6 ms | 16640 KB |
01-12.txt | WA | 6 ms | 14592 KB |
01-13.txt | WA | 8 ms | 16640 KB |
01-14.txt | WA | 8 ms | 16640 KB |
01-15.txt | WA | 7 ms | 16640 KB |
01-16.txt | WA | 5 ms | 14592 KB |
01-17.txt | WA | 7 ms | 16640 KB |
01-18.txt | WA | 8 ms | 16640 KB |
01-19.txt | WA | 7 ms | 16640 KB |
01-20.txt | WA | 8 ms | 16640 KB |
01-21.txt | WA | 6 ms | 16640 KB |
01-22.txt | WA | 6 ms | 16640 KB |
01-23.txt | WA | 7 ms | 16640 KB |
01-24.txt | WA | 7 ms | 16640 KB |
01-25.txt | WA | 7 ms | 16640 KB |
01-26.txt | WA | 7 ms | 16640 KB |
01-27.txt | WA | 8 ms | 16640 KB |
01-28.txt | WA | 6 ms | 16640 KB |
01-29.txt | WA | 8 ms | 16640 KB |
01-30.txt | WA | 7 ms | 16640 KB |
01-31.txt | WA | 5 ms | 14592 KB |
01-32.txt | WA | 6 ms | 14592 KB |
01-33.txt | AC | 1197 ms | 763008 KB |
01-34.txt | AC | 1402 ms | 762880 KB |
01-35.txt | WA | 1599 ms | 764292 KB |
01-36.txt | WA | 1622 ms | 764804 KB |
01-37.txt | WA | 1560 ms | 763264 KB |
01-38.txt | WA | 1559 ms | 763008 KB |
01-39.txt | WA | 1564 ms | 763524 KB |
01-40.txt | WA | 1550 ms | 763008 KB |
01-41.txt | WA | 1568 ms | 763524 KB |
01-42.txt | WA | 1550 ms | 763008 KB |
01-43.txt | WA | 1578 ms | 763652 KB |
01-44.txt | WA | 1547 ms | 763008 KB |
01-45.txt | WA | 1567 ms | 763524 KB |
01-46.txt | WA | 1552 ms | 763008 KB |
01-47.txt | WA | 1572 ms | 763524 KB |
01-48.txt | WA | 1553 ms | 763008 KB |
01-49.txt | WA | 1569 ms | 763652 KB |
01-50.txt | WA | 1550 ms | 763008 KB |
01-51.txt | WA | 1579 ms | 763652 KB |
01-52.txt | WA | 1550 ms | 763008 KB |
01-53.txt | WA | 1570 ms | 763652 KB |
01-54.txt | WA | 1552 ms | 763008 KB |
01-55.txt | WA | 1574 ms | 763780 KB |
01-56.txt | WA | 1547 ms | 763008 KB |
01-57.txt | WA | 1575 ms | 763780 KB |
01-58.txt | WA | 1593 ms | 765060 KB |
01-59.txt | WA | 1562 ms | 763008 KB |
01-60.txt | WA | 1569 ms | 763780 KB |
01-61.txt | WA | 1560 ms | 763264 KB |
01-62.txt | WA | 1550 ms | 763008 KB |
01-63.txt | WA | 1562 ms | 763396 KB |
sample-01.txt | WA | 5 ms | 14592 KB |
sample-02.txt | WA | 5 ms | 14592 KB |
sample-03.txt | WA | 5 ms | 14592 KB |
sample-04.txt | AC | 5 ms | 14592 KB |