답안 #165612

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
165612 2019-11-27T17:54:49 Z johutha 커다란 상품 (IOI17_prize) C++14
98.83 / 100
92 ms 512 KB
#include "prize.h"
#include <algorithm>
#include <queue>
#include <cmath>

using namespace std;

struct segment
{
	int l, r;
	int cnt_r;
	int cnt_l;
	int cnt_ins = -1;
};

int find_best(int n)
{
	queue<segment> q;

	segment s1;
	s1.l = 0;
	s1.r = n;
	s1.cnt_l = 0;
	s1.cnt_r = 0;
	q.push(s1);

	while (!q.empty())
	{
		segment curr = q.front();
		q.pop();
		int mid = (curr.l + curr.r) / 2;
		bool found = false;
		for (int i = mid; i < min(mid + (int)ceil(sqrt(n)) + 1, curr.r); i++)
		{
			auto r = ask(i);
			if (r[0] + r[1] == 0) return i;
			if (r[0] + r[1] < n / 2)
			{
				found = true;
				segment sl = curr;
				sl.r = mid;
				sl.cnt_ins = r[0] - curr.cnt_l;
				sl.cnt_r = r[1];
				segment sr = curr;
				sr.l = mid + 1;
				sr.cnt_ins = r[1] - curr.cnt_r;
				sr.cnt_l = r[0];
				if (sl.cnt_ins != 0) q.push(sl);
				if (sr.cnt_ins != 0) q.push(sr);
				break;
			}
		}
		if (!found)
		{
			segment ns = curr;
			ns.r = mid;
			ns.cnt_r += curr.r - mid;
			ns.cnt_ins -= curr.r - mid;
			if (ns.cnt_ins != 0) q.push(ns);
		}
	}
}

Compilation message

prize.cpp: In function 'int find_best(int)':
prize.cpp:62:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 392 KB Output is correct
4 Correct 2 ms 388 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 248 KB Output is correct
8 Correct 2 ms 248 KB Output is correct
9 Correct 2 ms 248 KB Output is correct
10 Correct 2 ms 248 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 308 KB Output is correct
3 Correct 2 ms 248 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 248 KB Output is correct
6 Correct 2 ms 248 KB Output is correct
7 Correct 2 ms 308 KB Output is correct
8 Correct 2 ms 304 KB Output is correct
9 Correct 2 ms 304 KB Output is correct
10 Correct 5 ms 248 KB Output is correct
11 Correct 8 ms 392 KB Output is correct
12 Correct 4 ms 376 KB Output is correct
13 Correct 6 ms 248 KB Output is correct
14 Correct 9 ms 376 KB Output is correct
15 Correct 45 ms 308 KB Output is correct
16 Correct 38 ms 248 KB Output is correct
17 Correct 33 ms 248 KB Output is correct
18 Partially correct 55 ms 332 KB Partially correct - number of queries: 5092
19 Correct 49 ms 412 KB Output is correct
20 Correct 23 ms 248 KB Output is correct
21 Correct 46 ms 332 KB Output is correct
22 Correct 21 ms 408 KB Output is correct
23 Correct 2 ms 376 KB Output is correct
24 Correct 4 ms 388 KB Output is correct
25 Correct 17 ms 324 KB Output is correct
26 Correct 60 ms 380 KB Output is correct
27 Correct 3 ms 388 KB Output is correct
28 Correct 44 ms 380 KB Output is correct
29 Correct 20 ms 408 KB Output is correct
30 Partially correct 47 ms 392 KB Partially correct - number of queries: 5060
31 Correct 51 ms 248 KB Output is correct
32 Correct 6 ms 248 KB Output is correct
33 Correct 2 ms 248 KB Output is correct
34 Correct 45 ms 376 KB Output is correct
35 Correct 4 ms 248 KB Output is correct
36 Correct 41 ms 248 KB Output is correct
37 Correct 5 ms 248 KB Output is correct
38 Correct 4 ms 376 KB Output is correct
39 Correct 50 ms 304 KB Output is correct
40 Correct 36 ms 304 KB Output is correct
41 Correct 46 ms 376 KB Output is correct
42 Correct 22 ms 376 KB Output is correct
43 Correct 43 ms 380 KB Output is correct
44 Correct 45 ms 248 KB Output is correct
45 Correct 43 ms 248 KB Output is correct
46 Correct 17 ms 328 KB Output is correct
47 Correct 47 ms 328 KB Output is correct
48 Correct 42 ms 324 KB Output is correct
49 Correct 29 ms 328 KB Output is correct
50 Correct 45 ms 248 KB Output is correct
51 Correct 92 ms 248 KB Output is correct
52 Correct 21 ms 396 KB Output is correct
53 Correct 3 ms 248 KB Output is correct
54 Correct 13 ms 376 KB Output is correct
55 Correct 33 ms 252 KB Output is correct
56 Correct 37 ms 376 KB Output is correct
57 Correct 43 ms 328 KB Output is correct
58 Correct 33 ms 428 KB Output is correct
59 Correct 36 ms 320 KB Output is correct
60 Correct 21 ms 444 KB Output is correct
61 Correct 3 ms 248 KB Output is correct
62 Correct 3 ms 248 KB Output is correct
63 Correct 3 ms 424 KB Output is correct
64 Correct 3 ms 312 KB Output is correct
65 Correct 2 ms 276 KB Output is correct
66 Correct 2 ms 380 KB Output is correct
67 Correct 2 ms 248 KB Output is correct
68 Correct 2 ms 248 KB Output is correct
69 Correct 2 ms 376 KB Output is correct
70 Correct 2 ms 308 KB Output is correct
71 Correct 43 ms 248 KB Output is correct
72 Correct 7 ms 376 KB Output is correct
73 Correct 48 ms 248 KB Output is correct
74 Correct 25 ms 332 KB Output is correct
75 Correct 3 ms 376 KB Output is correct
76 Correct 34 ms 504 KB Output is correct
77 Partially correct 48 ms 328 KB Partially correct - number of queries: 5077
78 Correct 4 ms 384 KB Output is correct
79 Correct 14 ms 512 KB Output is correct
80 Partially correct 29 ms 376 KB Partially correct - number of queries: 5014
81 Correct 47 ms 324 KB Output is correct
82 Correct 54 ms 252 KB Output is correct
83 Correct 2 ms 504 KB Output is correct
84 Correct 38 ms 412 KB Output is correct
85 Partially correct 51 ms 248 KB Partially correct - number of queries: 5117
86 Correct 6 ms 320 KB Output is correct
87 Correct 5 ms 248 KB Output is correct
88 Correct 9 ms 248 KB Output is correct
89 Correct 6 ms 384 KB Output is correct
90 Correct 3 ms 376 KB Output is correct
91 Correct 6 ms 248 KB Output is correct
92 Correct 2 ms 252 KB Output is correct
93 Correct 6 ms 248 KB Output is correct
94 Correct 6 ms 248 KB Output is correct
95 Correct 4 ms 248 KB Output is correct
96 Correct 5 ms 248 KB Output is correct
97 Correct 2 ms 376 KB Output is correct