답안 #118610

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
118610 2019-06-19T09:47:03 Z StevenH 커다란 상품 (IOI17_prize) C++14
96.16 / 100
58 ms 648 KB
#include "prize.h"
#include <cstring>
//#include <bits\stdc++.h> 
using namespace std;
const int maxn = 200005;
bool vis[maxn];
int lp;
									//rx right of r
int find(int l,int r,int lx,int rx)	//lx left of l
{
	int mid,tmp,nm;
	mid=(l+r)/2;
	int k=0,tp=-1;
	
	if(vis[mid])
	{
		while(mid-k>=l || mid+k<=r)
		{
			k++;
			if(!vis[mid+k] && mid+k<=r)
			{
				tp=mid+k;
				break;
			}
			else if(!vis[mid-k] && mid-k>=l)
			{
				tp=mid-k;
				break;
			}
		}
		if(tp==-1)return 0;
		mid=tp;
	}
	/*while(vis[mid] && mid<=r)mid++;
	if(mid>r)
	{
		mid=(l+r)/2;
		while(vis[mid] && mid>=l)mid--;
		if(mid<l)return 0;	// 0 not find any thing
	}
	
	if(mid<l || mid>199999)return 0;*/
	
	
	vector<int> res = ask(mid);
	vis[mid]=true;
	if(res[0]+res[1]==0)return mid;
	
	
	else if(res[0]+res[1]==lp)
	{
		if(res[0]-lx>0)	 // left not empty 
		{
			tmp=find(l,mid-1,lx,res[1]);
			if(tmp)return tmp;
		}
		if(res[1]-rx>0)	// right not empty
		{
			tmp=find(mid+1,r,res[0],rx);
			if(tmp)return tmp;
		}
	}
	else if(tmp=find(l,r,lx,rx))return tmp;
	
	return 0;
}

int find_best(int n) {
	int mx=-1,nm,id;
	//vector<int> res = ask(i);
	for(int i=0;i<476;i++)
	{
		vector<int> res = ask(i);
		int tmp = res[0] + res[1];
		if(tmp==0)
		{
			//cout<<i;
			return i;
		}
		if(tmp>mx)
		{
			mx=tmp;
			id=i;
			nm=1;
		}
		if(tmp==mx)nm++;
	}
	
	lp=mx;	//lp refers to lollipop
	memset(vis,false,sizeof(vis));
	int tp=find(476,n-1,476-nm,0);
	//cout<<tp;
	return tp;
	
	return 0;
}

Compilation message

prize.cpp: In function 'int find(int, int, int, int)':
prize.cpp:63:13: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
  else if(tmp=find(l,r,lx,rx))return tmp;
          ~~~^~~~~~~~~~~~~~~~
prize.cpp:11:14: warning: unused variable 'nm' [-Wunused-variable]
  int mid,tmp,nm;
              ^~
prize.cpp: In function 'int find_best(int)':
prize.cpp:69:15: warning: variable 'id' set but not used [-Wunused-but-set-variable]
  int mx=-1,nm,id;
               ^~
prize.cpp:69:12: warning: 'nm' may be used uninitialized in this function [-Wmaybe-uninitialized]
  int mx=-1,nm,id;
            ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 376 KB Output is correct
