답안 #780019

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
780019 2023-07-12T05:38:31 Z Evirir 커다란 상품 (IOI17_prize) C++17
100 / 100
62 ms 12516 KB
#include "prize.h"
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define sz(a) (int)(a.size())
#define all(a) a.begin(),a.end()
typedef pair<int,int> pii;
int loli = 0;
vector<vector<int>>memo(222222,{-1,-1});
vector<int>glo;
auto query(int x){
	if(memo[x][0] == -1)memo[x] = ask(x);
	glo = memo[x];
	return memo[x];
}
int ans = 0;
void solve(int l,int r,int cntl,int cntr){
	//cout<<l<<" "<<r<<" "<<cntl<<" "<<cntr<<'\n';
	int mid = (l+r)/2;
	int L = -1,R = -1;

	for(int i=mid;i>=l;i--){
		auto res = query(i);
		assert(glo == res);
		if(res[0]+res[1] == 0){
			ans = i;
			return;
		}
		if(res[0]+res[1] != loli)continue;
		L = i;
		break;
	}
	if(L!=-1){
		auto res = query(L);
		assert(glo == res);
		int x = mid-L;
		if(res[0] - cntl)solve(l,L-1,cntl,res[1]);
		if(res[1] - cntr - x)solve(mid+1,r,res[0] + x,cntr);
		return;
	}
	///
	for(int i=mid+1;i<=r;i++){
		auto res = query(i);
		assert(glo == res);
		if(res[0]+res[1] == 0){
			ans = i;
			return;
		}
		if(res[0]+res[1] != loli)continue;
		R = i;
		break;

	}
	if(R == -1)return;
	auto res = query(R);
	assert(glo == res);
	if(res[1] - cntr)solve(R+1,r,res[0],cntr);
}
int find_best(int n) {
	int p = 0;
	for(int i=0;i<min(n,477);i++){
		auto res = query(i);
		assert(glo == res);
		if(res[0]+res[1] == 0)return i;
		if(res[0]+res[1] > loli){
			loli = res[0]+res[1];
			p = i;
		}
		if(loli >= 27)break;
	}
	solve(p,n-1,p,0);
	return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 12460 KB Output is correct
2 Correct 12 ms 12472 KB Output is correct
3 Correct 16 ms 12368 KB Output is correct
4 Correct 14 ms 12420 KB Output is correct
5 Correct 13 ms 12484 KB Output is correct
6 Correct 10 ms 12408 KB Output is correct
7 Correct 13 ms 12368 KB Output is correct
8 Correct 11 ms 12480 KB Output is correct
9 Correct 13 ms 12368 KB Output is correct
10 Correct 14 ms 12368 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 12480 KB Output is correct
2 Correct 13 ms 12484 KB Output is correct
3 Correct 13 ms 12368 KB Output is correct
4 Correct 12 ms 12484 KB Output is correct
5 Correct 13 ms 12368 KB Output is correct
6 Correct 10 ms 12480 KB Output is correct
7 Correct 14 ms 12368 KB Output is correct
8 Correct 15 ms 12368 KB Output is correct
9 Correct 14 ms 12484 KB Output is correct
10 Correct 15 ms 12476 KB Output is correct
11 Correct 13 ms 12484 KB Output is correct
12 Correct 14 ms 12476 KB Output is correct
13 Correct 15 ms 12484 KB Output is correct
14 Correct 16 ms 12436 KB Output is correct
15 Correct 36 ms 12368 KB Output is correct
16 Correct 41 ms 12484 KB Output is correct
17 Correct 36 ms 12496 KB Output is correct
18 Correct 40 ms 12480 KB Output is correct
19 Correct 27 ms 12480 KB Output is correct
20 Correct 25 ms 12376 KB Output is correct
21 Correct 33 ms 12368 KB Output is correct
22 Correct 26 ms 12484 KB Output is correct
23 Correct 17 ms 12368 KB Output is correct
24 Correct 12 ms 12484 KB Output is correct
25 Correct 37 ms 12368 KB Output is correct
26 Correct 42 ms 12448 KB Output is correct
27 Correct 15 ms 12404 KB Output is correct
28 Correct 49 ms 12368 KB Output is correct
29 Correct 42 ms 12368 KB Output is correct
30 Correct 50 ms 12476 KB Output is correct
31 Correct 52 ms 12368 KB Output is correct
32 Correct 12 ms 12492 KB Output is correct
33 Correct 10 ms 12368 KB Output is correct
34 Correct 50 ms 12484 KB Output is correct
35 Correct 16 ms 12368 KB Output is correct
36 Correct 50 ms 12488 KB Output is correct
37 Correct 12 ms 12484 KB Output is correct
38 Correct 16 ms 12440 KB Output is correct
39 Correct 38 ms 12484 KB Output is correct
40 Correct 45 ms 12484 KB Output is correct
41 Correct 45 ms 12516 KB Output is correct
42 Correct 47 ms 12368 KB Output is correct
43 Correct 29 ms 12488 KB Output is correct
44 Correct 45 ms 12488 KB Output is correct
45 Correct 38 ms 12472 KB Output is correct
46 Correct 51 ms 12368 KB Output is correct
47 Correct 26 ms 12480 KB Output is correct
48 Correct 48 ms 12468 KB Output is correct
49 Correct 34 ms 12368 KB Output is correct
50 Correct 50 ms 12480 KB Output is correct
51 Correct 50 ms 12396 KB Output is correct
52 Correct 35 ms 12484 KB Output is correct
53 Correct 15 ms 12368 KB Output is correct
54 Correct 27 ms 12484 KB Output is correct
55 Correct 26 ms 12480 KB Output is correct
56 Correct 29 ms 12484 KB Output is correct
57 Correct 43 ms 12480 KB Output is correct
58 Correct 36 ms 12368 KB Output is correct
59 Correct 53 ms 12484 KB Output is correct
60 Correct 51 ms 12432 KB Output is correct
61 Correct 15 ms 12476 KB Output is correct
62 Correct 12 ms 12480 KB Output is correct
63 Correct 12 ms 12480 KB Output is correct
64 Correct 19 ms 12368 KB Output is correct
65 Correct 10 ms 12480 KB Output is correct
66 Correct 13 ms 12368 KB Output is correct
67 Correct 11 ms 12368 KB Output is correct
68 Correct 12 ms 12368 KB Output is correct
69 Correct 16 ms 12460 KB Output is correct
70 Correct 14 ms 12488 KB Output is correct
71 Correct 53 ms 12368 KB Output is correct
72 Correct 18 ms 12364 KB Output is correct
73 Correct 52 ms 12368 KB Output is correct
74 Correct 62 ms 12416 KB Output is correct
75 Correct 15 ms 12496 KB Output is correct
76 Correct 36 ms 12484 KB Output is correct
77 Correct 50 ms 12368 KB Output is correct
78 Correct 13 ms 12368 KB Output is correct
79 Correct 35 ms 12416 KB Output is correct
80 Correct 45 ms 12368 KB Output is correct
81 Correct 45 ms 12368 KB Output is correct
82 Correct 45 ms 12368 KB Output is correct
83 Correct 14 ms 12368 KB Output is correct
84 Correct 36 ms 12472 KB Output is correct
85 Correct 49 ms 12368 KB Output is correct
86 Correct 14 ms 12368 KB Output is correct
87 Correct 10 ms 12368 KB Output is correct
88 Correct 13 ms 12368 KB Output is correct
89 Correct 14 ms 12484 KB Output is correct
90 Correct 13 ms 12424 KB Output is correct
91 Correct 13 ms 12456 KB Output is correct
92 Correct 12 ms 12496 KB Output is correct
93 Correct 17 ms 12368 KB Output is correct
94 Correct 17 ms 12484 KB Output is correct
95 Correct 15 ms 12368 KB Output is correct
96 Correct 21 ms 12396 KB Output is correct
97 Correct 14 ms 12452 KB Output is correct