답안 #290354

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
290354 2020-09-03T16:17:29 Z A02 커다란 상품 (IOI17_prize) C++14
100 / 100
97 ms 11364 KB
#include <bits/stdc++.h>
#include "prize.h"

using namespace std;

vector<vector<int> > asked;

vector<int> ask2(int i){

    if (asked[i][0] == -1){
        asked[i] = ask(i);
    }

    return asked[i];

}

int find_best(int n) {

    asked = vector<vector<int> > (n, vector<int> (2, -1));

//	if (n <= 5000){
//        for (int i = 0; i < n; i++){
//            vector<int> r = ask(i);
//            if (r[0] == 0 && r[1] == 0){
//                return i;
//            }
//        }
//	}

    int small_count = 0;

    for (int i = 0; i < 500; i++){
        int low = 0;
        int high = n;
        for (int a = 0; a < 9; a++){
            small_count = max(small_count, ask2((low + high) / 2)[0] + ask2((low + high) / 2)[1]);
            if (i & (1 << a)){
                low = (low + high) / 2;
            } else {
                high = (low + high) / 2;
            }
        }
    }

    //vector<int> small_pos (small_count, -1);
    //cout << small_count << endl;

    for (int p = 0; p < small_count; p++){
        //cout << endl;
        //cout << 'p' << ' ' << p << endl;
        int low = 0;
        int high = n;
        int left_elements = 0;
        //pth small element in [0, n).

        while (high != low + 1){
            int mid = (low + high) / 2;
            //cout << low << ' ' << high << ' ' << left_elements << endl;
            while(ask2(mid)[0] + ask2(mid)[1] != small_count && mid - 1 >= low){
                mid--;
            }

            int m_original = (low + high) / 2;
            if (m_original != mid){
                //cout << 'a' << endl;
                if (ask2(mid)[0] + ask2(mid)[1] != small_count){
                    //cout << 'b' << endl;
                    int width = m_original - mid;
                    if (p < left_elements + width){
                        high = m_original;
                    } else {
                        low = m_original;
                        left_elements += width;
                    }
                } else {
                    //cout << 'c' << endl;
                    //cout << mid << ' ' << m_original << endl;
                    int extra = m_original - mid;
                    int left_of_mid_elements = ask2(mid)[0] + extra - 1;
                    //cout << ' ' << left_of_mid_elements << endl;
                    if (left_of_mid_elements > p){
                        high = m_original;
                    } else {
                        low = m_original;
                        left_elements = left_of_mid_elements;
                    }
                }
            } else {
                int left_of_mid_elements = ask2(mid)[0];
                if (left_of_mid_elements > p){
                    high = mid;
                } else {
                    low = mid;
                    left_elements = left_of_mid_elements;
                }
            }

        }

        //small_pos[p] = low;
        //cout << p << ' ' << low << endl;
        if (ask2(low)[0] + ask2(low)[1] == 0){
            return low;
        }

    }

  return 0;

}
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 11256 KB Output is correct
2 Correct 18 ms 11264 KB Output is correct
3 Correct 19 ms 11256 KB Output is correct
4 Correct 23 ms 11260 KB Output is correct
5 Correct 21 ms 11264 KB Output is correct
6 Correct 22 ms 11264 KB Output is correct
7 Correct 48 ms 11264 KB Output is correct
8 Correct 22 ms 11256 KB Output is correct
9 Correct 21 ms 11256 KB Output is correct
10 Correct 20 ms 11264 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 38 ms 11256 KB Output is correct
2 Correct 21 ms 11264 KB Output is correct
3 Correct 22 ms 11256 KB Output is correct
4 Correct 19 ms 11264 KB Output is correct
5 Correct 19 ms 11256 KB Output is correct
6 Correct 23 ms 11268 KB Output is correct
7 Correct 27 ms 11264 KB Output is correct
8 Correct 21 ms 11264 KB Output is correct
9 Correct 19 ms 11264 KB Output is correct
10 Correct 33 ms 11256 KB Output is correct
11 Correct 23 ms 11264 KB Output is correct
12 Correct 19 ms 11264 KB Output is correct
13 Correct 27 ms 11256 KB Output is correct
14 Correct 7 ms 1512 KB Output is correct
15 Correct 26 ms 11256 KB Output is correct
16 Correct 63 ms 11256 KB Output is correct
17 Correct 19 ms 11256 KB Output is correct
18 Correct 63 ms 11264 KB Output is correct
19 Correct 17 ms 11240 KB Output is correct
20 Correct 22 ms 5760 KB Output is correct
21 Correct 39 ms 11264 KB Output is correct
22 Correct 20 ms 11296 KB Output is correct
23 Correct 20 ms 11256 KB Output is correct
24 Correct 34 ms 11264 KB Output is correct
25 Correct 46 ms 11264 KB Output is correct
26 Correct 43 ms 11264 KB Output is correct
27 Correct 24 ms 11256 KB Output is correct
28 Correct 54 ms 11264 KB Output is correct
29 Correct 47 ms 11256 KB Output is correct
30 Correct 55 ms 11264 KB Output is correct
31 Correct 22 ms 11256 KB Output is correct
32 Correct 23 ms 11260 KB Output is correct
33 Correct 2 ms 256 KB Output is correct
34 Correct 30 ms 11264 KB Output is correct
35 Correct 19 ms 11264 KB Output is correct
36 Correct 34 ms 11264 KB Output is correct
37 Correct 22 ms 11264 KB Output is correct
38 Correct 21 ms 11264 KB Output is correct
39 Correct 47 ms 11364 KB Output is correct
40 Correct 66 ms 11264 KB Output is correct
41 Correct 51 ms 11264 KB Output is correct
42 Correct 50 ms 11264 KB Output is correct
43 Correct 46 ms 11264 KB Output is correct
44 Correct 43 ms 11264 KB Output is correct
45 Correct 25 ms 11256 KB Output is correct
46 Correct 20 ms 11264 KB Output is correct
47 Correct 44 ms 11256 KB Output is correct
48 Correct 48 ms 11256 KB Output is correct
49 Correct 21 ms 11256 KB Output is correct
50 Correct 65 ms 11264 KB Output is correct
51 Correct 53 ms 11256 KB Output is correct
52 Correct 20 ms 11264 KB Output is correct
53 Correct 20 ms 11264 KB Output is correct
54 Correct 41 ms 11256 KB Output is correct
55 Correct 20 ms 11256 KB Output is correct
56 Correct 54 ms 11264 KB Output is correct
57 Correct 47 ms 11264 KB Output is correct
58 Correct 51 ms 11256 KB Output is correct
59 Correct 52 ms 11264 KB Output is correct
60 Correct 40 ms 11296 KB Output is correct
61 Correct 24 ms 11256 KB Output is correct
62 Correct 21 ms 11248 KB Output is correct
63 Correct 19 ms 11264 KB Output is correct
64 Correct 22 ms 11264 KB Output is correct
65 Correct 20 ms 11256 KB Output is correct
66 Correct 39 ms 11256 KB Output is correct
67 Correct 20 ms 11264 KB Output is correct
68 Correct 44 ms 11264 KB Output is correct
69 Correct 36 ms 11256 KB Output is correct
70 Correct 22 ms 11256 KB Output is correct
71 Correct 79 ms 11264 KB Output is correct
72 Correct 22 ms 11264 KB Output is correct
73 Correct 69 ms 11264 KB Output is correct
74 Correct 79 ms 11256 KB Output is correct
75 Correct 22 ms 11264 KB Output is correct
76 Correct 51 ms 11264 KB Output is correct
77 Correct 65 ms 11264 KB Output is correct
78 Correct 23 ms 11264 KB Output is correct
79 Correct 42 ms 11236 KB Output is correct
80 Correct 73 ms 11264 KB Output is correct
81 Correct 60 ms 11264 KB Output is correct
82 Correct 97 ms 11264 KB Output is correct
83 Correct 22 ms 11264 KB Output is correct
84 Correct 50 ms 11264 KB Output is correct
85 Correct 79 ms 11264 KB Output is correct
86 Correct 59 ms 11264 KB Output is correct
87 Correct 25 ms 11264 KB Output is correct
88 Correct 58 ms 11264 KB Output is correct
89 Correct 59 ms 11264 KB Output is correct
90 Correct 22 ms 11264 KB Output is correct
91 Correct 28 ms 11264 KB Output is correct
92 Correct 70 ms 11264 KB Output is correct
93 Correct 66 ms 11264 KB Output is correct
94 Correct 72 ms 11264 KB Output is correct
95 Correct 89 ms 11264 KB Output is correct
96 Correct 77 ms 11264 KB Output is correct
97 Correct 70 ms 11264 KB Output is correct