답안 #367943

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
367943 2021-02-18T22:26:06 Z Marlov 커다란 상품 (IOI17_prize) C++14
98.29 / 100
65 ms 912 KB
/*
Code by @marlov       
*/
#include <iostream>
#include <fstream>
#include <string>
#include <sstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <utility>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <stack>
#include <queue>
#include <iterator>
#include <bitset>
#include "prize.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;

int N;
int sN;
int mvs=0;
int result=-1;

/*
vector<int> ask(int i){
	cout<<"query: "<<i<<endl;
	int rlv,rrv;
	cin>>rlv>>rrv;
	return {rlv,rrv};
}
*/

unordered_map<int,int> lv;
unordered_map<int,int> rv;
vector<int> query(int i){
	if(!(lv.count(i)==1&&rv.count(i)==1)){
	vector<int> askv=ask(i);
	lv[i]=askv[0];
	rv[i]=askv[1];
	}
	if(lv[i]+rv[i]==0) result=i;
	return {lv[i],rv[i]};
}

void binary_search(int l,int r){
	//cout<<"seeing:"<<l<<","<<r<<endl;
	if(result!=-1) return;
	if(l+1>=r) return;
	vector<int> lv=query(l);
	vector<int> rv=query(r);
	int mid=(l+r)/2;
	vector<int> midv=query(mid);
	while(midv[0]+midv[1]<mvs){
		mid++;
		midv=query(mid);
	}
	if(mid==r) return;
	if(midv[0]-lv[0]!=0) binary_search(l,mid);
	if(rv[0]-midv[0]!=0) binary_search(mid,r);
}

//method can use int[] ask(int i) which return left and right value
int find_best(int n){
	int N=n;
	int sN=floor(sqrt((double)N));
	//loop first sqrtN value to find max dude
	for(int i=0;i<N;i+=sN){
		vector<int> qv=query(i);
		mvs=max(mvs,qv[0]+qv[1]);
	}
	//loop through sqrtN
	int cl=0;
	int cr=sN;
	vector<int> clv;
	vector<int> crv;
	while(cr<N){
		clv=query(cl);
		if(clv[0]+clv[1]<mvs){
			cl++;
			continue;
		}
		crv=query(cr);
		if(cr<N&&crv[0]+crv[1]<mvs){
			cr++;
			continue;
		}
		if(crv[0]-clv[0]!=0) binary_search(cl,cr);
		swap(cl,cr);
		cr=cl+sN;
	}
	cr=N-1;
	vector<int> lastV=query(cr);
	while(cr>cl&&lastV[0]+lastV[1]<mvs){
		cr--;
		lastV=query(cr);
	}
	if(lastV[0]-crv[0]!=0) binary_search(cl,cr);
	
	return result;
}


/*
int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);
	int val=find_best(8);
	cout<<"ANSWER:"<<val<<endl;	
    return 0;
}
*/

