답안 #1118463

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1118463 2024-11-25T14:12:36 Z adaawf 커다란 상품 (IOI17_prize) C++17
99.65 / 100
94 ms 3732 KB
#include <bits/stdc++.h>
using namespace std;
int a[200005], cc = 0, hh = 200000, dd[200005], c[200005][10], da[200005];
void build(int n) {
    for (int j = 0; j <= 9; j++) {
        c[0][j] = (a[0] <= j);
        for (int i = 1; i < n; i++) {
            c[i][j] = c[i - 1][j] + (a[i] <= j);
        }
    }
}
mt19937 mt(chrono::steady_clock::now().time_since_epoch().count());
vector<int> ask(int i);
int find_best(int n) {
    vector<pair<int, pair<int, int>>> v;
    vector<int> t;
    int mi = 0;
    if (n <= 170000) {
         for (int i = 0; i < 480; i++) {
            t = ask(i);
            if (t[0] + t[1] == 0) return i;
            mi = max(mi, t[0] + t[1]);
        }
    }
    else {
        for (int i = 0; i < n; i++) da[i] = 0;
        for (int i = 0; i < 450; i++) {
            int h;
            while (1) {
                h = 1ll * (mt() % n) % n;
                if (da[h] == 1) continue;
                break;
            }
            da[h] = 1;
            t = ask(h);
            if (t[0] + t[1] == 0) return h;
            mi = max(mi, t[0] + t[1]);
        }
    }
    for (int i = 0; i < n; i++) dd[i] = da[i] = 0;
    int c = 0;
    for (int i = 0; i < n; i += 500) {
        while (1) {
            if (i >= n) break;
            t = ask(i);
            if (t[0] + t[1] == 0) return i;
            if (t[0] + t[1] == mi) {
                break;
            }
            c++;
            i++;
        }
        if (i < n) {
            v.push_back({i, {t[1], c}});
            c = 0;
        }
    }
    v.push_back({n, {0, c}});
    vector<int> vb, vvb;
    for (int i = 0; i < v.size() - 1; i++) vb.push_back(i);
    for (int i = 0; i < vb.size(); i++) {
        int h = mt() % (vb.size() - i) + 1;
        for (int j = 0; j < vb.size(); j++) {
            if (da[j] == 0) {
                h--;
                if (h == 0) {
                    vvb.push_back(vb[j]);
                    da[j] = 1;
                    break;
                }
            }
        }
    }
    for (int i : vvb) {
        int h = v[i].second.first - v[i + 1].second.first;
        h -= v[i + 1].second.second;
        vector<int> va, vc, vv;
        for (int j = v[i].first; j < min(v[i].first + 500, n + 1); j++) {
            va.push_back(j);
        }
        for (int j = 0; j < h; j++) {
            int l = 0, r = va.size() - 1, res;
            while (1) {
                int mid = (l + r) / 2;
                res = va[mid];
                dd[va[mid]] = 1;
                t = ask(va[mid]);
                if (t[0] + t[1] == 0) return va[mid];
                if (t[0] + t[1] != mi) break;
                for (int w : vc) {
                    if (w <= va[mid]) t[1]++;
                }
                if (t[1] == v[i].second.first) {
                    l = mid + 1;
                }
                else r = mid - 1;
            }
            vc.push_back(res);
            vv.clear();
            for (int w : va) {
                if (dd[w] == 0) vv.push_back(w);
            }
            va = vv;
        }
    }
    return -1;
}

Compilation message

prize.cpp: In function 'int find_best(int)':
prize.cpp:60:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, std::pair<int, int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   60 |     for (int i = 0; i < v.size() - 1; i++) vb.push_back(i);
      |                     ~~^~~~~~~~~~~~~~
