Submission #148276

# Submission time Handle Problem Language Result Execution time Memory
148276 2019-08-31T19:39:50 Z ksun48(#3707, ksun48) Get Hundred Points! (FXCUP4_hundred) C++17
100 / 100
8 ms 384 KB
#include "hundred.h"
#include <bits/stdc++.h>

std::string GetHundredPoints(int A, int B, int C) {
	using namespace std;
	assert(A + B + C == 100);
	string str;
	for(int i = 0; i < A; i++) str += 'A';
	for(int i = 0; i < B; i++) str += 'B';
	for(int i = 0; i < C; i++) str += 'C';
	if(A == 100) return string(100, 'A');
	if(B == 100) return string(100, 'B');
	if(C == 100) return string(100, 'C');
	
	string ans(A + B + C, 'A');
	int value = Mark(str);
	auto f = [&](int a, int b){
		string new_str = str;
		swap(new_str[a], new_str[b]);
		int diff = (Mark(new_str) - value) * (str[b] - str[a]) % 3;
		if(diff < 0) diff += 3;
		ans[b] = ((ans[a] - 'A' + diff) % 3) + 'A';
	};
	if(A && B && C){
		for(int i = A; i < A+B; i++) f(0, i);
		for(int i = 1; i < A; i++) f(A, i);
		for(int i = A+B; i < A+B+C; i++) f(A, i);
	} else {
		int a = A ? A : B;
		int b = C ? C : B;
		for(int i = a; i < a + b; i++) f(0, i);
		for(int i = 1; i < a; i++) f(a, i);
	}
	for(int i = 0; i < 3; i++){
		map<char	, int> cnt;
		for(char x : ans) cnt[x] += 1;
		if(cnt['A'] == A && cnt['B'] == B && cnt['C'] == C) return ans;
		for(char& x : ans) x = 'A' + ((x - 'A' + 1) % 3);
	}
	assert(false);
}
# Verdict Execution time Memory Grader output
1 Correct 6 ms 364 KB Output is correct
2 Correct 7 ms 256 KB Output is correct
3 Correct 7 ms 256 KB Output is correct
4 Correct 7 ms 344 KB Output is correct
5 Correct 7 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 364 KB Output is correct
2 Correct 7 ms 256 KB Output is correct
3 Correct 7 ms 256 KB Output is correct
4 Correct 7 ms 344 KB Output is correct
5 Correct 7 ms 384 KB Output is correct
6 Correct 6 ms 256 KB Output is correct
7 Correct 7 ms 384 KB Output is correct
8 Correct 7 ms 256 KB Output is correct
9 Correct 7 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 6 ms 256 KB Output is correct
12 Correct 6 ms 384 KB Output is correct
13 Correct 7 ms 384 KB Output is correct
14 Correct 7 ms 384 KB Output is correct
15 Correct 8 ms 304 KB Output is correct
16 Correct 7 ms 256 KB Output is correct