Submission #6495548


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 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);
	reverse(s,s+n);
	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;
			}
		}
	}
	reverse(sol.begin(),sol.end());
	puts(sol.c_str());
	return 0;
}

Submission Info

Submission Time
Task E - ABC String
User Hasan0540
Language C++14 (GCC 5.4.1)
Score 0
Code Size 1851 Byte
Status WA
Exec Time 1257 ms
Memory 729860 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 × 50
WA × 17
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 7 ms 16640 KB
01-05.txt WA 7 ms 16640 KB
01-06.txt AC 6 ms 16640 KB
01-07.txt AC 5 ms 14592 KB
01-08.txt AC 7 ms 16640 KB
01-09.txt AC 6 ms 16640 KB
01-10.txt AC 7 ms 16640 KB
01-11.txt AC 6 ms 16640 KB
01-12.txt AC 5 ms 14592 KB
01-13.txt AC 7 ms 16640 KB
01-14.txt AC 8 ms 16640 KB
01-15.txt AC 7 ms 16640 KB
01-16.txt AC 5 ms 14592 KB
01-17.txt AC 7 ms 16640 KB
01-18.txt AC 7 ms 16640 KB
01-19.txt AC 7 ms 16640 KB
01-20.txt AC 7 ms 16640 KB
01-21.txt WA 6 ms 16640 KB
01-22.txt AC 6 ms 14592 KB
01-23.txt AC 7 ms 16640 KB
01-24.txt AC 7 ms 16640 KB
01-25.txt AC 7 ms 16640 KB
01-26.txt AC 7 ms 16640 KB
01-27.txt AC 7 ms 16640 KB
01-28.txt WA 6 ms 16640 KB
01-29.txt AC 7 ms 16640 KB
01-30.txt AC 6 ms 16640 KB
01-31.txt AC 5 ms 14592 KB
01-32.txt AC 5 ms 14592 KB
01-33.txt AC 875 ms 727808 KB
01-34.txt AC 1050 ms 727808 KB
01-35.txt WA 1257 ms 729092 KB
01-36.txt WA 1252 ms 729732 KB
01-37.txt WA 1217 ms 728192 KB
01-38.txt AC 1212 ms 727808 KB
01-39.txt WA 1228 ms 728324 KB
01-40.txt AC 1211 ms 727808 KB
01-41.txt WA 1225 ms 728452 KB
01-42.txt AC 1210 ms 727808 KB
01-43.txt WA 1226 ms 728452 KB
01-44.txt AC 1210 ms 727808 KB
01-45.txt WA 1223 ms 728452 KB
01-46.txt AC 1211 ms 727808 KB
01-47.txt WA 1224 ms 728324 KB
01-48.txt AC 1209 ms 727808 KB
01-49.txt WA 1225 ms 728452 KB
01-50.txt AC 1210 ms 727808 KB
01-51.txt WA 1227 ms 728452 KB
01-52.txt AC 1209 ms 727808 KB
01-53.txt WA 1233 ms 728452 KB
01-54.txt AC 1211 ms 727808 KB
01-55.txt WA 1238 ms 728580 KB
01-56.txt AC 1210 ms 727808 KB
01-57.txt WA 1231 ms 728708 KB
01-58.txt AC 1244 ms 729860 KB
01-59.txt AC 1213 ms 727936 KB
01-60.txt AC 1225 ms 728580 KB
01-61.txt AC 1218 ms 728192 KB
01-62.txt AC 1209 ms 727808 KB
01-63.txt AC 1219 ms 728324 KB
sample-01.txt AC 5 ms 14592 KB
sample-02.txt AC 5 ms 14592 KB
sample-03.txt AC 4 ms 14592 KB
sample-04.txt AC 5 ms 14592 KB