#include #include "validate.h" using namespace std; int main(int argc, char **argv) { init_io(argc,argv); int n, q, i, s; int mq = 92000; judge_in >> s >> n; srand(s); int a[n], b[n]; cout << n << endl; for (i = 0; i < n; i++) judge_in >> a[i]; for (q = 0; ; q++) { string qt; if (!(author_out >> qt)) wrong_answer("Wrong answer: premature EOF.\n"); if (qt.compare("!") == 0) break; else if (qt.compare("?") == 0) { int x, y; if (!(author_out >> x >> y)) wrong_answer("Wrong answer: expected two integers.\n"); x--, y--; if (x < 0 || x >= n || y < 0 || y >= n) wrong_answer("Wrong answer: query indices out of range.\n"); if (x == y) wrong_answer("Wrong answer: query indices are identical.\n"); if (rand()%2) swap(a[x], a[y]); // shuffle before printing to print in a random order. cout << a[x] << ' ' << a[y] << endl; if (rand()%2) swap(a[x], a[y]); } else wrong_answer("Wrong answer: expected '?' or '!'.\n"); } if (q > mq) wrong_answer("Wrong answer: Too many guesses: %d (which is %d over).\n", q, q - mq); for (i = 0; i < n; i++) if (!(author_out >> b[i])) wrong_answer("Wrong answer: expected an integer.\n"); for (i = 0; i < n && a[i] == b[i]; i++); if (i < n) wrong_answer("Wrong answer: judge and author answers didn't match on index %d.\n", i); string junk; if (author_out >> junk) wrong_answer("Wrong answer: trailing output.\n"); cerr << "Queries used: " << q + 1 << endl; accept(); }