Submission #371245

#TimeUsernameProblemLanguageResultExecution timeMemory
371245FatihSolakIgra (COCI17_igra)C++17
100 / 100
1 ms492 KiB
#include <bits/stdc++.h> #define N 5005 using namespace std; int cnt[3]; int suf[N][3]; int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); //freopen("in.txt","r",stdin); //freopen("out.txt","w",stdout); int n; cin >> n; string s,t; cin >> s >> t; for(int i=n-1;i>=0;i--){ for(int j=0;j<3;j++){ suf[i][j] = suf[i+1][j] + ((t[i]-'a') == j); } cnt[s[i]-'a']++; } string ans; for(int i=0;i<n;i++){ for(int j=0;j<3;j++){ bool ok = 1; for(int c=0;c<3;c++){ int sum = 0; for(int d=0;d<3;d++){ if(d != c)sum+=cnt[d] - (d == j); } if(suf[i+1][c] > sum){ ok = 0; } } if(cnt[j] && (t[i]-'a') != j && ok){ ans+='a'+j; cnt[j]--; break; } } } cout << ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...