답안 #1045234

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1045234 2024-08-05T19:18:02 Z beaconmc 커다란 상품 (IOI17_prize) C++14
97.41 / 100
948 ms 2028 KB
#include "prize.h"

#include <bits/stdc++.h>
 
typedef int ll;
#define FOR(i,x,y) for(ll i=x; i<y; i++)
#define FORNEG(i,x,y) for(ll i=x; i>y; i--)
 
using namespace std;


map<ll, vector<ll>> cache;

vector<ll> query(int n){

	if (cache.count(n)) return cache[n];
	else return cache[n] = ask(n);
}


int find_best(int n) {
	cache.clear();
	vector<ll> stuff(n);

	FOR(i,0,n) stuff[i] = i;
	ll maxi = -1;
	FOR(i,0,min(500, n)){
		vector<ll> sus = query(i);
		maxi = max(maxi, sus[0]+sus[1]);
	}
	

	vector<ll> found;

	ll ans = -1;


	while (ans == -1){


		ll lo = 0;
		ll hi = stuff.size()-1;
		bool skip = false;

		while (lo < hi){


			ll mid = (lo+hi)/2;
			ll cur = 1;
			while (cur < 100000){

				if (lo <= mid-cur && cache.count(stuff[mid-cur])){
					mid = mid-cur;
					break;
				}
				if (mid+cur < hi && cache.count(stuff[mid+cur])){
					mid = mid+cur;
					break;
				}
				cur++;
			}


			vector<ll> sus = query(stuff[mid]);


			if (sus[0] + sus[1] < maxi){
					
				if (sus[0]+sus[1]==0) return stuff[mid];
				found.push_back(stuff[mid]);
				stuff.erase(stuff.begin()+mid);
				skip = true;
				break;
			}else{
				sort(found.begin(), found.end());
				ll idk = upper_bound(found.begin(), found.end(), stuff[mid]) - found.begin();

				if (idk < sus[0]){
					hi = mid;
				}else{
					lo = mid+1;
				}
			}
		}

		if (skip) continue;

		vector<ll> sus = query(stuff[lo]);
		if (sus[0]+sus[1] == maxi) break;
		if (sus[0]+sus[1]==0) return stuff[lo];
		found.push_back(stuff[lo]);
		stuff.erase(stuff.begin()+lo);

	}

	return 0;

}
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 1488 KB Output is correct
2 Correct 13 ms 1112 KB Output is correct
3 Correct 16 ms 1112 KB Output is correct
4 Correct 9 ms 1112 KB Output is correct
5 Correct 9 ms 1112 KB Output is correct
6 Correct 7 ms 1368 KB Output is correct
7 Correct 17 ms 1112 KB Output is correct
8 Correct 9 ms 1112 KB Output is correct
9 Correct 14 ms 1112 KB Output is correct
10 Correct 9 ms 1112 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 1112 KB Output is correct
2 Correct 9 ms 1112 KB Output is correct
3 Correct 12 ms 1656 KB Output is correct
4 Correct 10 ms 1112 KB Output is correct
5 Correct 10 ms 1252 KB Output is correct
6 Correct 8 ms 1112 KB Output is correct
7 Correct 9 ms 1112 KB Output is correct
8 Correct 9 ms 1112 KB Output is correct
9 Correct 8 ms 1112 KB Output is correct
10 Correct 14 ms 1368 KB Output is correct
11 Correct 44 ms 1360 KB Output is correct
12 Correct 9 ms 1112 KB Output is correct
13 Correct 60 ms 1292 KB Output is correct
14 Correct 14 ms 340 KB Output is correct
15 Correct 81 ms 1112 KB Output is correct
16 Correct 325 ms 1632 KB Output is correct
17 Correct 6 ms 1368 KB Output is correct
18 Correct 438 ms 1760 KB Output is correct
19 Correct 5 ms 1112 KB Output is correct
20 Correct 120 ms 900 KB Output is correct
21 Correct 139 ms 1652 KB Output is correct
22 Correct 42 ms 1112 KB Output is correct
23 Correct 14 ms 1276 KB Output is correct
24 Correct 16 ms 1112 KB Output is correct
25 Correct 254 ms 1872 KB Output is correct
26 Correct 199 ms 1556 KB Output is correct
27 Correct 20 ms 1368 KB Output is correct
28 Correct 372 ms 1912 KB Output is correct
29 Correct 305 ms 1452 KB Output is correct
30 Correct 450 ms 1832 KB Output is correct
31 Correct 5 ms 1368 KB Output is correct
32 Correct 69 ms 1112 KB Output is correct
33 Correct 1 ms 344 KB Output is correct
34 Correct 125 ms 1556 KB Output is correct
35 Correct 29 ms 1368 KB Output is correct
36 Correct 119 ms 1364 KB Output is correct
37 Correct 21 ms 1368 KB Output is correct
38 Correct 13 ms 1112 KB Output is correct
39 Correct 187 ms 1508 KB Output is correct
40 Correct 385 ms 1656 KB Output is correct
41 Correct 293 ms 1616 KB Output is correct
42 Correct 346 ms 1656 KB Output is correct
43 Correct 257 ms 1508 KB Output is correct
44 Correct 160 ms 1576 KB Output is correct
45 Correct 189 ms 1356 KB Output is correct
46 Correct 7 ms 1112 KB Output is correct
47 Correct 161 ms 1308 KB Output is correct
48 Correct 312 ms 1692 KB Output is correct
49 Correct 50 ms 1112 KB Output is correct
50 Correct 440 ms 1656 KB Output is correct
51 Correct 194 ms 1568 KB Output is correct
52 Correct 16 ms 1516 KB Output is correct
53 Correct 26 ms 1248 KB Output is correct
54 Correct 245 ms 1872 KB Output is correct
55 Correct 6 ms 1112 KB Output is correct
56 Correct 411 ms 2028 KB Output is correct
57 Correct 283 ms 1552 KB Output is correct
58 Correct 312 ms 1616 KB Output is correct
59 Correct 257 ms 1544 KB Output is correct
60 Correct 205 ms 1476 KB Output is correct
61 Correct 34 ms 1276 KB Output is correct
62 Correct 9 ms 1112 KB Output is correct
63 Correct 28 ms 1300 KB Output is correct
64 Correct 17 ms 1364 KB Output is correct
65 Correct 57 ms 1112 KB Output is correct
66 Correct 64 ms 1296 KB Output is correct
67 Correct 43 ms 1112 KB Output is correct
68 Correct 786 ms 1264 KB Output is correct
69 Correct 78 ms 1112 KB Output is correct
70 Correct 27 ms 1112 KB Output is correct
71 Partially correct 612 ms 1852 KB Partially correct - number of queries: 5259
72 Correct 66 ms 1368 KB Output is correct
73 Partially correct 476 ms 1604 KB Partially correct - number of queries: 5196
74 Partially correct 525 ms 1824 KB Partially correct - number of queries: 5223
75 Correct 23 ms 1112 KB Output is correct
76 Correct 399 ms 1828 KB Output is correct
77 Correct 459 ms 1996 KB Output is correct
78 Correct 54 ms 1356 KB Output is correct
79 Correct 265 ms 1732 KB Output is correct
80 Correct 436 ms 1740 KB Output is correct
81 Correct 524 ms 1896 KB Output is correct
82 Correct 418 ms 1604 KB Output is correct
83 Correct 22 ms 1296 KB Output is correct
84 Correct 360 ms 1784 KB Output is correct
85 Correct 515 ms 1868 KB Output is correct
86 Correct 895 ms 1368 KB Output is correct
87 Correct 74 ms 1260 KB Output is correct
88 Correct 892 ms 1112 KB Output is correct
89 Correct 943 ms 1492 KB Output is correct
90 Correct 22 ms 1112 KB Output is correct
91 Correct 535 ms 1368 KB Output is correct
92 Correct 915 ms 1268 KB Output is correct
93 Correct 948 ms 1360 KB Output is correct
94 Correct 910 ms 1364 KB Output is correct
95 Correct 907 ms 1260 KB Output is correct
96 Correct 878 ms 1364 KB Output is correct
97 Correct 853 ms 1112 KB Output is correct