Submission #12765112


Source Code Expand

Copy
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
            ∧_∧
      ∧_∧  (´<_` )  Welcome to My Coding Space!
     ( ´_ゝ`) /  ⌒i     @hamayanhamayan0
    /   \     | |
    /   / ̄ ̄ ̄ ̄/  |
  __(__ニつ/     _/ .| .|____
     \/____/ (u ⊃
---------------------------------------------------------------------------------------------------*/














int N, A, B, C;
string S[101010];
//---------------------------------------------------------------------------------------------------
vector<char> ans;
bool dfs(int cu, int a, int b, int c) {
	if (cu == N) return true;

	if (S[cu] == "AB") {
		if (a == 0 && b == 0) return false;
		if (0 < a && dfs(cu + 1, a - 1, b + 1, c)) {
			ans.push_back('B');
			return true;
		}
		if (0 < b && dfs(cu + 1, a + 1, b - 1, c)) {
			ans.push_back('A');
			return true;
		}
		return false;
	}

	if (S[cu] == "AC") {
		if (a == 0 && c == 0) return false;
		if (0 < a && dfs(cu + 1, a - 1, b, c + 1)) {
			ans.push_back('C');
			return true;
		}
		if (0 < c && dfs(cu + 1, a + 1, b, c - 1)) {
			ans.push_back('A');
			return true;
		}
		return false;
	}

	if (S[cu] == "BC") {
		if (b == 0 && c == 0) return false;
		if (0 < b && dfs(cu + 1, a, b - 1, c + 1)) {
			ans.push_back('C');
			return true;
		}
		if (0 < c && dfs(cu + 1, a, b + 1, c - 1)) {
			ans.push_back('B');
			return true;
		}
		return false;
	}
}
//---------------------------------------------------------------------------------------------------
void _main() {
	cin >> N >> A >> B >> C;
	rep(i, 0, N) cin >> S[i];

	dfs(0, A, B, C);

	if (ans.size() == 0) cout << "No" << endl;
	else {
		printf("Yes\n");
		reverse(all(ans));
		fore(c, ans) printf("%c\n", c);
	}
}





Submission Info

Submission Time
Task F - Three Variables Game
User hamayanhamayan
Language C++ (GCC 9.2.1)
Score 600
Code Size 2671 Byte
Status AC
Exec Time 30 ms
Memory 14896 KB

Compile Error

./Main.cpp: In function ‘bool dfs(int, int, int, int)’:
./Main.cpp:80:1: warning: control reaches end of non-void function [-Wreturn-type]
   80 | }
      | ^

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 8 ms 6844 KB
Sample_02.txt AC 4 ms 6700 KB
Sample_03.txt AC 4 ms 6704 KB
Sample_04.txt AC 4 ms 6816 KB
killer_01.txt AC 27 ms 14792 KB
killer_02.txt AC 25 ms 14764 KB
killer_03.txt AC 27 ms 14896 KB
killer_04.txt AC 24 ms 14752 KB
killer_05.txt AC 28 ms 14788 KB
killer_06.txt AC 20 ms 6688 KB
killer_07.txt AC 25 ms 14716 KB
killer_08.txt AC 28 ms 14788 KB
killer_09.txt AC 23 ms 14792 KB
killer_10.txt AC 27 ms 14768 KB
one_alive01.txt AC 8 ms 6848 KB
one_alive02.txt AC 5 ms 6820 KB
one_alive03.txt AC 27 ms 14716 KB
one_alive04.txt AC 25 ms 14780 KB
one_death01.txt AC 8 ms 6636 KB
one_death02.txt AC 6 ms 6684 KB
one_death03.txt AC 12 ms 6688 KB
one_death04.txt AC 9 ms 6752 KB
prime_alive01.txt AC 4 ms 6816 KB
prime_alive02.txt AC 6 ms 6824 KB
prime_alive03.txt AC 27 ms 14792 KB
prime_alive04.txt AC 26 ms 14772 KB
prime_alive05.txt AC 24 ms 14820 KB
prime_death01.txt AC 6 ms 6708 KB
prime_death02.txt AC 5 ms 6752 KB
prime_death03.txt AC 16 ms 11252 KB
prime_death04.txt AC 14 ms 9512 KB
prime_death05.txt AC 16 ms 11216 KB
prime_death06.txt AC 14 ms 10464 KB
prime_death07.txt AC 18 ms 11212 KB
prime_death08.txt AC 15 ms 10336 KB
prime_death09.txt AC 13 ms 9524 KB
prime_death10.txt AC 17 ms 10360 KB
superkiller_01.txt AC 24 ms 14656 KB
superkiller_02.txt AC 25 ms 14792 KB
superkiller_03.txt AC 27 ms 14716 KB
superkiller_04.txt AC 24 ms 14792 KB
superkiller_05.txt AC 27 ms 14792 KB
superkiller_06.txt AC 25 ms 14764 KB
superkiller_07.txt AC 25 ms 14656 KB
superkiller_08.txt AC 27 ms 14896 KB
superkiller_09.txt AC 25 ms 14760 KB
superkiller_10.txt AC 30 ms 14788 KB
three_01.txt AC 7 ms 6876 KB
three_02.txt AC 4 ms 6776 KB
three_03.txt AC 27 ms 14724 KB
three_04.txt AC 29 ms 14796 KB
two_01.txt AC 5 ms 6876 KB
two_02.txt AC 5 ms 6772 KB
two_03.txt AC 7 ms 6816 KB
two_04.txt AC 6 ms 6816 KB
two_05.txt AC 6 ms 6836 KB
two_06.txt AC 27 ms 14784 KB
two_07.txt AC 27 ms 14788 KB
two_08.txt AC 30 ms 14668 KB
zero_01.txt AC 12 ms 6644 KB