답안 #397275

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
397275 2021-05-01T19:26:33 Z idk321 커다란 상품 (IOI17_prize) C++11
90 / 100
117 ms 11284 KB
#include "prize.h"

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int n;


vector<int> big;

pair<int, vector<int>> differentRight(int a, int b, vector<int> inf)
{

    int res = -1;
    vector<int> rinf;
    while (a <= b)
    {
        int mid = (a + b) / 2;
        vector<int> cinf = ask(mid);

        if (cinf == inf)
        {
            a = mid + 1;
        } else
        {
            res = mid;
            rinf = cinf;
            b = mid - 1;
        }
    }

    return {res, rinf};
}

pair<int, vector<int>> differentLeft(int a, int b, vector<int> inf)
{
    int res = -1;
    vector<int> rinf;
    while (a <= b)
    {
        int mid = (a + b) / 2;
        vector<int> cinf = ask(mid);

        if (cinf == inf)
        {
            b = mid - 1;
        } else
        {
            res = mid;
            rinf = cinf;
            a = mid + 1;
        }
    }

    return {res, rinf};
}

int find_best(int N) {
    n = N;


    if (n <= 5000)
    {
        int res = -1;
        for (int i = 0; i < n; i++)
        {
            vector<int> v = ask(i);
            if (v[0] == 0 && v[1] == 0) res = i;
        }

        return res;
    }

    vector<int> needed = {0, 0};
    big = {0, 0};
    vector<int> inf;
    int cur = 0;
    inf = ask(cur);
    if (inf[0] + inf[1] > big[0] + big[1]) big = inf;

    if (inf == needed) return cur;
    for (int i = 0; i < 4; i++)
    {
        auto p1 = differentRight(cur, n - 1, inf);
        if (p1.first == -1) break;
        cur = p1.first;
        inf = p1.second;
        if (inf == needed) return cur;
        if (inf[0] + inf[1] > big[0] + big[1]) big = inf;
    }
    int sum = big[0] + big[1];

    vector<vector<int>> infAt(n, vector<int>(2));
    for (int i = 0; i < n; i += 100)
    {
        infAt[i] = ask(i);
        if (infAt[i] == needed) return i;
    }

    for (int i = 0; i + 100 < n; i += 100)
    {
        int l = i;
        int r = i + 100;

        if (infAt[l] == needed) return l;
        if (infAt[r] == needed) return r;

        if (infAt[l][0] + infAt[l][1] == infAt[r][0] + infAt[r][1])
        {
            if (infAt[l][1] - infAt[r][1] == 0) continue;
        }

        if (infAt[l][0] + infAt[l][1] == sum)
        {
            auto p1 = differentRight(l, r, infAt[l]);
            l = p1.first;
            if (l == -1) continue;
            infAt[l] = p1.second;
        }
        if (infAt[r][0] + infAt[r][1] == sum)
        {
            auto p2 = differentLeft(l, r, infAt[r]);
            r = p2.first;
            if (r == -1) continue;
            infAt[r] = p2.second;
        }


        if (l != -1 && infAt[l] == needed) return l;
        if (r != -1 && infAt[r] == needed) return r;

        if (l == -1 || r == -1) continue;

        if (r - l <= 1) continue;
        if ((infAt[l][0] + infAt[l][1] == infAt[r][0] + infAt[r][1] &&  infAt[l][1] - infAt[r][1] > 0) || (infAt[l][0] + infAt[l][1] != infAt[r][0] + infAt[r][1]))
        {
            for (int j = l + 1; j < r; j++)
            {
                vector<int> cinf = ask(j);
                if (cinf[0] == 0 && cinf[1] == 0) return j;
            }
        }
    }

    for (int i = 0; i < n; i += 100)
    {
        if (i + 100 >= n)
        {
            for (int j = i + 1; j < n; j++)
            {
                vector<int> cinf = ask(j);
                if (cinf == needed) return j;
            }
        }
    }


	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 200 KB Output is correct
2 Correct 1 ms 288 KB Output is correct
3 Correct 2 ms 200 KB Output is correct
4 Correct 1 ms 200 KB Output is correct
5 Correct 1 ms 288 KB Output is correct
6 Correct 1 ms 200 KB Output is correct
7 Correct 1 ms 280 KB Output is correct
8 Correct 1 ms 280 KB Output is correct
9 Correct 1 ms 280 KB Output is correct
10 Correct 1 ms 200 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 200 KB Output is correct
2 Correct 1 ms 200 KB Output is correct
3 Correct 1 ms 200 KB Output is correct
4 Correct 1 ms 288 KB Output is correct
5 Correct 1 ms 200 KB Output is correct
6 Correct 1 ms 200 KB Output is correct
7 Correct 1 ms 200 KB Output is correct
8 Correct 1 ms 200 KB Output is correct
9 Correct 1 ms 200 KB Output is correct
10 Correct 1 ms 200 KB Output is correct
11 Correct 48 ms 11160 KB Output is correct
12 Correct 1 ms 200 KB Output is correct
13 Correct 49 ms 11200 KB Output is correct
14 Correct 6 ms 1352 KB Output is correct
15 Correct 34 ms 11164 KB Output is correct
16 Partially correct 78 ms 11156 KB Partially correct - number of queries: 6785
17 Correct 1 ms 272 KB Output is correct
18 Partially correct 92 ms 11284 KB Partially correct - number of queries: 7779
19 Correct 1 ms 200 KB Output is correct
20 Correct 38 ms 5752 KB Output is correct
21 Correct 59 ms 11160 KB Output is correct
22 Correct 37 ms 11168 KB Output is correct
23 Correct 1 ms 292 KB Output is correct
24 Correct 1 ms 204 KB Output is correct
25 Correct 57 ms 11164 KB Output is correct
26 Correct 49 ms 11200 KB Output is correct
27 Correct 40 ms 11156 KB Output is correct
28 Partially correct 75 ms 11148 KB Partially correct - number of queries: 7112
29 Partially correct 70 ms 11160 KB Partially correct - number of queries: 5928
30 Partially correct 98 ms 11208 KB Partially correct - number of queries: 7689
31 Correct 1 ms 288 KB Output is correct
32 Correct 43 ms 11160 KB Output is correct
33 Correct 2 ms 200 KB Output is correct
34 Correct 59 ms 11200 KB Output is correct
35 Correct 37 ms 11168 KB Output is correct
36 Correct 64 ms 11200 KB Output is correct
37 Correct 31 ms 11156 KB Output is correct
38 Correct 1 ms 200 KB Output is correct
39 Correct 71 ms 11164 KB Output is correct
40 Partially correct 78 ms 11160 KB Partially correct - number of queries: 6878
41 Partially correct 79 ms 11220 KB Partially correct - number of queries: 5309
42 Partially correct 83 ms 11212 KB Partially correct - number of queries: 5309
43 Correct 60 ms 11220 KB Output is correct
44 Correct 54 ms 11164 KB Output is correct
45 Correct 51 ms 11200 KB Output is correct
46 Correct 1 ms 276 KB Output is correct
47 Correct 67 ms 11200 KB Output is correct
48 Partially correct 90 ms 11160 KB Partially correct - number of queries: 6115
49 Correct 38 ms 11232 KB Output is correct
50 Partially correct 75 ms 11200 KB Partially correct - number of queries: 7757
51 Correct 38 ms 11172 KB Output is correct
52 Correct 43 ms 11156 KB Output is correct
53 Correct 26 ms 11200 KB Output is correct
54 Correct 57 ms 11164 KB Output is correct
55 Correct 1 ms 200 KB Output is correct
56 Partially correct 72 ms 11248 KB Partially correct - number of queries: 7752
57 Partially correct 82 ms 11188 KB Partially correct - number of queries: 6035
58 Partially correct 96 ms 11160 KB Partially correct - number of queries: 6117
59 Partially correct 78 ms 11208 KB Partially correct - number of queries: 5309
60 Partially correct 53 ms 11200 KB Partially correct - number of queries: 5069
61 Correct 40 ms 11240 KB Output is correct
62 Correct 1 ms 200 KB Output is correct
63 Correct 30 ms 11200 KB Output is correct
64 Correct 33 ms 11156 KB Output is correct
65 Correct 2 ms 200 KB Output is correct
66 Correct 1 ms 200 KB Output is correct
67 Correct 1 ms 320 KB Output is correct
68 Correct 1 ms 328 KB Output is correct
69 Correct 1 ms 200 KB Output is correct
70 Correct 1 ms 264 KB Output is correct
71 Partially correct 94 ms 11220 KB Partially correct - number of queries: 7353
72 Correct 43 ms 11208 KB Output is correct
73 Partially correct 91 ms 11208 KB Partially correct - number of queries: 7276
74 Partially correct 76 ms 11204 KB Partially correct - number of queries: 7309
75 Correct 34 ms 11208 KB Output is correct
76 Partially correct 104 ms 11144 KB Partially correct - number of queries: 6561
77 Partially correct 117 ms 11208 KB Partially correct - number of queries: 7402
78 Correct 33 ms 11172 KB Output is correct
79 Correct 62 ms 11208 KB Output is correct
80 Partially correct 61 ms 11208 KB Partially correct - number of queries: 7384
81 Partially correct 103 ms 11208 KB Partially correct - number of queries: 7401
82 Partially correct 78 ms 11232 KB Partially correct - number of queries: 7352
83 Correct 44 ms 11208 KB Output is correct
84 Partially correct 92 ms 11208 KB Partially correct - number of queries: 6434
85 Partially correct 97 ms 11208 KB Partially correct - number of queries: 7396
86 Correct 53 ms 11208 KB Output is correct
87 Correct 49 ms 11208 KB Output is correct
88 Correct 48 ms 11208 KB Output is correct
89 Correct 38 ms 11208 KB Output is correct
90 Correct 1 ms 288 KB Output is correct
91 Correct 52 ms 11200 KB Output is correct
92 Correct 1 ms 200 KB Output is correct
93 Partially correct 52 ms 11208 KB Partially correct - number of queries: 5202
94 Partially correct 79 ms 11248 KB Partially correct - number of queries: 5281
95 Partially correct 60 ms 11252 KB Partially correct - number of queries: 5218
96 Correct 71 ms 11208 KB Output is correct
97 Correct 1 ms 200 KB Output is correct