답안 #137889

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
137889 2019-07-28T13:26:06 Z MAMBA 커다란 상품 (IOI17_prize) C++14
97.92 / 100
61 ms 936 KB
#include "prize.h"
#include <bits/stdc++.h>

using namespace std;

#define rep(i, j, k) for (int i = j; i < (int)k; i++)

typedef vector<int> vi;

inline bool smax(int &a, int b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

inline bool smin(int &a, int b) {
  if (b < a) {
    a = b;
    return true;
  }
  return false;
}

inline int sum(vi me) { return me[0] + me[1]; }

int mx;
map<int, vi> mp;
inline vi gholi(int v) {
  if (mp.count(v)) return mp[v];
  assert(mp.size() + 1 <= 10000);
  mp[v] = ask(v);
  smax(mx, sum(mp[v]));
  return mp[v];
}

int N;

int solve(int l, int r, int le, int ri) {
  assert(l >= 0 && r <= N);
  if (l >= r || le + ri == mx) return -1;
  int mid = l + r >> 1;
  rep(i, mid, r) {
    vi me = gholi(i);
    if (sum(me) == 0) return i;
    if (sum(me) == mx) {
      int res = solve(l, mid, le, me[1] + (i - mid));
      if (~res) return res;
      return solve(i + 1, r, me[0], ri);
    }
  }
  return solve(l, mid, le, r - mid + ri);
}

int find_best(int n) {
  N = n;
  mp.clear();
  mx = -1;
  rep(i, 0, min(n, 450)) {
    smax(mx, sum(gholi(i)));
    if (sum(gholi(i)) == 0) return i;
  }

  int me = solve(0, n, 0, 0);
  assert(~me);
  return me;
}

Compilation message

prize.cpp: In function 'int solve(int, int, int, int)':
prize.cpp:43:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   int mid = l + r >> 1;
             ~~^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 248 KB Output is correct
2 Correct 6 ms 376 KB Output is correct
3 Correct 7 ms 376 KB Output is correct
4 Correct 6 ms 376 KB Output is correct
5 Correct 8 ms 248 KB Output is correct
6 Correct 2 ms 248 KB Output is correct
7 Correct 6 ms 248 KB Output is correct
8 Correct 6 ms 248 KB Output is correct
9 Correct 5 ms 428 KB Output is correct
10 Correct 6 ms 248 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 248 KB Output is correct
2 Correct 5 ms 424 KB Output is correct
3 Correct 6 ms 376 KB Output is correct
4 Correct 7 ms 248 KB Output is correct
5 Correct 4 ms 412 KB Output is correct
6 Correct 2 ms 248 KB Output is correct
7 Correct 6 ms 396 KB Output is correct
8 Correct 7 ms 248 KB Output is correct
9 Correct 7 ms 248 KB Output is correct
10 Correct 7 ms 376 KB Output is correct
11 Correct 6 ms 440 KB Output is correct
12 Correct 5 ms 540 KB Output is correct
13 Correct 12 ms 308 KB Output is correct
14 Correct 8 ms 328 KB Output is correct
15 Correct 12 ms 528 KB Output is correct
16 Correct 27 ms 768 KB Output is correct
17 Correct 7 ms 248 KB Output is correct
18 Correct 54 ms 720 KB Output is correct
19 Correct 7 ms 248 KB Output is correct
20 Correct 11 ms 504 KB Output is correct
21 Correct 23 ms 496 KB Output is correct
22 Correct 10 ms 376 KB Output is correct
23 Correct 8 ms 248 KB Output is correct
24 Correct 7 ms 376 KB Output is correct
25 Correct 28 ms 592 KB Output is correct
26 Correct 25 ms 544 KB Output is correct
27 Correct 7 ms 376 KB Output is correct
28 Correct 32 ms 764 KB Output is correct
29 Correct 38 ms 632 KB Output is correct
30 Correct 57 ms 792 KB Output is correct
31 Correct 8 ms 392 KB Output is correct
32 Correct 11 ms 376 KB Output is correct
33 Correct 2 ms 248 KB Output is correct
34 Correct 18 ms 492 KB Output is correct
35 Correct 7 ms 376 KB Output is correct
36 Correct 11 ms 516 KB Output is correct
37 Correct 5 ms 492 KB Output is correct
38 Correct 7 ms 248 KB Output is correct
39 Correct 26 ms 504 KB Output is correct
40 Correct 45 ms 704 KB Output is correct
41 Correct 36 ms 584 KB Output is correct
42 Correct 32 ms 560 KB Output is correct
43 Correct 18 ms 584 KB Output is correct
44 Correct 24 ms 432 KB Output is correct
45 Correct 22 ms 432 KB Output is correct
46 Correct 5 ms 248 KB Output is correct
47 Correct 26 ms 436 KB Output is correct
48 Correct 40 ms 596 KB Output is correct
49 Correct 14 ms 388 KB Output is correct
50 Correct 55 ms 760 KB Output is correct
51 Correct 25 ms 504 KB Output is correct
52 Correct 7 ms 352 KB Output is correct
53 Correct 5 ms 456 KB Output is correct
54 Correct 24 ms 504 KB Output is correct
55 Correct 4 ms 428 KB Output is correct
56 Correct 41 ms 824 KB Output is correct
57 Correct 23 ms 656 KB Output is correct
58 Correct 37 ms 632 KB Output is correct
59 Correct 27 ms 624 KB Output is correct
60 Correct 35 ms 504 KB Output is correct
61 Correct 8 ms 276 KB Output is correct
62 Correct 4 ms 340 KB Output is correct
63 Correct 9 ms 376 KB Output is correct
64 Correct 7 ms 248 KB Output is correct
65 Correct 5 ms 348 KB Output is correct
66 Correct 11 ms 296 KB Output is correct
67 Correct 11 ms 360 KB Output is correct
68 Correct 7 ms 392 KB Output is correct
69 Correct 12 ms 304 KB Output is correct
70 Correct 9 ms 384 KB Output is correct
71 Partially correct 61 ms 880 KB Partially correct - number of queries: 5208
72 Correct 12 ms 376 KB Output is correct
73 Partially correct 43 ms 884 KB Partially correct - number of queries: 5145
74 Partially correct 59 ms 936 KB Partially correct - number of queries: 5172
75 Correct 5 ms 376 KB Output is correct
76 Correct 52 ms 808 KB Output is correct
77 Correct 60 ms 824 KB Output is correct
78 Correct 13 ms 296 KB Output is correct
79 Correct 30 ms 564 KB Output is correct
80 Correct 35 ms 816 KB Output is correct
81 Correct 49 ms 764 KB Output is correct
82 Correct 51 ms 812 KB Output is correct
83 Correct 9 ms 376 KB Output is correct
84 Correct 29 ms 768 KB Output is correct
85 Correct 50 ms 760 KB Output is correct
86 Correct 5 ms 312 KB Output is correct
87 Correct 7 ms 248 KB Output is correct
88 Correct 9 ms 248 KB Output is correct
89 Correct 6 ms 248 KB Output is correct
90 Correct 8 ms 360 KB Output is correct
91 Correct 6 ms 248 KB Output is correct
92 Correct 7 ms 348 KB Output is correct
93 Correct 11 ms 380 KB Output is correct
94 Correct 13 ms 376 KB Output is correct
95 Correct 11 ms 376 KB Output is correct
96 Correct 9 ms 376 KB Output is correct
97 Correct 6 ms 252 KB Output is correct