Submission #249484

#TimeUsernameProblemLanguageResultExecution timeMemory
249484VEGAnnIgra (COCI17_igra)C++14
100 / 100
1 ms384 KiB
#include <bits/stdc++.h> using namespace std; int cnt[3], ost[3], n; string s; bool ok(){ for (int msk = 1; msk < (1 << 3); msk++){ int sm = 0, nmsk = 0; for (int i = 0; i < 3; i++) if (msk & (1 << i)){ sm += cnt[i]; nmsk |= (7 - (1 << i)); } int kol = 0; for (int i = 0; i < 3; i++) if (nmsk & (1 << i)) kol += ost[i]; if (kol < sm) return 0; } return 1; } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); #ifdef _LOCAL freopen("in.txt","r",stdin); #endif // _LOCAL cin >> n; for (int i = 0; i < n; i++){ char c; cin >> c; cnt[c - 'a']++; } cin >> s; for (int i = 0; i < n; i++){ ost[s[i] - 'a']++; } for (int i = 0; i < n; i++){ int tp = 0, ch = (s[i] - 'a'); for (;; tp++){ if (tp == ch) continue; cnt[tp]--; ost[ch]--; if (ok()) { cout << char(tp + 'a'); break; } else { cnt[tp]++; ost[ch]++; } } } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...