답안 #581753

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
581753 2022-06-23T05:44:28 Z alireza_kaviani 커다란 상품 (IOI17_prize) C++17
100 / 100
68 ms 1952 KB
#include <bits/stdc++.h>
#include "prize.h"
using namespace std;

typedef pair<int, int> pii;

#define X		first
#define Y		second
#define sep		' '

const int MAXN = 2e5 + 10;

int n , mx;
pii res[MAXN];
vector<int> ans;

pii query(int x){
	if(res[x] != pii(-1 , -1)){
		return res[x];
	}
	vector<int> a = ask(x - 1);
	res[x].X = a[0];
	res[x].Y = a[1];
	return res[x];
}

void findMx(){
	int cnt = 0;
	queue<pii> Q;
	Q.push({0 , n});
	while(!Q.empty()){
		pii A = Q.front(); Q.pop();
		int l = A.X , r = A.Y;
		if(res[r] == pii(-1 , -1)){
			cnt++;
			query(r);
		}
		mx = max(mx , res[r].X + res[r].Y);
		if(cnt >= 500){
			return;
		}
		if(r - l == 1){
			continue;
		}
		int mid = l + r >> 1;
		Q.push({l , mid});
		Q.push({mid , r});
	}
}

void solve(int l , int r){ // (l , r]
	pii A = query(r);
	if(A.X + A.Y == mx && A.X == ans.size()){
		return;
	}
	if(r - l == 1){
		ans.push_back(r);
		return;
	}
	int mid = l + r >> 1;
	solve(l , mid);
	solve(mid , r);
}

int find_best(int N) {
	n = N;
	fill(res + 1 , res + MAXN , pii(-1 , -1));
	findMx();
	solve(0 , n);
	for(int i : ans){
		pii A = query(i);
		if(A.X + A.Y == 0){
			return i - 1;
		}
	}
	return -1;
}

Compilation message

prize.cpp: In function 'void findMx()':
prize.cpp:45:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   45 |   int mid = l + r >> 1;
      |             ~~^~~
