답안 #81994

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
81994 2018-10-28T10:52:41 Z Vasiljko Igra (COCI17_igra) C++14
100 / 100
2 ms 600 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
const ll MOD = 1e9+7;

int n,a,b,c,cura,curb,curc;
string s,t;
vector<char>ans;

bool check(int fi,int se,int th){
    if(fi<0||se<0||th<0)return false;
    if(fi+se>=curc&&fi+th>=curb&&se+th>=cura)return true;
    return false;
}

void Set(int ind,char p,int &val){
    ans[ind]=p;
    val--;
}

int main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    cin>>n;
    cin>>s>>t;
    ans.resize(n);

    for(int i=0;i<n;i++){
        if(s[i]=='a')a++;
        else if(s[i]=='b')b++;
        else c++;
    }
    for(int i=0;i<n;i++){
        if(t[i]=='a')cura++;
        else if(t[i]=='b')curb++;
        else curc++;
    }

    for(int i=0;i<n;i++){
        if(t[i]=='a'){
            cura--;
            bool ok1=check(a,b-1,c);
            bool ok2=check(a,b,c-1);

            if(ok1&&ok2)Set(i,'b',b);
            else{
                if(ok1)Set(i,'b',b);
                else Set(i,'c',c);
            }
        }else if(t[i]=='b'){
            curb--;
            bool ok1=check(a-1,b,c);
            bool ok2=check(a,b,c-1);

            if(ok1&&ok2)Set(i,'a',a);
            else{
                if(ok1)Set(i,'a',a);
                else Set(i,'c',c);
            }
        }else{
            curc--;
            bool ok1=check(a-1,b,c);
            bool ok2=check(a,b-1,c);

            if(ok1&&ok2)Set(i,'a',a);
            else{
                if(ok1)Set(i,'a',a);
                else Set(i,'b',b);
            }
        }
    }

    for(auto e:ans)cout<<e;
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 520 KB Output is correct
4 Correct 2 ms 600 KB Output is correct
5 Correct 2 ms 600 KB Output is correct
6 Correct 2 ms 600 KB Output is correct
7 Correct 2 ms 600 KB Output is correct
8 Correct 2 ms 600 KB Output is correct
9 Correct 2 ms 600 KB Output is correct
10 Correct 2 ms 600 KB Output is correct