Submission #1264636

#TimeUsernameProblemLanguageResultExecution timeMemory
1264636wedonttalkanymoreCombo (IOI18_combo)C++20
100 / 100
7 ms484 KiB
 #include "combo.h"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

//#define int long long
#define pii pair<ll, ll>
#define fi first
#define se second

const ll MAXX = 2e5 + 5, inf = 1e9, mod = 1e9 + 7, block = 320, lim = 16;

//namespace {
//
//constexpr int MAX_N = 2000;
//constexpr int MAX_NUM_MOVES = 8000;
//
//int N;
//std::string S;
//
//int num_moves = 0;
//
//void wrong_answer(const char *MSG) {
//  printf("Wrong Answer: %s\n", MSG);
//  exit(0);
//}
//
//}  // namespace
//
//int press(std::string p) {
//	cout << p << ' ' << num_moves << '\n';
//  if (++num_moves > MAX_NUM_MOVES) {
//  	cout << num_moves << '\n';
//    wrong_answer("too many moves");
//  }
//  int len = p.length();
//  if (len > 4 * N) {
//    wrong_answer("invalid press");
//  }
//  for (int i = 0; i < len; ++i) {
//    if (p[i] != 'A' && p[i] != 'B' && p[i] != 'X' && p[i] != 'Y') {
//      wrong_answer("invalid press");
//    }
//  }
//  int coins = 0;
//  for (int i = 0, j = 0; i < len; ++i) {
//    if (j < N && S[j] == p[i]) {
//      ++j;
//    } else if (S[0] == p[i]) {
//      j = 1;
//    } else {
//      j = 0;
//    }
//    coins = std::max(coins, j);
//  }
//  return coins;
//}

string convert(string &ans, vector <char> &unbanned) {
	string t = ans;
	t += unbanned[0];
	t += unbanned[0];
	t += ans;
	t += unbanned[0];
	t += unbanned[1];
	t += ans;
	t += unbanned[0];
	t += unbanned[2];
	t += ans;
	t += unbanned[1];
	return t;
//	ans + (to_string)unbanned[0] + (to_string)unbanned[0] + 
//	ans + (to_string)unbanned[0] + (to_string)unbanned[1] + 
//	ans + (to_string)unbanned[0] + (to_string)unbanned[2] + 
//	ans + (to_string)unbanned[1];
}

map <char, int> mp;
string guess_sequence(int N) {
	mp['A'] = 1, mp['B'] = 2, mp['X'] = 3, mp['Y'] = 4;
	string ans = "";
	int begin = 0;
	int t = press("AB");
	if (t) {
		int t1 = press("A");
		if (t1) ans += "A";
		else ans += "B";
		if (t1) begin = 1;
		else begin = 2;
	}
	else {
		int t1 = press("X");
		if (t1) ans += "X";
		else ans += "Y";
		if (t1) begin = 3;
		else begin = 4;
	}
	if ((int)ans.size() == N) return ans;
	vector <char> unbanned;
	for (auto i : mp) {
		if (begin != i.se) unbanned.push_back(i.fi);
//		cout << i.fi << ' ';
	}
	while((int)ans.size() < N - 1) {
        string pre = convert(ans, unbanned);
        int t = press(pre);
        if (t == ans.size()) ans += unbanned[2];
        else if (t == ans.size() + 1) ans += unbanned[1];
        else if (t == ans.size() + 2) ans += unbanned[0];
	}
	// for (auto i : unbanned) {
    {
        string tmp = ans;
		tmp += unbanned[0];
		int t = press(tmp);
		if (t == N) return tmp;
        tmp = ans;
		tmp += unbanned[1];
		t = press(tmp);
		if (t == N) return tmp;
        tmp = ans;
        tmp += unbanned[2];
        return tmp;
    }
	// }
//    return ans;
}

//int main() {
//  char buffer[MAX_N + 1];
//  if (scanf("%s", buffer) != 1) {
//    fprintf(stderr, "Error while reading input\n");
//    exit(1);
//  }
//  S = buffer;
//  N = S.length();
//
//  num_moves = 0;
//  std::string answer = guess_sequence(N);
//  if (answer != S) {
//    wrong_answer("wrong guess");
//    exit(0);
//  }
//  printf("Accepted: %d\n", num_moves);
//  return 0;
//}
//

#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...