Submission #477057

#TimeUsernameProblemLanguageResultExecution timeMemory
477057Genius3435Combo (IOI18_combo)C++17
30 / 100
39 ms288 KiB
#include "combo.h"

#include <algorithm>
#include <chrono>
#include <random>
#include <string>
#include <ctime>

using namespace std::string_literals;

const int t = std::chrono::high_resolution_clock::now().time_since_epoch().count();

inline int gen(int i) {
	static std::mt19937 rng = std::mt19937(t%10000/10);
	return rng() % i;
}

std::string guess_sequence(int N) {
	std::string cur; cur.resize(N);

	for (const char c: "ABXY") {
		if (press(""s+c)) {
			cur[0] = c; break;
		}
	}

	char poss[N][3], ind[N];
	for (int i = 1; i < N; ++i) {
		for (int k = 0, j = 0; j < 4; ++j)
			if ("ABXY"[j] != cur[0]) poss[i][k++] = "ABXY"[j];
		std::random_shuffle(poss[i], poss[i]+3, gen);
		ind[i] = 0, cur[i] = poss[i][0];
	}

	for (int known = 1; known < N; ) {
		if ((known = press(cur)) == N) break;
		cur[known] = poss[known][++ind[known]];
	}
	return cur;
}

Compilation message (stderr)

combo.cpp: In function 'std::string guess_sequence(int)':
combo.cpp:37:28: warning: array subscript has type 'char' [-Wchar-subscripts]
   37 |   cur[known] = poss[known][++ind[known]];
      |                            ^~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...