File size: 3,397 Bytes
1fe85dc | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
#include<cstdlib>
int qwerty_getcode(int code) {
return code == 42? 0: 1;
}
namespace std {
void qwerty_exit(int code){
exit(qwerty_getcode(code));
}
} using std::qwerty_exit;
#define exit qwerty_exit
#define main qwerty_main
#include <climits>
#include <set>
#include <vector>
#include "validate.h"
using namespace std;
void to_lower(std::string& s) {
for (char& c : s) c |= 0x20;
}
int main(int argc, char **argv) {
init_io(argc,argv);
int n;
judge_in >> n;
int position = 0;
vector<int> state(n);
for (int i = 0; i < n; i++) {
char c;
judge_in >> c;
state[i] = c - '0';
}
cout << state[position] << endl;
int max_queries = 3*n + 500;
int lim_queries = 5*n + 1000;
int queries_used = 0;
while (true) {
string response;
if (!(author_out >> response)) {
wrong_answer("Wrong answer: failed to read response. Queries used: %d\n", queries_used);
}
if (response == "?") {
queries_used++;
string query;
if (!(author_out >> query)) {
wrong_answer("Wrong answer: failed to read query. Queries used: %d\n", queries_used);
}
to_lower(query);
if (query == "left") {
position = (position + n - 1) % n;
} else if (query == "right") {
position = (position + 1) % n;
} else if (query == "flip") {
state[position] = 1 - state[position];
} else {
wrong_answer("Wrong answer: invalid query type. Queries used: %d\n", queries_used);
}
cout << state[position] << endl;
} else if (response == "!") {
int guess;
if (!(author_out >> guess)) {
wrong_answer("Wrong answer: failed to read guess. Queries used: %d\n", queries_used);
}
string junk;
if (author_out >> junk) {
wrong_answer("Wrong answer: trailing output after guess.\n");
}
if (guess == n) {
if (queries_used > max_queries) {
wrong_answer("Wrong answer: correct guess, but used too many queries. Queries used: %d (%d too many)\n", queries_used, queries_used-max_queries);
}
break;
} else {
wrong_answer("Wrong answer: incorrect guess %d (ans: %d). Queries used: %d\n", guess, n, queries_used);
}
} else {
wrong_answer("Wrong answer: invalid response type. Queries used: %d\n", queries_used);
}
if (queries_used > lim_queries) {
wrong_answer("Wrong answer: used too many queries. Queries used: %d (%d too many, terminated)\n", queries_used, queries_used-max_queries);
}
}
string junk;
if (author_out >> junk) {
wrong_answer("Wrong answer: trailing output.\n");
}
judge_message("Queries used: %d.\n", queries_used);
accept();
}
#undef main
#include<cstdio>
#include<vector>
#include<string>
#include<filesystem>
int main(int argc, char **argv) {
namespace fs = std::filesystem;
char judge_out[] = "/dev";
std::vector<char*> new_argv = {
argv[0], argv[1], argv[2],
judge_out,
};
return qwerty_getcode(qwerty_main((int)new_argv.size(), new_argv.data()));
}
|