Submission #87818

#TimeUsernameProblemLanguageResultExecution timeMemory
87818KoscheiIgra (COCI17_igra)C++17
100 / 100
3 ms744 KiB
#include <iostream> using namespace std; const int MAXN = 5001; int n; int cnts[3]; int cntm[3]; char s[MAXN]; char m[MAXN]; char r[3] = {'a', 'b', 'c'}; int main() { ios_base::sync_with_stdio(false); cin >> n >> s >> m; for (int i = 0; i < n; i++) { cnts[s[i]-'a']++; cntm[m[i]-'a']++; } for (int i = 0; i < n; i++) { cntm[m[i]-'a']--; for (int j = 0; j < 3; j++) { if (m[i] != r[j]) { if ((j == 0) && cnts[0]) { if ((cnts[0]+cnts[1]>=cntm[2]+1) && (cnts[0]+cnts[2]>=cntm[1]+1)) { cout << 'a'; cnts[0]--; break; } } if ((j == 1) && cnts[1]) { if ((cnts[0]+cnts[1]>=cntm[2]+1) && (cnts[1]+cnts[2]>=cntm[0]+1)) { cout << 'b'; cnts[1]--; break; } } if ((j == 2) && cnts[2]) { if ((cnts[2]+cnts[1]>=cntm[0]+1) && (cnts[0]+cnts[2]>=cntm[1]+1)) { cout << 'c'; cnts[2]--; break; } } } } } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...