Submission #152755

#TimeUsernameProblemLanguageResultExecution timeMemory
152755sofhiasouzaIgra (COCI17_igra)C++14
40 / 100
3 ms424 KiB
#include <bits/stdc++.h> #define pb push_back using namespace std; const int maxn = 5e3+10; int n, c1, c2, c3; string a, b, resp; priority_queue < int > v1, v3, v5; priority_queue < int, vector < int >, greater < int > > v2, v4, v6; int main() { cin >> n; cin >> a >> b; char resp[maxn]; for(int i = 0 ; i < a.size() ; i++) { if(a[i] == 'a') c1++; else if(a[i] == 'b') c2++; else c3++; } for(int i = 0 ; i < n ; i++) { if(b[i] == 'a') { if(c2) { resp[i] = 'b'; c2--; v1.push(i); } else if(c3) { resp[i] = 'c'; c3--; v2.push(i); } else { int u4 = -1, u6 = -1; if(v4.size()) u4 = v4.top(); if(v6.size()) u6 = v6.top(); if(u4 != -1 and (u4 < u6 or u6 == -1)) { v4.pop(); resp[u4] = 'a'; c1--; resp[i] = 'c'; v3.push(u4); v2.push(i); } else { v6.pop(); resp[u6] = 'a'; c1--; resp[i] = 'b'; v5.push(u6); v1.push(i); } } } else if(b[i] == 'b') { if(c1) { resp[i] = 'a'; c1--; v3.push(i); } else if(c3) { resp[i] = 'c'; c3--; v4.push(i); } else { int u2 = -1, u5 = -1; if(v2.size()) u2 = v2.top(); if(v5.size()) u5 = v5.top(); if(u2 != -1) { v2.pop(); resp[u2] = 'b'; c2--; resp[i] = 'c'; v1.push(u2); v4.push(i); } else { v5.pop(); resp[u5] = 'b'; c2--; resp[i] = 'a'; v6.push(u5); v3.push(i); } } } else { if(c1) { resp[i] = 'a'; c1--; v5.push(i); } else if(c2) { resp[i] = 'b'; c2--; v6.push(i); } else { int u1 = -1, u3 = -1; if(v1.size()) u1 = v1.top(); if(v3.size()) u3 = v3.top(); if(u1 > u3) { v1.pop(); resp[u1] = 'c'; c3--; resp[i] = 'b'; v2.push(u1); v6.push(i); } else { v3.pop(); resp[u3] = 'c'; c3--; resp[i] = 'a'; v4.push(u3); v5.push(i); } } } } for(int i = 0 ; i < n ; i++) cout << resp[i]; cout << "\n"; }

Compilation message (stderr)

igra.cpp: In function 'int main()':
igra.cpp:20:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 0 ; i < a.size() ; i++)
                  ~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...