답안 #1083258

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1083258 2024-09-02T19:36:04 Z Math4Life2020 커다란 상품 (IOI17_prize) C++17
100 / 100
34 ms 1408 KB
// Source: https://usaco.guide/general/io

#include <bits/stdc++.h>
using namespace std;
using ll = long long; using pii = pair<ll,ll>;
#include "prize.h"

map<ll,pii> pts;
ll N;
ll gm;
ll ans = -1;
vector<bool> asked;
const ll C = 500;
ll USED;
ll UMAX = 9000;

vector<int> get(ll x) {
	USED++;
	//assert(USED<UMAX);
	if (USED>UMAX) {
		ll y=0;
		while (1) {
			y++;
		}
	}
	return ask((int)x);
}

int triv(int N1) {
	for (ll i=0;i<N1;i++) {
		vector<int> a0 = get(i);
		if ((a0[0]+a0[1])==0) {
			return i;
		}
	}
	return -1;
}

ll process(ll x) {
	if (!asked[x]) {
		vector<int> a0 = get(x);
		pts[x]={a0[0],a0[1]};
		asked[x]=1;
	}
	ll S = pts[x].first+pts[x].second;
	if (S==0) {
		return x;
	}
	if (S<gm) {
		ll y = -1;
		if (x>0 && !asked[x-1]) {
			y=max(y,process(x-1));
		}
		if (x<(N-1) && !asked[x+1]) {
			y=max(y,process(x+1));
		}
		return y;
	}
	return -1;
}

void query(ll a, ll b) {
	if ((a+1)==b) {
		return;
	}
	if (pts[a].first==pts[b].first) {
		return;
	}
	ll c = (a+b)/2;
	ans=max(ans,process(c));
	if (ans!=-1) {
		return;
	}
	auto A1 = pts.find(a); A1++;
	query(a,(*A1).first);
	auto B1 = pts.find(b); B1--;
	query((*B1).first,b);
}

int find_best(int N0) {
	N=N0;
	USED=0;
	gm=0;
	ans = -1;
	pts.clear();
	asked.clear();
	for (ll i=0;i<N;i++) {
		asked.push_back(0);
	}
	if (N<=C) {
		return triv(N);
	}
	ll r = (N-1)/C;
	for (ll i=1;i<=C;i++) {
		vector<int> a0 = get(i*r);
		asked[i*r]=1;
		pts[i*r]={a0[0],a0[1]};
	}
	for (auto A: pts) {
		pii p0 = A.second;
		gm = max(gm,p0.first+p0.second);
	}
	for (auto A: pts) {
		ll v = process(A.first);
		/*if (v!=-1) {
			return v;
		}*/
	}
	if (process(0)!=-1) {
		//return 0;
	}
	if (process(N-1)!=-1) {
		//return (N-1);
	}
	auto A = pts.begin(); auto B=A; B++;
	vector<pii> qrv;
	do {
		pii pa = (*A).second; pii pb = (*B).second;
		if ((pa.first+pa.second+pb.first+pb.second)==(2*gm)) {
			/*query((*A).first,(*B).first);
			if (ans != -1) {
				return ans;
			}*/
			qrv.push_back({(*A).first,(*B).first});
		}
		A++; B++;
	} while (B != pts.end());
	for (pii p0: qrv) {
		query(p0.first,p0.second);
		/*if (ans != -1) {
			return ans;
		}*/
	}
	for (auto A: pts) {
		if ((A.second.second+A.second.first)==0) {
			return A.first;
		}
	}
}

Compilation message

prize.cpp: In function 'int find_best(int)':
prize.cpp:104:6: warning: unused variable 'v' [-Wunused-variable]
  104 |   ll v = process(A.first);
      |      ^
prize.cpp:116:14: warning: control reaches end of non-void function [-Wreturn-type]
  116 |  vector<pii> qrv;
      |              ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 344 KB Output is correct
