답안 #39399

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
39399 2018-01-13T19:17:53 Z mohammad_kilani 커다란 상품 (IOI17_prize) C++14
100 / 100
69 ms 7232 KB
#include "prize.h"
#include <bits/stdc++.h>
using namespace std;
const int N = 200010;
#define oo 2000000000
bool asked[N];
vector<int> answer[N] , v;
vector< pair<int,int> > v2;
int mx = 0 ;

vector<int> get(int i){
	if(asked[i])
		return answer[i];
	asked[i] = true;
	answer[i] = ask(i);
	if(answer[i][0] + answer[i][1] == mx) v2.push_back(make_pair(answer[i][0],i)); else v.push_back(i);
	return answer[i];
}

int solve(int s,int e){
	int res = e;
	vector<int> v1 = get(s);
	while(e >= s){
		int mid = (s + e) / 2;
		vector<int> cur = get(mid);
		if(cur[0] + cur[1] == mx && cur[0] == v1[0])
			s = mid + 1;
		else {
			res = mid;
			e = mid - 1;
		}
	}
	return res;
}

int find_best(int n) {
	int num = sqrt(n) - 2;
	int it = 0;
	if(n <= 5000){
		for(int i=0;i<n;i++){
			vector<int> cur = get(i);
			if(cur[0]+cur[1] == 0) return i;
		}
	}
	for(int i=0;i<n && it < 480;i+=num){
		vector<int> res = get(i);
		int cur = res[0] + res[1];
		mx = max(mx,cur);
		it++;
	}
	for(int i=1;i<n && it < 480;i+=num){
		it++;
		vector<int> res = get(i);
		int cur = res[0] + res[1];
		mx = max(mx,cur);
	}
	int low = 0;
	while(true){
		int high = n - 1;
		vector<int> cur = get(low);
		if(cur[0] + cur[1] == 0) return low;
		if(cur[0] + cur[1] != mx){
			low++;
			continue;
		}
		for(int i=0;i<v2.size();i++){
			if(v2[i].second >= low && v2[i].first != cur[0]){
				high = min(high,v2[i].second);
			}
			else if(v2[i].second >= low){
				low = max(low,v2[i].second);
			}
		}
		bool flag = false;
		for(int i=0;i<v.size();i++){
			vector<int> tmp = get(v[i]);
			if(tmp[0] + tmp[1] == 0) return v[i];
			if(v[i] > low){
				high = min(high,v[i]);
			}
		}
		if(flag) continue;
		low = solve(low,high);
	}
	return 0;
}

Compilation message

