답안 #1012780

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1012780 2024-07-02T15:15:11 Z ThegeekKnight16 커다란 상품 (IOI17_prize) C++17
100 / 100
32 ms 1532 KB
#include <bits/stdc++.h>
#include "prize.h"
using namespace std;
map<int, vector<int>> ans;

vector<int> query(int x)
{
    if (ans.count(x)) return ans[x];
    return ans[x] = ask(x);
}

int dc(int ini, int fim, int qMen, int qL, int qR)
{
    //Cases in which i don't have to test
    if (ini > fim || qL + qR == qMen) return -1;
    if (fim - ini <= 1)
    {
        vector<int> aL = query(ini), aR = query(fim);
        if (aL[0]+aL[1] == 0) return ini;
        if (aR[0]+aR[1] == 0) return fim;
        return -1;
    }
    if (query(ini) == query(fim)) return -1;

    //all of them are expensive
    if (fim - ini + 1 == qMen - (qL + qR))
    {
        for (int i = ini; i <= fim; i++)
        {
            vector<int> a = query(i);
            if (a[0]+a[1] == 0) return i;
        }
        return -1;
    }

    //get middle expensive
    int mL = (ini+fim)>>1, mR = (ini+fim)>>1;
    vector<int> aL, aR;
    while (mL >= ini)
    {
        aL = query(mL);
        if (aL[0]+aL[1] == 0) return mL;
        if (aL[0]+aL[1] < qMen) --mL;
        else break;
    }
    while (mR <= fim)
    {
        aR = query(mR);
        if (aR[0]+aR[1] == 0) return mR;
        if (aR[0]+aR[1] < qMen) ++mR;
        else break;
    }

    //then divide and conquer
    int x = dc(mR, fim, qMen, aR[0], qR);
    if (x == -1) return dc(ini, mL, qMen, qL, aL[1]);
    return x;

}

int find_best(int n)
{
    //here to find expensive quantity -> P(expensive) ~ 1/sqrt(N)
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    vector<int> ids;
    for (int i = 0; i < 10; i++) ids.push_back(uniform_int_distribution<int>(0, n-1)(rng));
    vector<vector<int>> possQ;
    for (auto x : ids) possQ.push_back(query(x));
    int qMen = 1;
    for (auto &x : possQ) qMen = max(qMen, x[0]+x[1]);

    return dc(0, n-1, qMen, 0, 0);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 420 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 2 ms 480 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 5 ms 344 KB Output is correct
15 Correct 25 ms 832 KB Output is correct
16 Correct 3 ms 344 KB Output is correct
17 Correct 20 ms 848 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 18 ms 856 KB Output is correct
20 Correct 12 ms 600 KB Output is correct
21 Correct 12 ms 568 KB Output is correct
22 Correct 17 ms 856 KB Output is correct
23 Correct 1 ms 344 KB Output is correct
24 Correct 3 ms 344 KB Output is correct
25 Correct 10 ms 600 KB Output is correct
26 Correct 8 ms 600 KB Output is correct
27 Correct 1 ms 344 KB Output is correct
28 Correct 1 ms 344 KB Output is correct
29 Correct 3 ms 432 KB Output is correct
30 Correct 1 ms 344 KB Output is correct
31 Correct 16 ms 1104 KB Output is correct
32 Correct 1 ms 344 KB Output is correct
33 Correct 1 ms 344 KB Output is correct
34 Correct 14 ms 852 KB Output is correct
35 Correct 1 ms 344 KB Output is correct
36 Correct 13 ms 628 KB Output is correct
37 Correct 2 ms 340 KB Output is correct
38 Correct 2 ms 344 KB Output is correct
39 Correct 14 ms 684 KB Output is correct
40 Correct 0 ms 344 KB Output is correct
41 Correct 11 ms 748 KB Output is correct
42 Correct 11 ms 600 KB Output is correct
43 Correct 8 ms 508 KB Output is correct
44 Correct 13 ms 492 KB Output is correct
45 Correct 11 ms 856 KB Output is correct
46 Correct 22 ms 1044 KB Output is correct
47 Correct 12 ms 600 KB Output is correct
48 Correct 9 ms 600 KB Output is correct
49 Correct 13 ms 1104 KB Output is correct
50 Correct 1 ms 344 KB Output is correct
51 Correct 12 ms 600 KB Output is correct
52 Correct 20 ms 1368 KB Output is correct
53 Correct 0 ms 344 KB Output is correct
54 Correct 12 ms 600 KB Output is correct
55 Correct 20 ms 848 KB Output is correct
56 Correct 0 ms 344 KB Output is correct
57 Correct 7 ms 344 KB Output is correct
58 Correct 5 ms 344 KB Output is correct
59 Correct 13 ms 636 KB Output is correct
60 Correct 6 ms 600 KB Output is correct
61 Correct 0 ms 344 KB Output is correct
62 Correct 1 ms 344 KB Output is correct
63 Correct 0 ms 428 KB Output is correct
64 Correct 1 ms 344 KB Output is correct
65 Correct 0 ms 344 KB Output is correct
66 Correct 2 ms 600 KB Output is correct
67 Correct 1 ms 344 KB Output is correct
68 Correct 3 ms 344 KB Output is correct
69 Correct 2 ms 600 KB Output is correct
70 Correct 1 ms 344 KB Output is correct
71 Correct 24 ms 844 KB Output is correct
72 Correct 2 ms 344 KB Output is correct
73 Correct 21 ms 776 KB Output is correct
74 Correct 15 ms 856 KB Output is correct
75 Correct 1 ms 344 KB Output is correct
76 Correct 22 ms 1144 KB Output is correct
77 Correct 23 ms 1112 KB Output is correct
78 Correct 2 ms 344 KB Output is correct
79 Correct 9 ms 600 KB Output is correct
80 Correct 24 ms 1144 KB Output is correct
81 Correct 27 ms 848 KB Output is correct
82 Correct 28 ms 1176 KB Output is correct
83 Correct 1 ms 344 KB Output is correct
84 Correct 21 ms 856 KB Output is correct
85 Correct 32 ms 1532 KB Output is correct
86 Correct 3 ms 344 KB Output is correct
87 Correct 3 ms 344 KB Output is correct
88 Correct 2 ms 344 KB Output is correct
89 Correct 4 ms 344 KB Output is correct
90 Correct 1 ms 344 KB Output is correct
91 Correct 2 ms 344 KB Output is correct
92 Correct 0 ms 356 KB Output is correct
93 Correct 2 ms 344 KB Output is correct
94 Correct 2 ms 344 KB Output is correct
95 Correct 2 ms 344 KB Output is correct
96 Correct 2 ms 344 KB Output is correct
97 Correct 0 ms 344 KB Output is correct