Submission #6494649


Source Code Expand

Copy
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e6+6;
const int k=5;
char s[N];
int dp[N][3][61];
int nxt[N][3];
int id[k][k][k];
int main() {
	vector<vector<int> > st;
	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){
					id[a][b][c]=st.size();
					st.push_back({a,b,c});
				}
	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 i=0;i<st.size();++i)
			dp[n][l][i]=i==0?0:-1e9;
	for(int i=n-1;i>=0;--i)
		for(int l=0;l<3;++l){
			for(int j=0;j<st.size();++j){
				int &ret=dp[i][l][j];
				ret=dp[i+1][l][j];
				for(int t=0;t<3;++t){
					if(t==l || nxt[i][t]==-1)
						continue;
					int A=st[j][0],B=st[j][1],C=st[j][2];
					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][id[A][B][C]]+1);
				}
			}
	}
	int ret=0,t;
	for(int T=0;T<3;++T){
		if(ret<dp[0][T][0]){
			ret=dp[0][T][0];
			t=T;
		}
	}
	if(ret==0){
		puts("");
		return 0;
	}
	string sol;
	int j=0,l=t;
	for(int i=0;i<n;++i){
		int &ret=dp[i][l][j];
		if(ret==dp[i+1][l][j])
			continue;
		for(int t=0;t<3;++t){
			if(t==l || nxt[i][t]==-1)
				continue;
			int A=st[j][0],B=st[j][1],C=st[j][2];
			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][id[A][B][C]]+1){
				i=nxt[i][t];
				l=t;
				j=id[A][B][C];
				sol+=t+'A';
				break;
			}
		}
	}
	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 1844 Byte
Status WA
Exec Time 2105 ms
Memory 727808 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:19: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
AC × 4
AC × 33
WA × 4
TLE × 30
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 6 ms 14592 KB
01-04.txt WA 10 ms 16640 KB
01-05.txt WA 9 ms 16640 KB
01-06.txt AC 8 ms 16640 KB
01-07.txt AC 6 ms 14592 KB
01-08.txt AC 9 ms 16640 KB
01-09.txt AC 8 ms 16640 KB
01-10.txt AC 9 ms 16640 KB
01-11.txt AC 7 ms 16640 KB
01-12.txt AC 6 ms 14592 KB
01-13.txt AC 10 ms 16640 KB
01-14.txt AC 10 ms 16640 KB
01-15.txt AC 8 ms 16640 KB
01-16.txt AC 5 ms 14592 KB
01-17.txt AC 8 ms 16640 KB
01-18.txt AC 9 ms 16640 KB
01-19.txt AC 9 ms 16640 KB
01-20.txt AC 10 ms 16640 KB
01-21.txt WA 8 ms 16640 KB
01-22.txt AC 7 ms 14592 KB
01-23.txt AC 9 ms 16640 KB
01-24.txt AC 9 ms 16640 KB
01-25.txt AC 9 ms 16640 KB
01-26.txt AC 9 ms 16640 KB
01-27.txt AC 10 ms 16640 KB
01-28.txt WA 8 ms 16640 KB
01-29.txt AC 10 ms 16640 KB
01-30.txt AC 8 ms 16640 KB
01-31.txt AC 6 ms 14592 KB
01-32.txt AC 6 ms 14592 KB
01-33.txt AC 1389 ms 727808 KB
01-34.txt TLE 2029 ms 727808 KB
01-35.txt TLE 2105 ms 586496 KB
01-36.txt TLE 2105 ms 586496 KB
01-37.txt TLE 2105 ms 584448 KB
01-38.txt TLE 2105 ms 586496 KB
01-39.txt TLE 2105 ms 586496 KB
01-40.txt TLE 2105 ms 586496 KB
01-41.txt TLE 2105 ms 586496 KB
01-42.txt TLE 2105 ms 584448 KB
01-43.txt TLE 2105 ms 584448 KB
01-44.txt TLE 2105 ms 586496 KB
01-45.txt TLE 2105 ms 586496 KB
01-46.txt TLE 2105 ms 586496 KB
01-47.txt TLE 2105 ms 586496 KB
01-48.txt TLE 2105 ms 586496 KB
01-49.txt TLE 2105 ms 586496 KB
01-50.txt TLE 2105 ms 586496 KB
01-51.txt TLE 2105 ms 586496 KB
01-52.txt TLE 2105 ms 586496 KB
01-53.txt TLE 2105 ms 586496 KB
01-54.txt TLE 2105 ms 586496 KB
01-55.txt TLE 2105 ms 586496 KB
01-56.txt TLE 2105 ms 588544 KB
01-57.txt TLE 2105 ms 586496 KB
01-58.txt TLE 2105 ms 586496 KB
01-59.txt TLE 2105 ms 586496 KB
01-60.txt TLE 2105 ms 586496 KB
01-61.txt TLE 2105 ms 586496 KB
01-62.txt TLE 2105 ms 586496 KB
01-63.txt TLE 2105 ms 586496 KB
sample-01.txt AC 5 ms 14592 KB
sample-02.txt AC 5 ms 14592 KB
sample-03.txt AC 5 ms 14592 KB
sample-04.txt AC 5 ms 14592 KB