prize.cpp:61:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   61 |     for (int i = 0; i < vb.size(); i++) {
      |                     ~~^~~~~~~~~~~
prize.cpp:63:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   63 |         for (int j = 0; j < vb.size(); j++) {
      |                         ~~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 3472 KB Output is correct
2 Correct 16 ms 3468 KB Output is correct
3 Correct 13 ms 3448 KB Output is correct
4 Correct 15 ms 3480 KB Output is correct
5 Correct 12 ms 1872 KB Output is correct
6 Correct 10 ms 1872 KB Output is correct
7 Correct 12 ms 2000 KB Output is correct
8 Correct 14 ms 2128 KB Output is correct
9 Correct 17 ms 1872 KB Output is correct
10 Correct 16 ms 2020 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 2008 KB Output is correct
2 Correct 15 ms 2032 KB Output is correct
3 Correct 16 ms 2304 KB Output is correct
4 Correct 13 ms 2292 KB Output is correct
5 Correct 14 ms 3716 KB Output is correct
6 Correct 9 ms 3420 KB Output is correct
7 Correct 12 ms 3476 KB Output is correct
8 Correct 12 ms 3408 KB Output is correct
9 Correct 14 ms 3468 KB Output is correct
10 Correct 15 ms 2260 KB Output is correct
11 Correct 16 ms 2276 KB Output is correct
12 Correct 24 ms 2032 KB Output is correct
13 Correct 18 ms 2016 KB Output is correct
14 Correct 14 ms 468 KB Output is correct
15 Correct 57 ms 2020 KB Output is correct
16 Correct 16 ms 2420 KB Output is correct
17 Correct 40 ms 1884 KB Output is correct
18 Correct 67 ms 1884 KB Output is correct
19 Correct 32 ms 3452 KB Output is correct
20 Correct 42 ms 3024 KB Output is correct
21 Correct 14 ms 3456 KB Output is correct
22 Correct 19 ms 3444 KB Output is correct
23 Correct 15 ms 2004 KB Output is correct
24 Correct 18 ms 2028 KB Output is correct
25 Correct 15 ms 2436 KB Output is correct
26 Correct 50 ms 2004 KB Output is correct
27 Correct 15 ms 1872 KB Output is correct
28 Correct 37 ms 2004 KB Output is correct
29 Correct 33 ms 2128 KB Output is correct
30 Correct 44 ms 2260 KB Output is correct
31 Correct 26 ms 3708 KB Output is correct
32 Correct 17 ms 3720 KB Output is correct
33 Correct 1 ms 336 KB Output is correct
34 Correct 28 ms 3452 KB Output is correct
35 Correct 13 ms 3468 KB Output is correct
36 Correct 56 ms 2036 KB Output is correct
37 Correct 15 ms 2024 KB Output is correct
38 Correct 18 ms 2632 KB Output is correct
39 Correct 46 ms 2264 KB Output is correct
40 Correct 27 ms 1872 KB Output is correct
41 Correct 27 ms 2268 KB Output is correct
42 Correct 25 ms 1872 KB Output is correct
43 Correct 29 ms 2040 KB Output is correct
44 Correct 34 ms 2024 KB Output is correct
45 Correct 54 ms 3464 KB Output is correct
46 Correct 64 ms 3456 KB Output is correct
47 Correct 74 ms 3448 KB Output is correct
48 Correct 24 ms 1872 KB Output is correct
49 Correct 16 ms 2036 KB Output is correct
50 Correct 39 ms 2128 KB Output is correct
51 Correct 31 ms 2140 KB Output is correct
52 Correct 54 ms 2124 KB Output is correct
53 Correct 18 ms 2048 KB Output is correct
54 Correct 47 ms 2276 KB Output is correct
55 Correct 36 ms 3732 KB Output is correct
56 Correct 52 ms 2140 KB Output is correct
57 Correct 41 ms 3664 KB Output is correct
58 Correct 35 ms 3468 KB Output is correct
59 Correct 74 ms 3440 KB Output is correct
60 Correct 46 ms 3696 KB Output is correct
61 Correct 15 ms 3664 KB Output is correct
62 Correct 18 ms 2128 KB Output is correct
63 Correct 19 ms 2008 KB Output is correct
64 Correct 17 ms 1872 KB Output is correct
65 Correct 19 ms 2276 KB Output is correct
66 Correct 20 ms 2280 KB Output is correct
67 Correct 23 ms 1872 KB Output is correct
68 Correct 17 ms 2024 KB Output is correct
69 Correct 26 ms 2140 KB Output is correct
70 Correct 16 ms 2140 KB Output is correct
71 Partially correct 75 ms 3728 KB Partially correct - number of queries: 5035
72 Correct 21 ms 3456 KB Output is correct
73 Correct 80 ms 3664 KB Output is correct
74 Correct 69 ms 2128 KB Output is correct
75 Correct 13 ms 2260 KB Output is correct
76 Correct 64 ms 2128 KB Output is correct
77 Correct 69 ms 2040 KB Output is correct
78 Correct 20 ms 2004 KB Output is correct
79 Correct 31 ms 3408 KB Output is correct
80 Correct 62 ms 3704 KB Output is correct
81 Correct 69 ms 3704 KB Output is correct
82 Correct 64 ms 2024 KB Output is correct
83 Correct 19 ms 2264 KB Output is correct
84 Correct 48 ms 2004 KB Output is correct
85 Correct 94 ms 2128 KB Output is correct
86 Correct 18 ms 2256 KB Output is correct
87 Correct 9 ms 3420 KB Output is correct
88 Correct 60 ms 3704 KB Output is correct
89 Correct 30 ms 3448 KB Output is correct
90 Correct 15 ms 3468 KB Output is correct
91 Correct 26 ms 2032 KB Output is correct
92 Correct 42 ms 2012 KB Output is correct
93 Correct 77 ms 2032 KB Output is correct
94 Correct 71 ms 2008 KB Output is correct
95 Correct 66 ms 1872 KB Output is correct
96 Correct 74 ms 3684 KB Output is correct
97 Correct 54 ms 3700 KB Output is correct