Submission #151742

# Submission time Handle Problem Language Result Execution time Memory
151742 2019-09-04T13:40:10 Z hdj79 Igra (COCI17_igra) C++14
100 / 100
4 ms 504 KB
#include<iostream>
#include<string>
using namespace std;
bool moze(int a,int b,int c,int A,int B,int C){
    int sa=a,sb=b,sc=c,sA=A,sB=B,sC=C;
   // cout<<a<<" "<<b<<" "<<c<<" "<<A<<" "<<B<<" "<<C<<endl;
    for(int k=0;k<=B;k++){
        a-=k;
        B-=k;
        if(a<0){a=sa;b=sb;c=sc;A=sA;B=sB;C=sC; continue;}
        C-=a;
        a=0;
        if(C<0){a=sa;b=sb;c=sc;A=sA;B=sB;C=sC; continue;}
        b-=C;
        C=0;
        if(b<0){a=sa;b=sb;c=sc;A=sA;B=sB;C=sC; continue;}
        A-=b;
        b=0;
        if(A<0) {a=sa;b=sb;c=sc;A=sA;B=sB;C=sC; continue;}
        c-=A;
        A=0;
        if(c<0){a=sa;b=sb;c=sc;A=sA;B=sB;C=sC; continue;}
        //cout<<a<<" "<<b<<" "<<c<<" "<<A<<" "<<B<<" "<<C<<endl;
        if(c==B) return true;
    }
    return false;
}
int main(){
    ios_base :: sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin>>n;
    string r;
    string mr;
    string sol="";
    cin>>r>>mr;
    int a=0,b=0,c=0,A=0,B=0,C=0;
    for(int i=0;i<n;i++){
        if(r[i]=='a') a++;
        if(r[i]=='b') b++;
        if(r[i]=='c') c++;
        if(mr[i]=='a') A++;
        if(mr[i]=='b') B++;
        if(mr[i]=='c') C++;
    }
    for(int i=0;i<n;i++){
        if(mr[i]=='a') A--;
        if(mr[i]=='b') B--;
        if(mr[i]=='c') C--;
        for(int j=0;j<3;j++){
            if(j+'a'==mr[i]) continue;
            if(j==0) a--;
            if(j==1) b--;
            if(j==2) c--;
            if(moze(a,b,c,A,B,C)){
                sol.push_back(j+'a');
                break;
            }
            else{
                if(j==0) a++;
                if(j==1) b++;
                if(j==2) c++;
            }
        }
    }
    cout<<sol;
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 504 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 380 KB Output is correct
9 Correct 4 ms 388 KB Output is correct
10 Correct 4 ms 376 KB Output is correct