Submission #348353

#TimeUsernameProblemLanguageResultExecution timeMemory
348353NachoLibreCombo (IOI18_combo)C++14
100 / 100
46 ms568 KiB
#include <bits/stdc++.h>
using namespace std;

#ifdef wambule
string cs;
int press(string s) {
	int dr = 0;
	for(int i = 0; i < s.size(); ++i) {
		for(int j = i; j < min((int)s.size(), i + (int)cs.size()); ++j) {
			if(s[j] != cs[j - i]) {
				dr = max(dr, j - i);
				break;
			}
			if(j + 1 == (int)s.size() || j + 1 == i + (int)cs.size()) {
				dr = max(dr, j - i + 1);
			}
		}
	}
	return dr;
}
#else
#include "combo.h"
#endif

string s = "";

int ask(vector<string> v) {
	assert(v.size() < 5);
	string c = "";
	for(string t : v) {
		c += s + t;
	}
	return press(c) - (int)s.size();
}

string guess_sequence(int n) {
	string c[] = {"X", "Y", "A", "B"};
	s = "";
	if(!ask({c[0], c[1]})) {
		swap(c[0], c[2]);
		swap(c[1], c[3]);
	}
	if(!ask({c[0]})) swap(c[0], c[1]);
	s = c[0];
	swap(c[0], c[3]);
	if(n == 1) return s;
	for(int i = 2; i < n; ++i) {
		int x = ask({c[0] + c[0], c[0] + c[1], c[0] + c[2], c[1]});
		if(x == 2) {
			s += c[0];
		} else if(x == 1) {
			s += c[1];
		} else {
			s += c[2];
		}
	}
	if(ask({c[0]})) s += c[0];
	else if(ask({c[1]})) s += c[1];
	else s += c[2];
	return s;
}

#ifdef wambule
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	srand(time(0));
	int y = 0;
	while(true) {
		if(0) {
			string c[] = {"X", "Y", "A", "B"};
			int x = rand() % 4;
			swap(c[3], c[x]);
			cs = c[3];
			for(int i = 0; i < 2000; ++i) {
				x = rand() % 3;
				cs += c[x];
			}
			string t = guess_sequence(cs.size());
			if(t != cs) {
				cout << cs << "\n" << t << endl;
				cin.get();
			} else if(y % 1 == 0) {
				cout << y << endl;
			}
			++y;
		} else {
			cin >> cs;
			string t = guess_sequence(cs.size());
			cout << "[" << (t == cs) << "] " << t << endl;
		}
	}
	return 0;
}
#endif
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...