Submission #256744

# Submission time Handle Problem Language Result Execution time Memory
256744 2020-08-03T07:37:01 Z spacewalker The Big Prize (IOI17_prize) C++14
97.67 / 100
64 ms 2028 KB
#include <bits/stdc++.h>
#include "prize.h"

using namespace std;
constexpr int NMAX = 200000;
constexpr int NORMIE_MAX = 475;

int lessLeft[NMAX];
int lessRight[NMAX];

int totalHigher = -1;

pair<int, int> query(int i) {
	if (lessLeft[i] == -1) {
		vector<int> ans = ask(i);
		lessLeft[i] = ans[0];
		lessRight[i] = ans[1];
	}
	return {lessLeft[i], lessRight[i]};
}

int higherThan(int i) {
	auto [lx, ly] = query(i);
	return lx + ly;
}

int findAllValuables(int i, int j, int valBefore, int valAfter, vector<int> &ans) {
//	printf("FNV %d %d %d %d\n", i, j, valBefore, valAfter);
	if (i > j) return -1;
	else {
		int k = (i + j) / 2;
		int nonValBefore, nonValAfter;
		for (nonValAfter = k; nonValAfter <= j && higherThan(nonValAfter) != totalHigher; ++nonValAfter) {
			if (higherThan(nonValAfter) == 0) return nonValAfter;
			ans.push_back(nonValAfter);
		}
		for (nonValBefore = k; nonValBefore >= i && higherThan(nonValBefore) != totalHigher; --nonValBefore) {
			if (higherThan(nonValBefore) == 0) return nonValBefore;
			ans.push_back(nonValBefore);
		}
		if (lessLeft[nonValBefore] != valBefore) {
			int potAns = findAllValuables(i, nonValBefore - 1, valBefore, lessRight[nonValBefore], ans);
			if (potAns != -1) return potAns;
		}
		if (lessRight[nonValAfter] != valAfter) {
			int potAns = findAllValuables(nonValAfter + 1, j, lessLeft[nonValAfter], valAfter, ans);
			if (potAns != -1) return potAns;
		}
		return -1;
	}
}

int find_best(int n) {
	memset(lessLeft, -1, sizeof lessLeft);
	memset(lessRight, -1, sizeof lessRight);
	if (n <= NORMIE_MAX) {
		for (int i = 0; i < n - 1; ++i) {
			if (higherThan(i) == 0) return i;
		}
	}
	for (int i = 0; i < NORMIE_MAX; ++i) {
		totalHigher = max(totalHigher, higherThan(i));
	}
	int firstNonValuable = -1;
	for (int i = 0; i < n; ++i) {
		if (higherThan(i) == totalHigher) {
			firstNonValuable = i;
			break;
		}
	}
	vector<int> vToCheck;
	for (int i = 0; i < firstNonValuable; ++i) vToCheck.push_back(i);
	int potAns = findAllValuables(firstNonValuable + 1, n - 1, query(firstNonValuable).first, 0, vToCheck);
	if (potAns != -1) return potAns;
	for (int i : vToCheck) {
		if (higherThan(i) == 0) return i;
	}
	return 0;
}

Compilation message

prize.cpp: In function 'int higherThan(int)':
prize.cpp:23:7: warning: decomposition declaration only available with -std=c++1z or -std=gnu++1z
  auto [lx, ly] = query(i);
       ^
# Verdict Execution time Memory Grader output
1 Correct 8 ms 1912 KB Output is correct
2 Correct 5 ms 1920 KB Output is correct
3 Correct 6 ms 1912 KB Output is correct
4 Correct 4 ms 1920 KB Output is correct
5 Correct 6 ms 1920 KB Output is correct
6 Correct 6 ms 1920 KB Output is correct
7 Correct 7 ms 1920 KB Output is correct
8 Correct 5 ms 1920 KB Output is correct
9 Correct 7 ms 1920 KB Output is correct
10 Correct 5 ms 1920 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 1920 KB Output is correct
2 Correct 9 ms 1912 KB Output is correct
3 Correct 7 ms 1912 KB Output is correct
4 Correct 7 ms 1920 KB Output is correct
5 Correct 4 ms 1896 KB Output is correct
6 Correct 7 ms 1912 KB Output is correct
7 Correct 7 ms 1920 KB Output is correct
8 Correct 7 ms 1912 KB Output is correct
9 Correct 6 ms 1912 KB Output is correct
10 Correct 10 ms 1920 KB Output is correct
11 Correct 13 ms 1920 KB Output is correct
12 Correct 6 ms 1920 KB Output is correct
13 Correct 13 ms 1912 KB Output is correct
14 Correct 8 ms 1920 KB Output is correct
15 Correct 15 ms 1920 KB Output is correct
16 Correct 51 ms 1912 KB Output is correct
17 Correct 8 ms 1912 KB Output is correct
18 Partially correct 64 ms 1912 KB Partially correct - number of queries: 5075
19 Correct 8 ms 1920 KB Output is correct
20 Correct 18 ms 1920 KB Output is correct
21 Correct 25 ms 1912 KB Output is correct
22 Correct 8 ms 1912 KB Output is correct
23 Correct 8 ms 1904 KB Output is correct
24 Correct 8 ms 1912 KB Output is correct
25 Correct 30 ms 1916 KB Output is correct
26 Correct 30 ms 1912 KB Output is correct
27 Correct 9 ms 1920 KB Output is correct
28 Correct 44 ms 1920 KB Output is correct
29 Correct 53 ms 1920 KB Output is correct
30 Partially correct 48 ms 1920 KB Partially correct - number of queries: 5039
31 Correct 5 ms 1912 KB Output is correct
32 Correct 12 ms 1920 KB Output is correct
33 Correct 1 ms 1920 KB Output is correct
34 Correct 29 ms 1928 KB Output is correct
35 Correct 7 ms 1920 KB Output is correct
36 Correct 22 ms 1936 KB Output is correct
37 Correct 7 ms 1900 KB Output is correct
38 Correct 8 ms 1920 KB Output is correct
39 Correct 29 ms 1904 KB Output is correct
40 Correct 43 ms 1896 KB Output is correct
41 Correct 25 ms 1928 KB Output is correct
42 Correct 26 ms 1932 KB Output is correct
43 Correct 29 ms 1928 KB Output is correct
44 Correct 20 ms 1920 KB Output is correct
45 Correct 18 ms 1916 KB Output is correct
46 Correct 6 ms 1912 KB Output is correct
47 Correct 26 ms 1920 KB Output is correct
48 Correct 33 ms 1912 KB Output is correct
49 Correct 11 ms 1920 KB Output is correct
50 Partially correct 55 ms 1920 KB Partially correct - number of queries: 5078
51 Correct 20 ms 1920 KB Output is correct
52 Correct 6 ms 1920 KB Output is correct
53 Correct 4 ms 1900 KB Output is correct
54 Correct 34 ms 1920 KB Output is correct
55 Correct 6 ms 1912 KB Output is correct
56 Partially correct 64 ms 1936 KB Partially correct - number of queries: 5066
57 Correct 36 ms 2028 KB Output is correct
58 Correct 48 ms 1920 KB Output is correct
59 Correct 35 ms 1912 KB Output is correct
60 Correct 41 ms 1912 KB Output is correct
61 Correct 10 ms 1920 KB Output is correct
62 Correct 4 ms 1912 KB Output is correct
63 Correct 7 ms 1912 KB Output is correct
64 Correct 6 ms 1920 KB Output is correct
65 Correct 6 ms 1920 KB Output is correct
66 Correct 8 ms 1912 KB Output is correct
67 Correct 13 ms 1920 KB Output is correct
68 Correct 5 ms 1920 KB Output is correct
69 Correct 10 ms 1920 KB Output is correct
70 Correct 6 ms 1920 KB Output is correct
71 Partially correct 45 ms 1920 KB Partially correct - number of queries: 5233
72 Correct 12 ms 1908 KB Output is correct
73 Partially correct 58 ms 1932 KB Partially correct - number of queries: 5170
74 Partially correct 50 ms 1896 KB Partially correct - number of queries: 5197
75 Correct 5 ms 1920 KB Output is correct
76 Correct 35 ms 1936 KB Output is correct
77 Partially correct 48 ms 1920 KB Partially correct - number of queries: 5198
78 Correct 12 ms 1920 KB Output is correct
79 Correct 30 ms 1920 KB Output is correct
80 Partially correct 54 ms 1936 KB Partially correct - number of queries: 5181
81 Partially correct 59 ms 1932 KB Partially correct - number of queries: 5194
82 Partially correct 52 ms 1944 KB Partially correct - number of queries: 5150
83 Correct 7 ms 1920 KB Output is correct
84 Correct 35 ms 1920 KB Output is correct
85 Partially correct 34 ms 1920 KB Partially correct - number of queries: 5221
86 Correct 6 ms 1920 KB Output is correct
87 Correct 5 ms 1920 KB Output is correct
88 Correct 7 ms 1920 KB Output is correct
89 Correct 9 ms 1920 KB Output is correct
90 Correct 5 ms 1904 KB Output is correct
91 Correct 7 ms 1920 KB Output is correct
92 Correct 7 ms 1920 KB Output is correct
93 Correct 11 ms 1920 KB Output is correct
94 Correct 9 ms 1920 KB Output is correct
95 Correct 14 ms 1920 KB Output is correct
96 Correct 6 ms 1920 KB Output is correct
97 Correct 5 ms 1936 KB Output is correct