/* stuff you should look for
	* int overflow, array bounds
	* special cases (n=1,n=0?)
	* do smth instead of nothing and stay organized
*/
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 364 KB Output is correct
2 Correct 6 ms 512 KB Output is correct
3 Correct 7 ms 364 KB Output is correct
4 Correct 5 ms 492 KB Output is correct
5 Correct 5 ms 620 KB Output is correct
6 Correct 4 ms 364 KB Output is correct
7 Correct 4 ms 364 KB Output is correct
8 Correct 6 ms 364 KB Output is correct
9 Correct 6 ms 364 KB Output is correct
10 Correct 3 ms 408 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 524 KB Output is correct
2 Correct 5 ms 364 KB Output is correct
3 Correct 4 ms 492 KB Output is correct
4 Correct 5 ms 492 KB Output is correct
5 Correct 4 ms 524 KB Output is correct
6 Correct 7 ms 364 KB Output is correct
7 Correct 5 ms 364 KB Output is correct
8 Correct 6 ms 364 KB Output is correct
9 Correct 5 ms 364 KB Output is correct
10 Correct 7 ms 364 KB Output is correct
11 Correct 6 ms 364 KB Output is correct
12 Correct 6 ms 364 KB Output is correct
13 Correct 5 ms 548 KB Output is correct
14 Correct 4 ms 364 KB Output is correct
15 Correct 12 ms 492 KB Output is correct
16 Correct 41 ms 748 KB Output is correct
17 Correct 7 ms 364 KB Output is correct
18 Correct 46 ms 876 KB Output is correct
19 Correct 11 ms 364 KB Output is correct
20 Correct 16 ms 492 KB Output is correct
21 Correct 14 ms 576 KB Output is correct
22 Correct 11 ms 364 KB Output is correct
23 Correct 5 ms 364 KB Output is correct
24 Correct 3 ms 524 KB Output is correct
25 Correct 22 ms 492 KB Output is correct
26 Correct 29 ms 620 KB Output is correct
27 Correct 6 ms 364 KB Output is correct
28 Correct 37 ms 876 KB Output is correct
29 Correct 35 ms 620 KB Output is correct
30 Correct 49 ms 748 KB Output is correct
31 Correct 5 ms 364 KB Output is correct
32 Correct 6 ms 548 KB Output is correct
33 Correct 1 ms 492 KB Output is correct
34 Correct 25 ms 492 KB Output is correct
35 Correct 6 ms 364 KB Output is correct
36 Correct 18 ms 492 KB Output is correct
37 Correct 4 ms 400 KB Output is correct
38 Correct 6 ms 364 KB Output is correct
39 Correct 30 ms 492 KB Output is correct
40 Correct 41 ms 748 KB Output is correct
41 Correct 28 ms 620 KB Output is correct
42 Correct 41 ms 620 KB Output is correct
43 Correct 38 ms 620 KB Output is correct
44 Correct 21 ms 620 KB Output is correct
45 Correct 23 ms 620 KB Output is correct
46 Correct 5 ms 364 KB Output is correct
47 Correct 27 ms 492 KB Output is correct
48 Correct 40 ms 784 KB Output is correct
49 Correct 9 ms 364 KB Output is correct
50 Correct 39 ms 792 KB Output is correct
51 Correct 22 ms 620 KB Output is correct
52 Correct 8 ms 416 KB Output is correct
53 Correct 7 ms 364 KB Output is correct
54 Correct 14 ms 620 KB Output is correct
55 Correct 10 ms 368 KB Output is correct
56 Partially correct 64 ms 880 KB Partially correct - number of queries: 5085
57 Correct 39 ms 620 KB Output is correct
58 Correct 65 ms 748 KB Output is correct
59 Correct 39 ms 620 KB Output is correct
60 Correct 39 ms 620 KB Output is correct
61 Correct 8 ms 364 KB Output is correct
62 Correct 8 ms 364 KB Output is correct
63 Correct 9 ms 364 KB Output is correct
64 Correct 7 ms 364 KB Output is correct
65 Correct 5 ms 368 KB Output is correct
66 Correct 17 ms 364 KB Output is correct
67 Correct 7 ms 548 KB Output is correct
68 Correct 9 ms 364 KB Output is correct
69 Correct 13 ms 364 KB Output is correct
70 Correct 9 ms 364 KB Output is correct
71 Correct 52 ms 876 KB Output is correct
72 Correct 9 ms 364 KB Output is correct
73 Correct 60 ms 748 KB Output is correct
74 Correct 58 ms 748 KB Output is correct
75 Correct 5 ms 512 KB Output is correct
76 Correct 54 ms 876 KB Output is correct
77 Partially correct 43 ms 748 KB Partially correct - number of queries: 5171
78 Correct 10 ms 364 KB Output is correct
79 Correct 33 ms 492 KB Output is correct
80 Correct 53 ms 792 KB Output is correct
81 Partially correct 56 ms 880 KB Partially correct - number of queries: 5129
82 Correct 64 ms 748 KB Output is correct
83 Correct 6 ms 364 KB Output is correct
84 Correct 43 ms 876 KB Output is correct
85 Correct 48 ms 748 KB Output is correct
86 Correct 59 ms 748 KB Output is correct
87 Correct 15 ms 364 KB Output is correct
88 Correct 40 ms 748 KB Output is correct
89 Correct 54 ms 748 KB Output is correct
90 Correct 10 ms 636 KB Output is correct
91 Correct 40 ms 620 KB Output is correct
92 Correct 48 ms 912 KB Output is correct
93 Correct 52 ms 864 KB Output is correct
94 Correct 61 ms 748 KB Output is correct
95 Correct 65 ms 748 KB Output is correct
96 Correct 43 ms 748 KB Output is correct
97 Correct 42 ms 748 KB Output is correct