Submission #487615

#TimeUsernameProblemLanguageResultExecution timeMemory
487615KazamaHoangIgra (COCI17_igra)C++14
100 / 100
1 ms336 KiB
#include <bits/stdc++.h> using namespace std; int n; string s, t; int cnt[3], suf[3][50005]; bool put(int x, int u) { if (t[u] == x || cnt[x] == 0) return false; -- cnt[x]; int sumcnt = 0; for (int i = 0; i < 3; ++ i) sumcnt += cnt[i]; for (int i = 0; i < 3; ++ i) { int rem = sumcnt - cnt[i]; int tmp = suf[i][u+1]; if (rem < tmp) { ++ cnt[x]; return false; } } return true; } int main() { cin.tie(0)->sync_with_stdio(0); cin >> n >> s >> t; s = " " + s; t = " " + t; for (int i = n; i >= 1; -- i) { s[i] -= 'a'; t[i] -= 'a'; ++ cnt[s[i]]; for (int j = 0; j < 3; ++ j) suf[j][i] = suf[j][i+1] + (t[i] == j); } string res = ""; for (int i = 1; i <= n; ++ i) { for (int j = 0; j < 3; ++ j) if (put(j, i)) { res += char('a' + j); break; } } cout << res; return 0; }

Compilation message (stderr)

igra.cpp: In function 'int main()':
igra.cpp:33:20: warning: array subscript has type 'char' [-Wchar-subscripts]
   33 |         ++ cnt[s[i]];
      |                    ^
#Verdict Execution timeMemoryGrader output
Fetching results...