답안 #52412

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
52412 2018-06-25T22:20:14 Z Kubalionzzale 커다란 상품 (IOI17_prize) C++14
90 / 100
67 ms 888 KB
#include "prize.h"

#include <algorithm>
#include <set>
#include <map>

std::map<int, int> mapa;
//first - sum
//second - left

int find_best(int n) {

    if (n <= 500)
    {
        std::vector<int> get;
        for (int i = 0; i < n; ++i)
        {
            get = ask(i);

            if (get[0] == 0 && get[1] == 0)
            {
                return i;
            }
        }
    }


    int max = 0;
    std::vector<int> get;
    std::map<int, std::pair<int, int> > askedBig;
    for (int i = 0; i < 500; ++i)
    {
        get = ask(i);
        if (get[0] + get[1] > max)
        {
            max = get[0] + get[1];
        }
        if (get[0] == 0 && get[1] == 0)
        {
            return i;
        }

        int sum = get[0] + get[1];
        if (mapa.find(sum) == mapa.end())
        {
            mapa.insert(std::make_pair(sum, 0));
        }
        else
        {
            mapa[sum] = get[0];
        }
    }

    int cur = 499;
    while (1)
    {

        if (askedBig.find(cur) != askedBig.end())
        {
            get[0] = askedBig[cur].first;
            get[1] = askedBig[cur].second;
        }
        else
        {
            get = ask(cur);
            askedBig.insert(std::make_pair(cur, std::make_pair(get[0], get[1])));
        }

        if (get[0] == 0 && get[1] == 0)
        {
            return cur;
        }


        int s = get[0] + get[1];
        while (1 && s != max)
        {
            if (askedBig.find(cur + 1) != askedBig.end())
            {
                get[0] = askedBig[cur + 1].first;
                get[1] = askedBig[cur + 1].second;
            }
            else
            {
                get = ask(cur + 1);
                askedBig.insert(std::make_pair(cur + 1, std::make_pair(get[0], get[1])));
            }

            int inner = get[0] + get[1];
            if (inner == 0)
            {
                return cur + 1;
            }
            else if (inner != max)
            {
                mapa[inner] = get[0];
                ++cur;
            }
            else
            {
                mapa[inner] = get[0];
                break;
            }
        }

        int curs = 1 << 9;
        curs = std::min(n - 1, curs + cur);
        if (askedBig.find(curs) != askedBig.end())
        {
            get[0] = askedBig[curs].first;
            get[1] = askedBig[curs].second;
        }
        else
        {
            get = ask(curs);
            askedBig.insert(std::make_pair(curs, std::make_pair(get[0], get[1])));
        }

        int sum = get[0] + get[1];

        if (get[0] == 0 && get[1] == 0)
        {
            return curs;
        }

        bool flag2 = false;
        if (mapa.find(sum) == mapa.end())
            flag2 = true;
        if (get[0] > mapa[sum])
            flag2 = true;

        if (get[0] == 0 && sum != max)
        {
            mapa.insert(std::make_pair(sum, 0));

            cur = curs;
        }
        else if (get[0] == mapa[sum] && sum != max)
        {
            cur = curs;
        }
        else if (mapa.find(sum) == mapa.end())
        {
            flag2 = true;
        }
        else if (get[0] > mapa[sum])
        {
            flag2 = true;
        }
        else
        {
            cur = curs;
        }

        bool flag = false;
        for (int i = 8; i >= 0 && flag2; --i)
        {
            int nr = 1 << i;
            int toAsk = std::min(cur + nr, n - 1);

            if (askedBig.find(toAsk) != askedBig.end())
            {
                get[0] = askedBig[toAsk].first;
                get[1] = askedBig[toAsk].second;
            }
            else
            {
                get = ask(toAsk);
                askedBig.insert(std::make_pair(toAsk, std::make_pair(get[0], get[1])));
            }


            int sum = get[0] + get[1];

            if (get[0] == 0 && get[1] == 0)
            {
                return toAsk;
            }

            if (get[0] == 0 && sum != max)
            {
                mapa.insert(std::make_pair(sum, 0));

                cur = toAsk;
                flag = true;
                break;
            }
            else if (mapa.find(sum) == mapa.end())
            {
                continue;
            }
            else if (get[0] > mapa[sum])
            {
                continue;
            }
            else if (get[0] == mapa[sum] && sum != max)
            {
                cur = toAsk;
                flag = true;
                break;
            }
            else
            {
                cur = toAsk;
            }
        }

        if (!flag)
            ++cur;
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 248 KB Output is correct
2 Correct 5 ms 380 KB Output is correct
3 Correct 8 ms 512 KB Output is correct
4 Correct 10 ms 512 KB Output is correct
5 Correct 6 ms 512 KB Output is correct
6 Correct 2 ms 512 KB Output is correct
7 Correct 10 ms 520 KB Output is correct
8 Correct 8 ms 520 KB Output is correct
9 Correct 9 ms 524 KB Output is correct
10 Correct 13 ms 524 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 548 KB Output is correct
2 Correct 10 ms 552 KB Output is correct
3 Correct 11 ms 568 KB Output is correct
4 Correct 12 ms 572 KB Output is correct
5 Correct 10 ms 572 KB Output is correct
6 Correct 2 ms 572 KB Output is correct
7 Correct 11 ms 572 KB Output is correct
8 Correct 9 ms 572 KB Output is correct
9 Correct 7 ms 572 KB Output is correct
10 Correct 10 ms 576 KB Output is correct
11 Correct 5 ms 576 KB Output is correct
12 Correct 6 ms 576 KB Output is correct
13 Correct 8 ms 640 KB Output is correct
14 Correct 7 ms 640 KB Output is correct
15 Correct 13 ms 700 KB Output is correct
16 Correct 34 ms 756 KB Output is correct
17 Correct 5 ms 756 KB Output is correct
18 Partially correct 62 ms 812 KB Partially correct - number of queries: 5492
19 Correct 5 ms 812 KB Output is correct
20 Correct 14 ms 812 KB Output is correct
21 Correct 19 ms 812 KB Output is correct
22 Correct 8 ms 812 KB Output is correct
23 Correct 5 ms 812 KB Output is correct
24 Correct 5 ms 812 KB Output is correct
25 Correct 31 ms 812 KB Output is correct
26 Correct 28 ms 812 KB Output is correct
27 Correct 4 ms 812 KB Output is correct
28 Partially correct 45 ms 828 KB Partially correct - number of queries: 5503
29 Correct 37 ms 828 KB Output is correct
30 Partially correct 46 ms 828 KB Partially correct - number of queries: 5514
31 Correct 4 ms 828 KB Output is correct
32 Correct 12 ms 828 KB Output is correct
33 Correct 1 ms 828 KB Output is correct
34 Correct 13 ms 828 KB Output is correct
35 Correct 8 ms 828 KB Output is correct
36 Correct 13 ms 828 KB Output is correct
37 Correct 4 ms 828 KB Output is correct
38 Correct 5 ms 828 KB Output is correct
39 Correct 24 ms 828 KB Output is correct
40 Correct 36 ms 828 KB Output is correct
41 Correct 26 ms 828 KB Output is correct
42 Correct 26 ms 828 KB Output is correct
43 Correct 32 ms 828 KB Output is correct
44 Correct 14 ms 828 KB Output is correct
45 Correct 14 ms 828 KB Output is correct
46 Correct 3 ms 828 KB Output is correct
47 Correct 24 ms 828 KB Output is correct
48 Correct 32 ms 832 KB Output is correct
49 Correct 7 ms 832 KB Output is correct
50 Partially correct 53 ms 832 KB Partially correct - number of queries: 5419
51 Correct 29 ms 832 KB Output is correct
52 Correct 7 ms 832 KB Output is correct
53 Correct 15 ms 832 KB Output is correct
54 Correct 31 ms 832 KB Output is correct
55 Correct 7 ms 832 KB Output is correct
56 Partially correct 67 ms 832 KB Partially correct - number of queries: 5486
57 Correct 40 ms 832 KB Output is correct
58 Correct 35 ms 848 KB Output is correct
59 Correct 23 ms 848 KB Output is correct
60 Correct 14 ms 848 KB Output is correct
61 Correct 15 ms 848 KB Output is correct
62 Correct 7 ms 848 KB Output is correct
63 Correct 15 ms 848 KB Output is correct
64 Correct 12 ms 848 KB Output is correct
65 Correct 7 ms 848 KB Output is correct
66 Correct 19 ms 848 KB Output is correct
67 Correct 16 ms 848 KB Output is correct
68 Correct 5 ms 848 KB Output is correct
69 Correct 15 ms 848 KB Output is correct
70 Correct 13 ms 848 KB Output is correct
71 Partially correct 43 ms 848 KB Partially correct - number of queries: 5221
72 Correct 11 ms 848 KB Output is correct
73 Partially correct 49 ms 848 KB Partially correct - number of queries: 5151
74 Partially correct 45 ms 848 KB Partially correct - number of queries: 5181
75 Correct 13 ms 848 KB Output is correct
76 Correct 38 ms 848 KB Output is correct
77 Partially correct 41 ms 848 KB Partially correct - number of queries: 5431
78 Correct 13 ms 848 KB Output is correct
79 Correct 20 ms 848 KB Output is correct
80 Partially correct 46 ms 888 KB Partially correct - number of queries: 6255
81 Partially correct 48 ms 888 KB Partially correct - number of queries: 5399
82 Partially correct 59 ms 888 KB Partially correct - number of queries: 5323
83 Correct 9 ms 888 KB Output is correct
84 Correct 35 ms 888 KB Output is correct
85 Partially correct 31 ms 888 KB Partially correct - number of queries: 5384
86 Correct 15 ms 888 KB Output is correct
87 Correct 6 ms 888 KB Output is correct
88 Correct 12 ms 888 KB Output is correct
89 Correct 10 ms 888 KB Output is correct
90 Correct 11 ms 888 KB Output is correct
91 Correct 7 ms 888 KB Output is correct
92 Correct 10 ms 888 KB Output is correct
93 Correct 13 ms 888 KB Output is correct
94 Correct 7 ms 888 KB Output is correct
95 Correct 10 ms 888 KB Output is correct
96 Correct 11 ms 888 KB Output is correct
97 Correct 13 ms 888 KB Output is correct