Submission #1354286

#TimeUsernameProblemLanguageResultExecution timeMemory
1354286WH8Get Hundred Points! (FXCUP4_hundred)C++17
33 / 100
1 ms428 KiB
#include "hundred.h"
#include <bits/stdc++.h>
#define pb push_back
#define all(x) x.begin(),x.end()
using namespace std;

const int maxn=100;
string base;
int a=0;
vector<vector<pair<int,int>>> al(maxn);
map<char, char> m;

int Ask(string tomark){
	for(auto & c : tomark){
		c=m[c];
	}
	return Mark(tomark);
}
string Answer(string ass){
	//cout<<"Answering "<<ass<<endl;
	for(auto & c : ass){
		c=m[c];
	}
	return ass;
}

string GetHundredPoints(int A, int B, int C) {
	//cout<<A<<" "<<B<<" "<<C<<endl;
	m['A']='A';
	m['B']='B';
	m['C']='C';
	if(A==0){
		swap(C, A);
		m['A']='C';
		m['C']='A';
	} // A is nonzero now. 
	for(int i=0;i<A;i++)base+="A";
	for(int i=0;i<B;i++)base+="B";
	for(int i=0;i<C;i++)base+="C";
	if(A==maxn or B==maxn or C==maxn)Answer(base);
	a=Ask(base);
	//cout<<base<<endl;
	//return base;
	for(int i=A;i<maxn;i++){
		auto cur=base;
		swap(cur[i], cur[0]);
		int ret=Ask(cur);
		al[i].pb({0, ret-a});
		al[0].pb({i, ret-a});
		//printf("%d %d delta %d\n", i, 0, ret-a);
	}
	for(int i=1;i<A;i++){
		auto cur=base;
		swap(cur[i], cur[A+1]);
		int ret=Ask(cur);
		al[i].pb({A+1, ret-a});
		al[A+1].pb({i, ret-a});
		//printf("%d %d delta %d\n", i, A+1, ret-a);
	}
	auto notin=[&](char a, char b){
		if('C' != a and 'C' != b) return 'C';
		else if('A' != a and 'A' != b) return 'A';
		else return 'B';
	};
	string ass=base;
	vector<bool> vis(maxn+1, 0);
	auto dfs=[&](auto && dfs, int x, char cur)->bool{
		vis[x]=1;
		//cout<<x<<" "<<cur<<endl;
		ass[x]=cur;
		//for(auto [to, d] : al[x])printf("to %d d %d\n", to, d);
		for(auto [to, d] : al[x]){
			if(vis[to])continue;
			if(d==2){
				if(cur != base[to]) return 0;
				dfs(dfs, to, base[x]);
			}
			else if(d==-2){
				if(cur != base[x]) return 0;
				dfs(dfs, to, base[to]);
			}
			else if(d==1){
				if(cur == base[x]) return 0;
				if(cur == base[to]) dfs(dfs, to, notin(base[to], base[x]));
				else dfs(dfs, to, base[x]);
			}
			else if(d==-1){
				if(cur == base[to]) return 0;
				if(cur == base[x]) dfs(dfs, to, notin(base[to], base[x]));
				else dfs(dfs, to, base[to]);
			}
			else if(d==0){
				dfs(dfs, to, cur);
			}
			else assert(false);
		}
		return 1;
	};
	vector<char> cs={'B', 'A', 'C'};
	for (auto c : cs){
		fill(all(vis), 0);
		bool ok=dfs(dfs, 0, c);
		if(ok and count(all(ass), 'A')==A and count(all(ass), 'B')==B and count(all(ass), 'C')==C) {
			return Answer(ass);
		}
	}
	return "ABCCABCCABCCABCCABCCABCCABCCABCCABCCABCCABCCABCCABCCABCCABCCABCCABCCABCCABCCABCCABCCABCCABCCABCCABCC";
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...