Submission #155144

#TimeUsernameProblemLanguageResultExecution timeMemory
155144phillipIgra (COCI17_igra)C++14
40 / 100
3 ms504 KiB
#include<bits/stdc++.h> #define ll long long using namespace std; int n,aa,bb,cc; string s; int dp[21][21][21][21]; void bt(int i,int a,int b,int c,string x) { if(dp[i][a][b][c])return; if(a==0&&b==0&&c==0) { cout<<x; exit(0); } if(s[i]!='a'&&a) { bt(i+1,a-1,b,c,x+'a'); } if(s[i]!='b'&&b) { bt(i+1,a,b-1,c,x+'b'); } if(s[i]!='c'&&c) { bt(i+1,a,b,c-1,x+'c'); } dp[i][a][b][c]=1; } int main() { cin>>n>>s; for(int i=0;i<n;i++) { if(s[i]=='a')aa++; else if(s[i]=='b')bb++; else cc++; } cin>>s; bt(0,aa,bb,cc,""); }
#Verdict Execution timeMemoryGrader output
Fetching results...