prize.cpp: In function 'int find_best(int)':
prize.cpp:66:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int i=0;i<v2.size();i++){
                ^
prize.cpp:75:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int i=0;i<v.size();i++){
                ^
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 6912 KB Output is correct
2 Correct 0 ms 6912 KB Output is correct
3 Correct 6 ms 6912 KB Output is correct
4 Correct 6 ms 6912 KB Output is correct
5 Correct 0 ms 6912 KB Output is correct
6 Correct 0 ms 6912 KB Output is correct
7 Correct 6 ms 6912 KB Output is correct
8 Correct 0 ms 6912 KB Output is correct
9 Correct 0 ms 6912 KB Output is correct
10 Correct 3 ms 6912 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 6912 KB Output is correct
2 Correct 0 ms 6912 KB Output is correct
3 Correct 3 ms 6912 KB Output is correct
4 Correct 3 ms 6912 KB Output is correct
5 Correct 6 ms 6912 KB Output is correct
6 Correct 0 ms 6912 KB Output is correct
7 Correct 13 ms 6912 KB Output is correct
8 Correct 0 ms 6912 KB Output is correct
9 Correct 0 ms 6912 KB Output is correct
10 Correct 3 ms 6912 KB Output is correct
11 Correct 6 ms 6912 KB Output is correct
12 Correct 9 ms 6912 KB Output is correct
13 Correct 3 ms 6912 KB Output is correct
14 Correct 6 ms 6912 KB Output is correct
15 Correct 6 ms 6912 KB Output is correct
16 Correct 43 ms 7052 KB Output is correct
17 Correct 3 ms 6912 KB Output is correct
18 Correct 69 ms 7232 KB Output is correct
19 Correct 0 ms 6912 KB Output is correct
20 Correct 6 ms 7052 KB Output is correct
21 Correct 26 ms 7052 KB Output is correct
22 Correct 6 ms 6912 KB Output is correct
23 Correct 0 ms 6912 KB Output is correct
24 Correct 0 ms 6912 KB Output is correct
25 Correct 13 ms 7052 KB Output is correct
26 Correct 9 ms 7052 KB Output is correct
27 Correct 0 ms 6912 KB Output is correct
28 Correct 9 ms 7052 KB Output is correct
29 Correct 16 ms 7052 KB Output is correct
30 Correct 53 ms 7232 KB Output is correct
31 Correct 0 ms 6912 KB Output is correct
32 Correct 6 ms 6912 KB Output is correct
33 Correct 0 ms 6912 KB Output is correct
34 Correct 9 ms 7052 KB Output is correct
35 Correct 0 ms 6912 KB Output is correct
36 Correct 13 ms 7052 KB Output is correct
37 Correct 6 ms 6912 KB Output is correct
38 Correct 3 ms 6912 KB Output is correct
39 Correct 9 ms 7052 KB Output is correct
40 Correct 39 ms 7052 KB Output is correct
41 Correct 23 ms 7052 KB Output is correct
42 Correct 36 ms 7052 KB Output is correct
43 Correct 13 ms 7052 KB Output is correct
44 Correct 16 ms 7052 KB Output is correct
45 Correct 0 ms 7052 KB Output is correct
46 Correct 0 ms 6912 KB Output is correct
47 Correct 0 ms 7052 KB Output is correct
48 Correct 29 ms 7052 KB Output is correct
49 Correct 6 ms 6912 KB Output is correct
50 Correct 26 ms 7232 KB Output is correct
51 Correct 13 ms 7052 KB Output is correct
52 Correct 0 ms 6912 KB Output is correct
53 Correct 9 ms 6912 KB Output is correct
54 Correct 0 ms 7052 KB Output is correct
55 Correct 0 ms 6912 KB Output is correct
56 Correct 46 ms 7232 KB Output is correct
57 Correct 0 ms 7052 KB Output is correct
58 Correct 13 ms 7052 KB Output is correct
59 Correct 13 ms 7052 KB Output is correct
60 Correct 9 ms 7052 KB Output is correct
61 Correct 0 ms 6912 KB Output is correct
62 Correct 0 ms 6912 KB Output is correct
63 Correct 3 ms 6912 KB Output is correct
64 Correct 0 ms 6912 KB Output is correct
65 Correct 0 ms 6912 KB Output is correct
66 Correct 13 ms 6912 KB Output is correct
67 Correct 3 ms 6912 KB Output is correct
68 Correct 6 ms 6912 KB Output is correct
69 Correct 9 ms 6912 KB Output is correct
70 Correct 0 ms 6912 KB Output is correct
71 Correct 33 ms 7232 KB Output is correct
72 Correct 9 ms 6912 KB Output is correct
73 Correct 13 ms 7232 KB Output is correct
74 Correct 63 ms 7232 KB Output is correct
75 Correct 6 ms 6912 KB Output is correct
76 Correct 26 ms 7052 KB Output is correct
77 Correct 56 ms 7232 KB Output is correct
78 Correct 6 ms 6912 KB Output is correct
79 Correct 9 ms 7052 KB Output is correct
80 Correct 46 ms 7232 KB Output is correct
81 Correct 66 ms 7232 KB Output is correct
82 Correct 46 ms 7232 KB Output is correct
83 Correct 3 ms 6912 KB Output is correct
84 Correct 19 ms 7052 KB Output is correct
85 Correct 26 ms 7232 KB Output is correct
86 Correct 13 ms 7052 KB Output is correct
87 Correct 6 ms 6912 KB Output is correct
88 Correct 16 ms 7052 KB Output is correct
89 Correct 26 ms 7052 KB Output is correct
90 Correct 0 ms 6912 KB Output is correct
91 Correct 9 ms 7052 KB Output is correct
92 Correct 39 ms 7052 KB Output is correct
93 Correct 9 ms 7216 KB Output is correct
94 Correct 13 ms 7216 KB Output is correct
95 Correct 13 ms 7216 KB Output is correct
96 Correct 16 ms 7216 KB Output is correct
97 Correct 23 ms 7216 KB Output is correct