Submission #547709

#TimeUsernameProblemLanguageResultExecution timeMemory
547709AbdelmagedNourIgra (COCI17_igra)C++17
100 / 100
1 ms340 KiB
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") using namespace std; int freq1[3],freq2[3],ch[3][2]={{1,2},{0,2},{0,1}}; bool check(int c){ if(freq1[c]==0)return 0; freq1[c]--; bool ok=1; if(freq1[0]+freq1[1]<freq2[2])ok=0; if(freq1[0]+freq1[2]<freq2[1])ok=0; if(freq1[1]+freq1[2]<freq2[0])ok=0; if(freq2[0]+freq2[1]<freq1[2])ok=0; if(freq2[0]+freq2[2]<freq1[1])ok=0; if(freq2[1]+freq2[2]<freq1[0])ok=0; freq1[c]++; return ok; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; string s1,s2,res=""; cin>>n>>s1>>s2; for(int i=0;i<n;i++)freq1[s1[i]-'a']++; for(int i=0;i<n;i++)freq2[s2[i]-'a']++; res=string(n,'a'); for(int i=0;i<n;i++){ freq2[s2[i]-'a']--; if(check(ch[s2[i]-'a'][0]))res[i]+=ch[s2[i]-'a'][0]; else if(check(ch[s2[i]-'a'][1]))res[i]+=ch[s2[i]-'a'][1]; freq1[res[i]-'a']--; } cout<<res; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...