2 Correct 7 ms 504 KB Output is correct
3 Correct 7 ms 524 KB Output is correct
4 Correct 5 ms 504 KB Output is correct
5 Correct 4 ms 512 KB Output is correct
6 Correct 2 ms 308 KB Output is correct
7 Correct 5 ms 512 KB Output is correct
8 Correct 4 ms 648 KB Output is correct
9 Correct 4 ms 640 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 504 KB Output is correct
2 Correct 8 ms 432 KB Output is correct
3 Correct 4 ms 524 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 4 ms 504 KB Output is correct
6 Correct 2 ms 432 KB Output is correct
7 Correct 4 ms 376 KB Output is correct
8 Correct 6 ms 424 KB Output is correct
9 Correct 3 ms 512 KB Output is correct
10 Correct 5 ms 512 KB Output is correct
11 Correct 6 ms 504 KB Output is correct
12 Correct 5 ms 504 KB Output is correct
13 Correct 5 ms 440 KB Output is correct
14 Correct 6 ms 384 KB Output is correct
15 Correct 9 ms 384 KB Output is correct
16 Correct 32 ms 504 KB Output is correct
17 Correct 4 ms 256 KB Output is correct
18 Partially correct 53 ms 512 KB Partially correct - number of queries: 5241
19 Correct 4 ms 256 KB Output is correct
20 Correct 11 ms 504 KB Output is correct
21 Correct 18 ms 444 KB Output is correct
22 Correct 4 ms 448 KB Output is correct
23 Correct 7 ms 504 KB Output is correct
24 Correct 5 ms 504 KB Output is correct
25 Correct 29 ms 512 KB Output is correct
26 Correct 49 ms 380 KB Output is correct
27 Correct 8 ms 512 KB Output is correct
28 Correct 16 ms 532 KB Output is correct
29 Correct 41 ms 376 KB Output is correct
30 Partially correct 31 ms 436 KB Partially correct - number of queries: 5203
31 Correct 3 ms 384 KB Output is correct
32 Correct 5 ms 532 KB Output is correct
33 Correct 2 ms 384 KB Output is correct
34 Correct 25 ms 436 KB Output is correct
35 Correct 6 ms 504 KB Output is correct
36 Correct 11 ms 376 KB Output is correct
37 Correct 8 ms 504 KB Output is correct
38 Correct 3 ms 528 KB Output is correct
39 Correct 18 ms 376 KB Output is correct
40 Correct 43 ms 444 KB Output is correct
41 Correct 21 ms 512 KB Output is correct
42 Correct 12 ms 512 KB Output is correct
43 Correct 29 ms 504 KB Output is correct
44 Correct 16 ms 376 KB Output is correct
45 Correct 21 ms 512 KB Output is correct
46 Correct 6 ms 308 KB Output is correct
47 Correct 16 ms 436 KB Output is correct
48 Correct 46 ms 512 KB Output is correct
49 Correct 10 ms 504 KB Output is correct
50 Partially correct 44 ms 424 KB Partially correct - number of queries: 5238
51 Correct 17 ms 504 KB Output is correct
52 Correct 6 ms 504 KB Output is correct
53 Correct 8 ms 504 KB Output is correct
54 Correct 24 ms 516 KB Output is correct
55 Correct 6 ms 256 KB Output is correct
56 Partially correct 53 ms 456 KB Partially correct - number of queries: 5238
57 Correct 23 ms 504 KB Output is correct
58 Correct 24 ms 436 KB Output is correct
59 Correct 24 ms 524 KB Output is correct
60 Correct 29 ms 440 KB Output is correct
61 Correct 5 ms 376 KB Output is correct
62 Correct 5 ms 504 KB Output is correct
63 Correct 4 ms 512 KB Output is correct
64 Correct 6 ms 504 KB Output is correct
65 Correct 6 ms 432 KB Output is correct
66 Correct 10 ms 504 KB Output is correct
67 Correct 6 ms 504 KB Output is correct
68 Correct 5 ms 256 KB Output is correct
69 Correct 10 ms 504 KB Output is correct
70 Correct 10 ms 504 KB Output is correct
71 Partially correct 31 ms 384 KB Partially correct - number of queries: 5244
72 Correct 11 ms 512 KB Output is correct
73 Partially correct 38 ms 384 KB Partially correct - number of queries: 5181
74 Partially correct 42 ms 512 KB Partially correct - number of queries: 5208
75 Correct 6 ms 512 KB Output is correct
76 Correct 18 ms 448 KB Output is correct
77 Partially correct 58 ms 504 KB Partially correct - number of queries: 5384
78 Correct 10 ms 512 KB Output is correct
79 Correct 11 ms 520 KB Output is correct
80 Partially correct 33 ms 384 KB Partially correct - number of queries: 5351
81 Partially correct 40 ms 384 KB Partially correct - number of queries: 5346
82 Partially correct 24 ms 520 KB Partially correct - number of queries: 5310
83 Correct 7 ms 512 KB Output is correct
84 Correct 39 ms 512 KB Output is correct
85 Partially correct 36 ms 504 KB Partially correct - number of queries: 5319
86 Correct 8 ms 512 KB Output is correct
87 Correct 4 ms 648 KB Output is correct
88 Correct 7 ms 512 KB Output is correct
89 Correct 8 ms 504 KB Output is correct
90 Correct 3 ms 520 KB Output is correct
91 Correct 5 ms 384 KB Output is correct
92 Correct 5 ms 512 KB Output is correct
93 Correct 10 ms 512 KB Output is correct
94 Correct 8 ms 384 KB Output is correct
95 Correct 8 ms 384 KB Output is correct
96 Correct 8 ms 380 KB Output is correct
97 Correct 7 ms 512 KB Output is correct