답안 #1045262

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1045262 2024-08-05T19:37:57 Z beaconmc 커다란 상품 (IOI17_prize) C++14
100 / 100
142 ms 2892 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);
	vector<ll> newstuff(n);

	FOR(i,0,n) stuff[i] = i, newstuff[i] = i;
	ll maxi = -1;
	

	random_device rd;
    mt19937 g(rd());
 
    shuffle(newstuff.begin(), newstuff.end(), g);

	FOR(i,0,min(455, n)){
		vector<ll> sus = query(newstuff[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 < 10000){

				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 5 ms 1880 KB Output is correct
2 Correct 6 ms 1880 KB Output is correct
3 Correct 7 ms 2284 KB Output is correct
4 Correct 6 ms 1880 KB Output is correct
5 Correct 7 ms 1880 KB Output is correct
6 Correct 4 ms 1880 KB Output is correct
7 Correct 4 ms 1880 KB Output is correct
8 Correct 5 ms 1880 KB Output is correct
9 Correct 4 ms 1964 KB Output is correct
10 Correct 5 ms 1880 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 1880 KB Output is correct
2 Correct 7 ms 2048 KB Output is correct
3 Correct 5 ms 1880 KB Output is correct
4 Correct 5 ms 1880 KB Output is correct
5 Correct 4 ms 1880 KB Output is correct
6 Correct 5 ms 1880 KB Output is correct
7 Correct 5 ms 1880 KB Output is correct
8 Correct 5 ms 1964 KB Output is correct
9 Correct 5 ms 1880 KB Output is correct
10 Correct 5 ms 1880 KB Output is correct
11 Correct 11 ms 1880 KB Output is correct
12 Correct 5 ms 1880 KB Output is correct
13 Correct 11 ms 2084 KB Output is correct
14 Correct 6 ms 600 KB Output is correct
15 Correct 15 ms 2088 KB Output is correct
16 Correct 84 ms 2528 KB Output is correct
17 Correct 4 ms 1880 KB Output is correct
18 Correct 123 ms 2384 KB Output is correct
19 Correct 5 ms 2028 KB Output is correct
20 Correct 19 ms 1296 KB Output is correct
21 Correct 33 ms 2136 KB Output is correct
22 Correct 10 ms 1880 KB Output is correct
23 Correct 5 ms 1880 KB Output is correct
24 Correct 6 ms 2152 KB Output is correct
25 Correct 46 ms 2132 KB Output is correct
26 Correct 47 ms 2136 KB Output is correct
27 Correct 6 ms 1880 KB Output is correct
28 Correct 81 ms 2384 KB Output is correct
29 Correct 88 ms 2392 KB Output is correct
30 Correct 116 ms 2444 KB Output is correct
31 Correct 5 ms 1880 KB Output is correct
32 Correct 9 ms 1880 KB Output is correct
33 Correct 1 ms 344 KB Output is correct
34 Correct 42 ms 2828 KB Output is correct
35 Correct 10 ms 1880 KB Output is correct
36 Correct 25 ms 2136 KB Output is correct
37 Correct 8 ms 1880 KB Output is correct
38 Correct 5 ms 1880 KB Output is correct
39 Correct 39 ms 2336 KB Output is correct
40 Correct 82 ms 2356 KB Output is correct
41 Correct 50 ms 2136 KB Output is correct
42 Correct 68 ms 2084 KB Output is correct
43 Correct 48 ms 2076 KB Output is correct
44 Correct 36 ms 2112 KB Output is correct
45 Correct 29 ms 2148 KB Output is correct
46 Correct 5 ms 1880 KB Output is correct
47 Correct 45 ms 2156 KB Output is correct
48 Correct 65 ms 2128 KB Output is correct
49 Correct 11 ms 1880 KB Output is correct
50 Correct 103 ms 2416 KB Output is correct
51 Correct 45 ms 2332 KB Output is correct
52 Correct 5 ms 1880 KB Output is correct
53 Correct 7 ms 1880 KB Output is correct
54 Correct 51 ms 2416 KB Output is correct
55 Correct 6 ms 1880 KB Output is correct
56 Correct 107 ms 2620 KB Output is correct
57 Correct 59 ms 2140 KB Output is correct
58 Correct 61 ms 2184 KB Output is correct
59 Correct 51 ms 2160 KB Output is correct
60 Correct 47 ms 2252 KB Output is correct
61 Correct 5 ms 1880 KB Output is correct
62 Correct 5 ms 1964 KB Output is correct
63 Correct 5 ms 1880 KB Output is correct
64 Correct 6 ms 1880 KB Output is correct
65 Correct 8 ms 1964 KB Output is correct
66 Correct 36 ms 2012 KB Output is correct
67 Correct 28 ms 2156 KB Output is correct
68 Correct 38 ms 1880 KB Output is correct
69 Correct 55 ms 2092 KB Output is correct
70 Correct 12 ms 2020 KB Output is correct
71 Correct 142 ms 2640 KB Output is correct
72 Correct 12 ms 2136 KB Output is correct
73 Correct 124 ms 2392 KB Output is correct
74 Correct 104 ms 2892 KB Output is correct
75 Correct 6 ms 1880 KB Output is correct
76 Correct 107 ms 2376 KB Output is correct
77 Correct 101 ms 2456 KB Output is correct
78 Correct 17 ms 1880 KB Output is correct
79 Correct 42 ms 2012 KB Output is correct
80 Correct 111 ms 2336 KB Output is correct
81 Correct 92 ms 2296 KB Output is correct
82 Correct 92 ms 2384 KB Output is correct
83 Correct 6 ms 1880 KB Output is correct
84 Correct 80 ms 2392 KB Output is correct
85 Correct 134 ms 2456 KB Output is correct
86 Correct 46 ms 1880 KB Output is correct
87 Correct 5 ms 1876 KB Output is correct
88 Correct 42 ms 1880 KB Output is correct
89 Correct 47 ms 1880 KB Output is correct
90 Correct 6 ms 1880 KB Output is correct
91 Correct 22 ms 2176 KB Output is correct
92 Correct 19 ms 1880 KB Output is correct
93 Correct 59 ms 2068 KB Output is correct
94 Correct 61 ms 2136 KB Output is correct
95 Correct 77 ms 2080 KB Output is correct
96 Correct 57 ms 2080 KB Output is correct
97 Correct 64 ms 2052 KB Output is correct