답안 #547709

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
547709 2022-04-11T14:07:49 Z AbdelmagedNour Igra (COCI17_igra) C++17
100 / 100
1 ms 340 KB
#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;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 316 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 328 KB Output is correct
10 Correct 1 ms 340 KB Output is correct