Submission #963287

#TimeUsernameProblemLanguageResultExecution timeMemory
963287shezittIgra (COCI17_igra)C++14
100 / 100
2 ms348 KiB
#include <iostream> #include <vector> #include <algorithm> #include <cassert> #include <cstring> #include <queue> #include <numeric> using namespace std; using ll = long long; #define int ll #define fore(i, a, b) for(int i=a; i<b; ++i) #define endl '\n' #define all(x) x.begin(), x.end() #define sz(x) (int)x.size() #define pb push_back #define ii pair<int,int> #define vi vector<int> signed main(){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; cin >> n; string s, m, ans; cin >> s >> m; int scnt[3] = {}; int mcnt[3] = {}; int stmp[3] = {}; for(char c : s){ scnt[c - 'a']++; } for(char c : m){ mcnt[c - 'a']++; } auto check = [&](int i, int p) -> bool { fore(j, 0, 3){ stmp[j] = scnt[j]; } if(stmp[p] == 0) return 0; if(m[i] == 'a'+p) { return 0; } stmp[p]--; int ba, bc, ac, ab, ca, cb; fore(bba, 0, stmp[1]+1){ ba = bba; bc = stmp[1] - ba; ac = mcnt[2] - bc; ca = mcnt[0] - ba; ab = stmp[0] - ac; cb = stmp[2] - ca; bool ok = min({ba, bc, ac, ca, ab, cb}) >= 0; ok &= ac + ab == stmp[0] && ba + bc == stmp[1] && ca + cb == stmp[2]; if(ok){ return 1; } } return 0; }; fore(i, 0, n){ mcnt[m[i] - 'a']--; fore(j, 0, 3){ if(check(i, j)){ scnt[j]--; ans.pb('a'+j); break; } } } cout << ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...