Submission #310855

#TimeUsernameProblemLanguageResultExecution timeMemory
310855kaplanbarIgra (COCI17_igra)C++14
100 / 100
1 ms384 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; int c[3], dp[5005][3]; int main() { ios_base::sync_with_stdio(false); cin.tie(0); int n; cin >> n; string a, b; cin >> a >> b; for(int i = 0; i < n; i++) { c[a[i] - 'a']++; } for(int i = n - 1; i >= 0; i--) { dp[i][b[i] - 'a']++; if(i != n - 1) { for(int j = 0; j < 3; j++) dp[i][j] += dp[i + 1][j]; } } auto check = [&](int idx) -> bool { if(idx == n - 1) return true; int s = 0; for(int i = 0; i < 3; i++) { s += c[i]; } for(int i = 0; i < 3; i++) { if(s - c[i] < dp[idx + 1][i]) return false; } return true; }; for(int i = 0; i < n; i++) { for(int j = 0; j < 3; j++) { if(c[j] && j != b[i] - 'a') { c[j]--; if(check(i)) { cout << (char)(j + 'a'); break; } c[j]++; } } } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...