2 Correct 3 ms 344 KB Output is correct
3 Correct 3 ms 344 KB Output is correct
4 Correct 3 ms 344 KB Output is correct
5 Correct 4 ms 744 KB Output is correct
6 Correct 2 ms 344 KB Output is correct
7 Correct 2 ms 344 KB Output is correct
8 Correct 3 ms 344 KB Output is correct
9 Correct 3 ms 344 KB Output is correct
10 Correct 4 ms 488 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 344 KB Output is correct
2 Correct 5 ms 344 KB Output is correct
3 Correct 4 ms 344 KB Output is correct
4 Correct 2 ms 600 KB Output is correct
5 Correct 4 ms 344 KB Output is correct
6 Correct 4 ms 344 KB Output is correct
7 Correct 3 ms 344 KB Output is correct
8 Correct 3 ms 344 KB Output is correct
9 Correct 4 ms 344 KB Output is correct
10 Correct 3 ms 344 KB Output is correct
11 Correct 4 ms 344 KB Output is correct
12 Correct 2 ms 344 KB Output is correct
13 Correct 4 ms 344 KB Output is correct
14 Correct 4 ms 344 KB Output is correct
15 Correct 8 ms 496 KB Output is correct
16 Correct 21 ms 848 KB Output is correct
17 Correct 4 ms 344 KB Output is correct
18 Correct 26 ms 544 KB Output is correct
19 Correct 5 ms 344 KB Output is correct
20 Correct 8 ms 344 KB Output is correct
21 Correct 10 ms 572 KB Output is correct
22 Correct 5 ms 344 KB Output is correct
23 Correct 3 ms 344 KB Output is correct
24 Correct 3 ms 344 KB Output is correct
25 Correct 14 ms 600 KB Output is correct
26 Correct 12 ms 600 KB Output is correct
27 Correct 3 ms 344 KB Output is correct
28 Correct 24 ms 1408 KB Output is correct
29 Correct 17 ms 492 KB Output is correct
30 Correct 22 ms 696 KB Output is correct
31 Correct 5 ms 344 KB Output is correct
32 Correct 3 ms 344 KB Output is correct
33 Correct 1 ms 344 KB Output is correct
34 Correct 13 ms 496 KB Output is correct
35 Correct 3 ms 344 KB Output is correct
36 Correct 10 ms 600 KB Output is correct
37 Correct 4 ms 344 KB Output is correct
38 Correct 3 ms 344 KB Output is correct
39 Correct 17 ms 600 KB Output is correct
40 Correct 14 ms 600 KB Output is correct
41 Correct 16 ms 600 KB Output is correct
42 Correct 16 ms 780 KB Output is correct
43 Correct 14 ms 592 KB Output is correct
44 Correct 13 ms 600 KB Output is correct
45 Correct 9 ms 344 KB Output is correct
46 Correct 7 ms 344 KB Output is correct
47 Correct 13 ms 600 KB Output is correct
48 Correct 23 ms 600 KB Output is correct
49 Correct 7 ms 344 KB Output is correct
50 Correct 22 ms 848 KB Output is correct
51 Correct 12 ms 592 KB Output is correct
52 Correct 8 ms 344 KB Output is correct
53 Correct 4 ms 344 KB Output is correct
54 Correct 15 ms 772 KB Output is correct
55 Correct 5 ms 600 KB Output is correct
56 Correct 24 ms 904 KB Output is correct
57 Correct 22 ms 852 KB Output is correct
58 Correct 18 ms 600 KB Output is correct
59 Correct 14 ms 860 KB Output is correct
60 Correct 12 ms 856 KB Output is correct
61 Correct 5 ms 344 KB Output is correct
62 Correct 3 ms 344 KB Output is correct
63 Correct 4 ms 500 KB Output is correct
64 Correct 3 ms 344 KB Output is correct
65 Correct 3 ms 344 KB Output is correct
66 Correct 3 ms 344 KB Output is correct
67 Correct 5 ms 344 KB Output is correct
68 Correct 5 ms 344 KB Output is correct
69 Correct 3 ms 340 KB Output is correct
70 Correct 4 ms 344 KB Output is correct
71 Correct 31 ms 600 KB Output is correct
72 Correct 7 ms 344 KB Output is correct
73 Correct 32 ms 856 KB Output is correct
74 Correct 24 ms 600 KB Output is correct
75 Correct 3 ms 344 KB Output is correct
76 Correct 27 ms 908 KB Output is correct
77 Correct 32 ms 856 KB Output is correct
78 Correct 4 ms 344 KB Output is correct
79 Correct 17 ms 600 KB Output is correct
80 Correct 29 ms 1160 KB Output is correct
81 Correct 34 ms 1112 KB Output is correct
82 Correct 32 ms 804 KB Output is correct
83 Correct 3 ms 344 KB Output is correct
84 Correct 27 ms 748 KB Output is correct
85 Correct 24 ms 592 KB Output is correct
86 Correct 8 ms 344 KB Output is correct
87 Correct 4 ms 344 KB Output is correct
88 Correct 7 ms 612 KB Output is correct
89 Correct 9 ms 600 KB Output is correct
90 Correct 3 ms 600 KB Output is correct
91 Correct 4 ms 340 KB Output is correct
92 Correct 7 ms 524 KB Output is correct
93 Correct 8 ms 344 KB Output is correct
94 Correct 9 ms 520 KB Output is correct
95 Correct 9 ms 344 KB Output is correct
96 Correct 8 ms 344 KB Output is correct
97 Correct 7 ms 344 KB Output is correct