답안 #245318

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
245318 2020-07-06T03:44:15 Z LittleFlowers__ 커다란 상품 (IOI17_prize) C++17
100 / 100
65 ms 2304 KB
#include <vector>
#include <cmath>
#include <cstring>
#include "prize.h"
#define X first
#define Y second
using namespace std;

typedef pair<int,int> pii;

int numb;
pii P[210000];
bool mark[210000];
vector<int>vtmp;

pii query(int x)
{
  if(mark[x]) return P[x];
  mark[x]=true;
  vtmp=ask(x);
  pii tmp=pii(vtmp[0],vtmp[1]);
  if(tmp.X+tmp.Y==0) throw x;
  return P[x]=tmp;
}

void bs(int l,int r,int nl,int nr)
{
  if(l>r) return;
  for(int i=0;i<=r-l;i++)
    {
      int mid,midl=(l+r)/2-i/2,midr=(l+r)/2+(i+1)/2;
      if(i%2==0) mid=midl;
      else mid=midr;
      pii tmp=query(mid);
      if(tmp.X+tmp.Y==numb)
	{
	  int tmpl=(i%2==0?0:midr-midl);
	  int tmpr=(i%2==1?0:midr-midl);
	  if(tmp.X-tmpl>nl) bs(l,midl-1,nl,tmp.Y+tmpl);
	  if(tmp.Y-tmpr>nr) bs(midr+1,r,tmp.X+tmpr,nr);
	  break;
	}
    }
}

int find_best(int n)
{
  if(n==1) return 0;
  try{
    numb=0;
    memset(mark,false,sizeof mark);
    int p=0;
    for(int i=0;i<sqrt(n)+30 && i<n && numb<=26;i++)
      {
	pii tmp=query(i);
	if(tmp.X+tmp.Y>numb) p=i;
	numb=max(numb,tmp.X+tmp.Y);
      }
    bs(p,n-1,p,0);
  }
  catch(int ans){
    return ans;
  }
  return -1;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 632 KB Output is correct
2 Correct 12 ms 640 KB Output is correct
3 Correct 11 ms 640 KB Output is correct
4 Correct 10 ms 632 KB Output is correct
5 Correct 13 ms 640 KB Output is correct
6 Correct 6 ms 728 KB Output is correct
7 Correct 13 ms 632 KB Output is correct
8 Correct 9 ms 600 KB Output is correct
9 Correct 12 ms 640 KB Output is correct
10 Correct 13 ms 640 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 632 KB Output is correct
2 Correct 13 ms 632 KB Output is correct
3 Correct 9 ms 600 KB Output is correct
4 Correct 11 ms 640 KB Output is correct
5 Correct 12 ms 640 KB Output is correct
6 Correct 7 ms 640 KB Output is correct
7 Correct 12 ms 632 KB Output is correct
8 Correct 13 ms 640 KB Output is correct
9 Correct 12 ms 640 KB Output is correct
10 Correct 13 ms 640 KB Output is correct
11 Correct 8 ms 888 KB Output is correct
12 Correct 7 ms 580 KB Output is correct
13 Correct 10 ms 1152 KB Output is correct
14 Correct 7 ms 640 KB Output is correct
15 Correct 14 ms 888 KB Output is correct
16 Correct 35 ms 1912 KB Output is correct
17 Correct 7 ms 632 KB Output is correct
18 Correct 29 ms 2304 KB Output is correct
19 Correct 7 ms 640 KB Output is correct
20 Correct 16 ms 896 KB Output is correct
21 Correct 20 ms 1144 KB Output is correct
22 Correct 11 ms 760 KB Output is correct
23 Correct 13 ms 632 KB Output is correct
24 Correct 7 ms 632 KB Output is correct
25 Correct 26 ms 1400 KB Output is correct
26 Correct 31 ms 1400 KB Output is correct
27 Correct 11 ms 640 KB Output is correct
28 Correct 40 ms 2016 KB Output is correct
29 Correct 23 ms 1840 KB Output is correct
30 Correct 33 ms 2220 KB Output is correct
31 Correct 7 ms 632 KB Output is correct
32 Correct 10 ms 1000 KB Output is correct
33 Correct 6 ms 640 KB Output is correct
34 Correct 19 ms 1016 KB Output is correct
35 Correct 10 ms 760 KB Output is correct
36 Correct 20 ms 992 KB Output is correct
37 Correct 8 ms 768 KB Output is correct
38 Correct 13 ms 632 KB Output is correct
39 Correct 24 ms 1272 KB Output is correct
40 Correct 51 ms 2168 KB Output is correct
41 Correct 39 ms 1532 KB Output is correct
42 Correct 42 ms 1528 KB Output is correct
43 Correct 27 ms 1400 KB Output is correct
44 Correct 23 ms 1144 KB Output is correct
45 Correct 21 ms 1020 KB Output is correct
46 Correct 7 ms 640 KB Output is correct
47 Correct 22 ms 1272 KB Output is correct
48 Correct 45 ms 1656 KB Output is correct
49 Correct 11 ms 760 KB Output is correct
50 Correct 53 ms 2152 KB Output is correct
51 Correct 18 ms 1296 KB Output is correct
52 Correct 7 ms 632 KB Output is correct
53 Correct 14 ms 756 KB Output is correct
54 Correct 30 ms 1272 KB Output is correct
55 Correct 7 ms 632 KB Output is correct
56 Correct 47 ms 2168 KB Output is correct
57 Correct 43 ms 1656 KB Output is correct
58 Correct 36 ms 1728 KB Output is correct
59 Correct 25 ms 1528 KB Output is correct
60 Correct 38 ms 1392 KB Output is correct
61 Correct 15 ms 760 KB Output is correct
62 Correct 9 ms 592 KB Output is correct
63 Correct 11 ms 768 KB Output is correct
64 Correct 14 ms 768 KB Output is correct
65 Correct 7 ms 640 KB Output is correct
66 Correct 8 ms 628 KB Output is correct
67 Correct 8 ms 640 KB Output is correct
68 Correct 10 ms 632 KB Output is correct
69 Correct 11 ms 632 KB Output is correct
70 Correct 8 ms 640 KB Output is correct
71 Correct 63 ms 2168 KB Output is correct
72 Correct 13 ms 1152 KB Output is correct
73 Correct 51 ms 2172 KB Output is correct
74 Correct 41 ms 2168 KB Output is correct
75 Correct 11 ms 768 KB Output is correct
76 Correct 40 ms 2168 KB Output is correct
77 Correct 49 ms 2168 KB Output is correct
78 Correct 13 ms 1280 KB Output is correct
79 Correct 18 ms 2128 KB Output is correct
80 Correct 65 ms 2136 KB Output is correct
81 Correct 43 ms 2168 KB Output is correct
82 Correct 60 ms 2168 KB Output is correct
83 Correct 12 ms 768 KB Output is correct
84 Correct 47 ms 2168 KB Output is correct
85 Correct 65 ms 2168 KB Output is correct
86 Correct 13 ms 640 KB Output is correct
87 Correct 7 ms 640 KB Output is correct
88 Correct 13 ms 640 KB Output is correct
89 Correct 13 ms 640 KB Output is correct
90 Correct 11 ms 640 KB Output is correct
91 Correct 10 ms 640 KB Output is correct
92 Correct 9 ms 640 KB Output is correct
93 Correct 11 ms 896 KB Output is correct
94 Correct 16 ms 1024 KB Output is correct
95 Correct 17 ms 1024 KB Output is correct
96 Correct 13 ms 896 KB Output is correct
97 Correct 12 ms 640 KB Output is correct