File size: 1,326 Bytes
5fed0fc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#include "testlib.h"
#include <bits/stdc++.h>

int main(int argc, char ** argv){
	registerInteraction(argc, argv);

	int n = inf.readInt();
	println(n);

	std::vector<int> o(n);
	for (int i = 0; i < n; i++) {
		o[i] = inf.readInt();
	}

	for (int q = 0; q <= 600; q++) {
		std::string op = ouf.readToken();
		if (op == "?") {
			int res = ouf.readInt();
			if (res < 0 || res >= 1000000007) {
				quitf(_wa, "Invalid query: element %d is out of range [1, 1000000006]", res);
			}

			for (int i = 0; i < n; i++) {
				int x = ouf.readInt();
				if (x < 0 || x >= 1000000007) {
					quitf(_wa, "Invalid query: element %d is out of range [1, 1000000006]", x);
				}

				res = (o[i] == 0 ? (res + x) % 1000000007 : 1ll * res * x % 1000000007);
			}

			println(res);
		} else if (op == "!") {
			std::vector<int> guess(n);
			for (int i = 0; i < n; i++) {
				guess[i] = ouf.readInt();
			}

			if (guess == o) {
				double ratio_unbounded = (40.0 + 1) / (q + 1);
				double ratio = std::min(1.0, ratio_unbounded);
				quitp(ratio, "Correct guess. Ratio: %.4f, RatioUnbounded: %.4f", ratio, ratio_unbounded);
			} else {
				quitp(0., "Wrong guess. Ratio: 0.0000");
			}
		} else {
			quitf(_wa, "Invalid action type: expected ? or !, but got %s", op.c_str());
		}
	}
	quitp(0., "Too many queries. Ratio: 0.0000");

	return 0;
}