Submission #15585466


Source Code Expand

Copy
#include <bits/stdc++.h>
using namespace std;
int main(){
  	ios_base::sync_with_stdio(0);
  	cin.tie(0);
    int n;
    vector<int> seq(3);
    cin >> n;
    for(auto &x : seq){
        cin>>x;
    }
    vector<string> choice(n);
    for(auto &x : choice){
        cin>>x;
    }
    string ans;
    function<bool(int)> solve = [&](int i){
        if(seq[0]<0 || seq[1]<0 || seq[2]<0) return false;
        if(i==n) return true;

        ans.push_back(choice[i][0]);
        seq[choice[i][0] - 'A']++;
        seq[choice[i][1] - 'A']--;

        if(solve(i+1)){
            return true;
        }

        ans.pop_back();
        seq[choice[i][0] - 'A']--;
        seq[choice[i][1] - 'A']++;

        ans.push_back(choice[i][1]);
        seq[choice[i][0] - 'A']--;
        seq[choice[i][1] - 'A']++;

        if(solve(i+1)){
            return true;
        }
        
        ans.pop_back();
        seq[choice[i][0] - 'A']++;
        seq[choice[i][1] - 'A']--;

        return false;
    };
    if(solve(0)){
        cout<<"Yes\n";
        for(const auto &c : ans){
            cout<<c<<"\n";
        }
    }
    else{
        cout<<"No\n";
    }
}

Submission Info

Submission Time
Task F - Three Variables Game
User Everule
Language C++ (GCC 9.2.1)
Score 600
Code Size 1205 Byte
Status AC
Exec Time 38 ms
Memory 16048 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 600 / 600
Status
AC × 4
AC × 60
Set Name Test Cases
Sample Sample_01.txt, Sample_02.txt, Sample_03.txt, Sample_04.txt
All Sample_01.txt, Sample_02.txt, Sample_03.txt, Sample_04.txt, killer_01.txt, killer_02.txt, killer_03.txt, killer_04.txt, killer_05.txt, killer_06.txt, killer_07.txt, killer_08.txt, killer_09.txt, killer_10.txt, one_alive01.txt, one_alive02.txt, one_alive03.txt, one_alive04.txt, one_death01.txt, one_death02.txt, one_death03.txt, one_death04.txt, prime_alive01.txt, prime_alive02.txt, prime_alive03.txt, prime_alive04.txt, prime_alive05.txt, prime_death01.txt, prime_death02.txt, prime_death03.txt, prime_death04.txt, prime_death05.txt, prime_death06.txt, prime_death07.txt, prime_death08.txt, prime_death09.txt, prime_death10.txt, superkiller_01.txt, superkiller_02.txt, superkiller_03.txt, superkiller_04.txt, superkiller_05.txt, superkiller_06.txt, superkiller_07.txt, superkiller_08.txt, superkiller_09.txt, superkiller_10.txt, three_01.txt, three_02.txt, three_03.txt, three_04.txt, two_01.txt, two_02.txt, two_03.txt, two_04.txt, two_05.txt, two_06.txt, two_07.txt, two_08.txt, zero_01.txt
Case Name Status Exec Time Memory
Sample_01.txt AC 7 ms 3560 KB
Sample_02.txt AC 2 ms 3564 KB
Sample_03.txt AC 2 ms 3492 KB
Sample_04.txt AC 2 ms 3640 KB
killer_01.txt AC 32 ms 15880 KB
killer_02.txt AC 31 ms 16004 KB
killer_03.txt AC 32 ms 15876 KB
killer_04.txt AC 29 ms 16032 KB
killer_05.txt AC 33 ms 15952 KB
killer_06.txt AC 16 ms 6200 KB
killer_07.txt AC 34 ms 15880 KB
killer_08.txt AC 31 ms 15824 KB
killer_09.txt AC 34 ms 15956 KB
killer_10.txt AC 29 ms 15888 KB
one_alive01.txt AC 3 ms 3492 KB
one_alive02.txt AC 2 ms 3548 KB
one_alive03.txt AC 25 ms 16000 KB
one_alive04.txt AC 31 ms 15956 KB
one_death01.txt AC 4 ms 3624 KB
one_death02.txt AC 3 ms 3436 KB
one_death03.txt AC 14 ms 6288 KB
one_death04.txt AC 17 ms 6204 KB
prime_alive01.txt AC 2 ms 3532 KB
prime_alive02.txt AC 3 ms 3592 KB
prime_alive03.txt AC 38 ms 15956 KB
prime_alive04.txt AC 32 ms 15940 KB
prime_alive05.txt AC 28 ms 15892 KB
prime_death01.txt AC 7 ms 3596 KB
prime_death02.txt AC 2 ms 3632 KB
prime_death03.txt AC 23 ms 11560 KB
prime_death04.txt AC 19 ms 8552 KB
prime_death05.txt AC 24 ms 11588 KB
prime_death06.txt AC 15 ms 9988 KB
prime_death07.txt AC 25 ms 11640 KB
prime_death08.txt AC 14 ms 9984 KB
prime_death09.txt AC 19 ms 8288 KB
prime_death10.txt AC 19 ms 9852 KB
superkiller_01.txt AC 31 ms 16048 KB
superkiller_02.txt AC 26 ms 15940 KB
superkiller_03.txt AC 31 ms 15920 KB
superkiller_04.txt AC 32 ms 15988 KB
superkiller_05.txt AC 33 ms 16048 KB
superkiller_06.txt AC 26 ms 15940 KB
superkiller_07.txt AC 33 ms 15972 KB
superkiller_08.txt AC 27 ms 15864 KB
superkiller_09.txt AC 32 ms 15864 KB
superkiller_10.txt AC 31 ms 16028 KB
three_01.txt AC 5 ms 3528 KB
three_02.txt AC 2 ms 3488 KB
three_03.txt AC 31 ms 16000 KB
three_04.txt AC 30 ms 15876 KB
two_01.txt AC 3 ms 3544 KB
two_02.txt AC 2 ms 3468 KB
two_03.txt AC 3 ms 3636 KB
two_04.txt AC 2 ms 3432 KB
two_05.txt AC 2 ms 3492 KB
two_06.txt AC 30 ms 15820 KB
two_07.txt AC 28 ms 15880 KB
two_08.txt AC 24 ms 15992 KB
zero_01.txt AC 18 ms 6288 KB