prize.cpp: In function 'void solve(int, int)':
prize.cpp:53:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   53 |  if(A.X + A.Y == mx && A.X == ans.size()){
      |                        ~~~~^~~~~~~~~~~~~
prize.cpp:60:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   60 |  int mid = l + r >> 1;
      |            ~~^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 1836 KB Output is correct
2 Correct 4 ms 1860 KB Output is correct
3 Correct 5 ms 1872 KB Output is correct
4 Correct 5 ms 1848 KB Output is correct
5 Correct 7 ms 1844 KB Output is correct
6 Correct 7 ms 1872 KB Output is correct
7 Correct 7 ms 1836 KB Output is correct
8 Correct 4 ms 1836 KB Output is correct
9 Correct 6 ms 1872 KB Output is correct
10 Correct 7 ms 1872 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 1824 KB Output is correct
2 Correct 6 ms 1836 KB Output is correct
3 Correct 5 ms 1832 KB Output is correct
4 Correct 5 ms 1832 KB Output is correct
5 Correct 5 ms 1832 KB Output is correct
6 Correct 4 ms 1872 KB Output is correct
7 Correct 6 ms 1832 KB Output is correct
8 Correct 4 ms 1864 KB Output is correct
9 Correct 4 ms 1872 KB Output is correct
10 Correct 7 ms 1744 KB Output is correct
11 Correct 7 ms 1828 KB Output is correct
12 Correct 10 ms 1740 KB Output is correct
13 Correct 9 ms 1872 KB Output is correct
14 Correct 11 ms 1864 KB Output is correct
15 Correct 49 ms 1812 KB Output is correct
16 Correct 31 ms 1836 KB Output is correct
17 Correct 48 ms 1872 KB Output is correct
18 Correct 49 ms 1832 KB Output is correct
19 Correct 20 ms 1852 KB Output is correct
20 Correct 26 ms 1836 KB Output is correct
21 Correct 19 ms 1860 KB Output is correct
22 Correct 32 ms 1832 KB Output is correct
23 Correct 6 ms 1872 KB Output is correct
24 Correct 10 ms 1828 KB Output is correct
25 Correct 45 ms 1840 KB Output is correct
26 Correct 36 ms 1872 KB Output is correct
27 Correct 8 ms 1828 KB Output is correct
28 Correct 23 ms 1832 KB Output is correct
29 Correct 28 ms 1828 KB Output is correct
30 Correct 46 ms 1820 KB Output is correct
31 Correct 51 ms 1852 KB Output is correct
32 Correct 10 ms 1828 KB Output is correct
33 Correct 2 ms 1744 KB Output is correct
34 Correct 49 ms 1736 KB Output is correct
35 Correct 7 ms 1836 KB Output is correct
36 Correct 39 ms 1828 KB Output is correct
37 Correct 10 ms 1864 KB Output is correct
38 Correct 8 ms 1816 KB Output is correct
39 Correct 44 ms 1872 KB Output is correct
40 Correct 21 ms 1868 KB Output is correct
41 Correct 31 ms 1784 KB Output is correct
42 Correct 49 ms 1836 KB Output is correct
43 Correct 20 ms 1832 KB Output is correct
44 Correct 52 ms 1872 KB Output is correct
45 Correct 34 ms 1872 KB Output is correct
46 Correct 37 ms 1820 KB Output is correct
47 Correct 44 ms 1884 KB Output is correct
48 Correct 44 ms 1828 KB Output is correct
49 Correct 47 ms 1744 KB Output is correct
50 Correct 30 ms 1812 KB Output is correct
51 Correct 52 ms 1832 KB Output is correct
52 Correct 39 ms 1736 KB Output is correct
53 Correct 7 ms 1832 KB Output is correct
54 Correct 43 ms 1952 KB Output is correct
55 Correct 41 ms 1824 KB Output is correct
56 Correct 34 ms 1832 KB Output is correct
57 Correct 46 ms 1832 KB Output is correct
58 Correct 22 ms 1852 KB Output is correct
59 Correct 40 ms 1836 KB Output is correct
60 Correct 49 ms 1836 KB Output is correct
61 Correct 4 ms 1852 KB Output is correct
62 Correct 6 ms 1828 KB Output is correct
63 Correct 7 ms 1872 KB Output is correct
64 Correct 4 ms 1868 KB Output is correct
65 Correct 5 ms 1828 KB Output is correct
66 Correct 11 ms 1836 KB Output is correct
67 Correct 8 ms 1868 KB Output is correct
68 Correct 10 ms 1816 KB Output is correct
69 Correct 14 ms 1856 KB Output is correct
70 Correct 14 ms 1744 KB Output is correct
71 Correct 48 ms 1868 KB Output is correct
72 Correct 8 ms 1744 KB Output is correct
73 Correct 46 ms 1876 KB Output is correct
74 Correct 56 ms 1744 KB Output is correct
75 Correct 7 ms 1872 KB Output is correct
76 Correct 39 ms 1744 KB Output is correct
77 Correct 36 ms 1872 KB Output is correct
78 Correct 8 ms 1872 KB Output is correct
79 Correct 23 ms 1744 KB Output is correct
80 Correct 68 ms 1868 KB Output is correct
81 Correct 19 ms 1872 KB Output is correct
82 Correct 36 ms 1744 KB Output is correct
83 Correct 9 ms 1924 KB Output is correct
84 Correct 23 ms 1872 KB Output is correct
85 Correct 38 ms 1872 KB Output is correct
86 Correct 48 ms 1788 KB Output is correct
87 Correct 9 ms 1868 KB Output is correct
88 Correct 38 ms 1872 KB Output is correct
89 Correct 44 ms 1744 KB Output is correct
90 Correct 7 ms 1876 KB Output is correct
91 Correct 26 ms 1868 KB Output is correct
92 Correct 34 ms 1872 KB Output is correct
93 Correct 48 ms 1868 KB Output is correct
94 Correct 56 ms 1872 KB Output is correct
95 Correct 46 ms 1872 KB Output is correct
96 Correct 25 ms 1868 KB Output is correct
97 Correct 44 ms 1872 KB Output is correct