Submission #6495198


Source Code Expand

Copy
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e6+6;
const int k=6;
char s[N];
int dp[N][3][91];
int nxt[N][3];
int id[k][k][k];
int nid[91][3];
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=0;i<st.size();++i)
		for(int t=0;t<3;++t){
			int j=i;
			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)
				nid[i][t]=-1;
			else
				nid[i][t]=id[A][B][C];
		}
	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 || nid[j][t]==-1)
						continue;
					ret=max(ret,dp[nxt[i][t]+1][t][nid[j][t]]+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 || nid[j][t]==-1)
				continue;
			if(ret==dp[nxt[i][t]+1][t][nid[j][t]]+1){
				i=nxt[i][t];
				l=t;
				j=nid[j][t];
				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 1797 Byte
Status WA
Exec Time 2061 ms
Memory 1081476 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:20: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 × 3
TLE × 20
MLE × 11
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 12544 KB
01-02.txt AC 5 ms 12544 KB
01-03.txt AC 5 ms 12544 KB
01-04.txt WA 8 ms 14592 KB
01-05.txt WA 7 ms 14592 KB
01-06.txt AC 7 ms 14592 KB
01-07.txt AC 5 ms 12544 KB
01-08.txt AC 8 ms 14592 KB
01-09.txt AC 7 ms 14592 KB
01-10.txt AC 7 ms 14592 KB
01-11.txt AC 6 ms 14592 KB
01-12.txt AC 5 ms 12544 KB
01-13.txt AC 8 ms 14592 KB
01-14.txt AC 9 ms 14592 KB
01-15.txt AC 7 ms 14592 KB
01-16.txt AC 5 ms 12544 KB
01-17.txt AC 7 ms 14592 KB
01-18.txt AC 8 ms 14592 KB
01-19.txt AC 7 ms 14592 KB
01-20.txt AC 9 ms 14592 KB
01-21.txt AC 7 ms 14592 KB
01-22.txt AC 6 ms 14592 KB
01-23.txt AC 8 ms 14592 KB
01-24.txt AC 8 ms 14592 KB
01-25.txt AC 8 ms 14592 KB
01-26.txt AC 8 ms 14592 KB
01-27.txt AC 8 ms 14592 KB
01-28.txt WA 7 ms 14592 KB
01-29.txt AC 8 ms 14592 KB
01-30.txt AC 6 ms 14592 KB
01-31.txt AC 5 ms 12544 KB
01-32.txt AC 6 ms 14592 KB
01-33.txt MLE 1335 ms 1079296 KB
01-34.txt MLE 1704 ms 1079424 KB
01-35.txt TLE 2061 ms 1080708 KB
01-36.txt TLE 2047 ms 1081348 KB
01-37.txt TLE 2009 ms 1079680 KB
01-38.txt MLE 2000 ms 1079424 KB
01-39.txt TLE 2015 ms 1079940 KB
01-40.txt MLE 2000 ms 1079424 KB
01-41.txt TLE 2025 ms 1079940 KB
01-42.txt MLE 1999 ms 1079424 KB
01-43.txt TLE 2017 ms 1080068 KB
01-44.txt MLE 1999 ms 1079424 KB
01-45.txt TLE 2015 ms 1079940 KB
01-46.txt MLE 2000 ms 1079424 KB
01-47.txt TLE 2015 ms 1079940 KB
01-48.txt MLE 2000 ms 1079424 KB
01-49.txt TLE 2018 ms 1080068 KB
01-50.txt MLE 2000 ms 1079424 KB
01-51.txt TLE 2037 ms 1080068 KB
01-52.txt TLE 2008 ms 1079424 KB
01-53.txt TLE 2019 ms 1080196 KB
01-54.txt MLE 1999 ms 1079424 KB
01-55.txt TLE 2020 ms 1080196 KB
01-56.txt MLE 1999 ms 1079424 KB
01-57.txt TLE 2024 ms 1080196 KB
01-58.txt TLE 2037 ms 1081476 KB
01-59.txt TLE 2003 ms 1079424 KB
01-60.txt TLE 2035 ms 1080196 KB
01-61.txt TLE 2009 ms 1079680 KB
01-62.txt TLE 2003 ms 1079296 KB
01-63.txt TLE 2012 ms 1079812 KB
sample-01.txt AC 5 ms 12544 KB
sample-02.txt AC 5 ms 12544 KB
sample-03.txt AC 5 ms 12544 KB
sample-04.txt AC 4 ms 12544 KB