Submission #148058

# Submission time Handle Problem Language Result Execution time Memory
148058 2019-08-31T12:41:34 Z .(#3664, khsoo01) Get Hundred Points! (FXCUP4_hundred) C++17
100 / 100
9 ms 384 KB
#include "hundred.h"
#include<bits/stdc++.h>
#define X first
#define Y second
using namespace std;

typedef pair<int,int> pii;
const int N = 105;

pii par[N];

bool Test (int A, int B, int C, string R, string T, int V) {
	int RA = 0, RB = 0, RC = 0;
	for(int i=0;i<A+B+C;i++) {
		if(R[i] == 'A') RA++;
		if(R[i] == 'B') RB++;
		if(R[i] == 'C') RC++;
	}
	if(A != RA || B != RB || C != RC) return false;
	int RV = 0;
	for(int i=0;i<A+B+C;i++) {
		if(R[i] == T[i]) RV++;
	}
	return (V == RV);
}

string GetHundredPoints(int _A, int _B, int _C) {
	int cnt[3] = {_A, _B, _C};
	string def;
	for(int i=0;i<3;i++) {
		if(!cnt[i]) continue;
		def.push_back('A'+i);
		cnt[i]--;
	}
	for(int i=0;i<3;i++) {
		while(cnt[i]--) {
			def.push_back('A'+i);
		}
	}
	if(!_A+!_B+!_C==2) return def;
	int dv = Mark(def);
	for(int i=_A+_B+_C-1;i;i--) {
		int j;
		for(j=0;def[i]==def[j];j++);
		swap(def[i], def[j]);
		int T = Mark(def);
		swap(def[i], def[j]);
		par[i] = {j, T - dv};
	}
	for(int k=0;k<3;k++) {
		string R;
		R.push_back('A'+k);
		bool mosun = false;
		for(int i=1;i<_A+_B+_C;i++) {
			int P, Q;
			tie(P, Q) = par[i];
			char A = def[P], B = def[i];
			char C = (3*'A'+3) - ((int)A + B);
			if(Q == 2) {
				if(R[P] != B) {mosun = true; break;}
				R.push_back(A);
			}
			else if(Q == 1) {
				if(R[P] == B) R.push_back(C);
				else if(R[P] == C) R.push_back(A);
				else {mosun = true; break;}
			}
			else if(Q == 0) {
				R.push_back(R[P]);
			}
			else if(Q == -1) {
				if(R[P] == A) R.push_back(C);
				else if(R[P] == C) R.push_back(B);
				else {mosun = true; break;}
			}
			else if(Q == -2) {
				if(R[P] != A) {mosun = true; break;}
				R.push_back(B);
			}
			else {mosun = true; break;}
		}
		if(mosun) continue;
		if(Test(_A, _B, _C, R, def, dv)) return R;
	}
	return "";
}
# Verdict Execution time Memory Grader output
1 Correct 7 ms 256 KB Output is correct
2 Correct 7 ms 256 KB Output is correct
3 Correct 6 ms 256 KB Output is correct
4 Correct 8 ms 256 KB Output is correct
5 Correct 9 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 256 KB Output is correct
2 Correct 7 ms 256 KB Output is correct
3 Correct 6 ms 256 KB Output is correct
4 Correct 8 ms 256 KB Output is correct
5 Correct 9 ms 384 KB Output is correct
6 Correct 8 ms 344 KB Output is correct
7 Correct 7 ms 256 KB Output is correct
8 Correct 7 ms 256 KB Output is correct
9 Correct 7 ms 384 KB Output is correct
10 Correct 6 ms 344 KB Output is correct
11 Correct 6 ms 256 KB Output is correct
12 Correct 6 ms 256 KB Output is correct
13 Correct 7 ms 256 KB Output is correct
14 Correct 7 ms 384 KB Output is correct
15 Correct 7 ms 344 KB Output is correct
16 Correct 7 ms 256 KB Output is correct