# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
249484 | VEGAnn | Igra (COCI17_igra) | C++14 | 1 ms | 384 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |