답안 #300704

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
300704 2020-09-17T12:22:26 Z JPN20 커다란 상품 (IOI17_prize) C++17
100 / 100
62 ms 3192 KB
#include "prize.h"
#include <bits/stdc++.h>
using namespace std;

int p1[1 << 18];
int p2[1 << 18];
int maxn = 0;
vector<int> V;
vector<int> W;

int Rand() {
	return (rand() % 32768) * 32768 + (rand() % 32768);
}

pair<int, int> query(int pos) {
	if (p1[pos] >= 0) return make_pair(p1[pos], p2[pos]);
	vector<int> vec = ask(pos);
	p1[pos] = vec[0];
	p2[pos] = vec[1];
	return make_pair(p1[pos], p2[pos]);
}

void dfs(int cl, int cr, int c1, int c2) {
	//cout << cl << " " << cr << " " << c1 << " " << c2 << endl;
	if (cl == cr) { W.push_back(V[cl]); return; }
	int cm = (cl + cr) / 2;
	int el = -1, e1 = 0;
	int er = -1, e2 = 0;
	for (int i = cm; i >= cl; i--) {
		pair<int, int> T = query(V[i]);
		if (T.first + T.second == maxn) { el = i; e1 = T.first; break; }
		else { W.push_back(V[i]); }
	}
	for (int i = cm; i <= cr; i++) {
		pair<int, int> T = query(V[i]);
		if (T.first + T.second == maxn) { er = i; e2 = T.first; break; }
		else { W.push_back(V[i]); }
	}
	if (el >= 0 && c1 != e1 && cl <= el + 1) dfs(cl, el - 1, c1, e1);
	if (er >= 0 && c2 != e2 && er + 1 <= cr) dfs(er + 1, cr, e2, c2);
}

vector<int> solve() {
	//for (int i = 0; i < V.size(); i++) cout << V[i] << " " ; cout << endl;
	maxn = 0; W.clear();
	for (int i = 0; i < 100; i++) {
		int T = Rand() % V.size();
		pair<int, int> T2 = query(V[T]);
		maxn = max(maxn, T2.first + T2.second);
	}
	//cout << maxn << endl;
	dfs(0, V.size() - 1, 0, maxn);
	return W;
}

int find_best(int n) {
	V.clear();
	W.clear();
	for (int i = 0; i < n; i++) p1[i] = -1;
	for (int i = 0; i < n; i++) p2[i] = -1;
	for (int i = 0; i < n; i++) V.push_back(i);
	while (V.size() >= 2) {
		vector<int> V2 = solve();
		sort(V2.begin(), V2.end());
		V2.erase(unique(V2.begin(), V2.end()), V2.end());
		V = V2;
	}
	return V[0];
}
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 3064 KB Output is correct
2 Correct 5 ms 3064 KB Output is correct
3 Correct 4 ms 3064 KB Output is correct
4 Correct 4 ms 3192 KB Output is correct
5 Correct 4 ms 3192 KB Output is correct
6 Correct 4 ms 3064 KB Output is correct
7 Correct 4 ms 3064 KB Output is correct
8 Correct 4 ms 3064 KB Output is correct
9 Correct 4 ms 3064 KB Output is correct
10 Correct 4 ms 3064 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 3064 KB Output is correct
2 Correct 4 ms 3064 KB Output is correct
3 Correct 4 ms 3064 KB Output is correct
4 Correct 4 ms 3064 KB Output is correct
5 Correct 5 ms 3064 KB Output is correct
6 Correct 4 ms 3192 KB Output is correct
7 Correct 4 ms 3096 KB Output is correct
8 Correct 5 ms 3064 KB Output is correct
9 Correct 4 ms 3064 KB Output is correct
10 Correct 5 ms 3096 KB Output is correct
11 Correct 9 ms 3064 KB Output is correct
12 Correct 9 ms 3064 KB Output is correct
13 Correct 9 ms 3064 KB Output is correct
14 Correct 15 ms 768 KB Output is correct
15 Correct 40 ms 3064 KB Output is correct
16 Correct 45 ms 3064 KB Output is correct
17 Correct 41 ms 3064 KB Output is correct
18 Correct 41 ms 3064 KB Output is correct
19 Correct 42 ms 3064 KB Output is correct
20 Correct 29 ms 1788 KB Output is correct
21 Correct 50 ms 3064 KB Output is correct
22 Correct 32 ms 3064 KB Output is correct
23 Correct 6 ms 3064 KB Output is correct
24 Correct 8 ms 3064 KB Output is correct
25 Correct 38 ms 3064 KB Output is correct
26 Correct 45 ms 3064 KB Output is correct
27 Correct 5 ms 3064 KB Output is correct
28 Correct 41 ms 3064 KB Output is correct
29 Correct 37 ms 3064 KB Output is correct
30 Correct 40 ms 3064 KB Output is correct
31 Correct 43 ms 3064 KB Output is correct
32 Correct 9 ms 3064 KB Output is correct
33 Correct 1 ms 384 KB Output is correct
34 Correct 62 ms 3064 KB Output is correct
35 Correct 6 ms 3064 KB Output is correct
36 Correct 46 ms 3064 KB Output is correct
37 Correct 9 ms 3064 KB Output is correct
38 Correct 6 ms 3064 KB Output is correct
39 Correct 62 ms 3192 KB Output is correct
40 Correct 56 ms 3064 KB Output is correct
41 Correct 45 ms 3064 KB Output is correct
42 Correct 27 ms 3192 KB Output is correct
43 Correct 46 ms 3064 KB Output is correct
44 Correct 59 ms 3064 KB Output is correct
45 Correct 41 ms 3064 KB Output is correct
46 Correct 45 ms 3064 KB Output is correct
47 Correct 36 ms 3064 KB Output is correct
48 Correct 61 ms 3064 KB Output is correct
49 Correct 59 ms 3064 KB Output is correct
50 Correct 44 ms 3064 KB Output is correct
51 Correct 39 ms 3064 KB Output is correct
52 Correct 43 ms 3064 KB Output is correct
53 Correct 5 ms 3192 KB Output is correct
54 Correct 52 ms 3064 KB Output is correct
55 Correct 49 ms 3064 KB Output is correct
56 Correct 28 ms 3096 KB Output is correct
57 Correct 53 ms 3064 KB Output is correct
58 Correct 56 ms 3064 KB Output is correct
59 Correct 49 ms 3064 KB Output is correct
60 Correct 44 ms 3064 KB Output is correct
61 Correct 5 ms 3064 KB Output is correct
62 Correct 5 ms 3064 KB Output is correct
63 Correct 5 ms 3192 KB Output is correct
64 Correct 5 ms 3064 KB Output is correct
65 Correct 4 ms 3064 KB Output is correct
66 Correct 9 ms 3064 KB Output is correct
67 Correct 9 ms 3064 KB Output is correct
68 Correct 9 ms 3064 KB Output is correct
69 Correct 10 ms 3064 KB Output is correct
70 Correct 8 ms 3064 KB Output is correct
71 Correct 45 ms 3064 KB Output is correct
72 Correct 9 ms 3064 KB Output is correct
73 Correct 46 ms 3064 KB Output is correct
74 Correct 37 ms 3064 KB Output is correct
75 Correct 6 ms 3064 KB Output is correct
76 Correct 43 ms 3192 KB Output is correct
77 Correct 58 ms 3064 KB Output is correct
78 Correct 8 ms 3064 KB Output is correct
79 Correct 25 ms 3064 KB Output is correct
80 Correct 44 ms 3064 KB Output is correct
81 Correct 44 ms 3064 KB Output is correct
82 Correct 44 ms 3064 KB Output is correct
83 Correct 5 ms 3064 KB Output is correct
84 Correct 36 ms 3064 KB Output is correct
85 Correct 47 ms 3064 KB Output is correct
86 Correct 20 ms 3064 KB Output is correct
87 Correct 10 ms 3064 KB Output is correct
88 Correct 12 ms 3064 KB Output is correct
89 Correct 17 ms 3064 KB Output is correct
90 Correct 6 ms 3064 KB Output is correct
91 Correct 17 ms 3064 KB Output is correct
92 Correct 17 ms 3064 KB Output is correct
93 Correct 6 ms 3064 KB Output is correct
94 Correct 6 ms 3064 KB Output is correct
95 Correct 5 ms 3064 KB Output is correct
96 Correct 6 ms 3064 KB Output is correct
97 Correct 5 ms 3064 KB Output is correct