Submission #906074

# Submission time Handle Problem Language Result Execution time Memory
906074 2024-01-13T13:24:38 Z nightfal The Big Prize (IOI17_prize) C++14
100 / 100
25 ms 600 KB
//#include "prize.h"
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

static const int max_q = 10000;
static int n;
static int query_count = 0;
static vector<int> g;
static vector<vector<int> > rank_count;

int find_best(int n);
std::vector<int> ask(int i);

int subtask1(int n){
    int start=0, end=n-1;
    while (start<end) {
        int mid = (start+end)/2;
        vector<int> ans = ask(mid);
        if (!ans[0] && !ans[1]) return mid;
        else if (!ans[0]) start=mid+1;
        else end = mid-1;
    }
    return start;
}

int bSearch97(int start, int end, std::vector<int> sAns, std::vector<int> eAns, int maxVal) {

    if (sAns[0]+sAns[1]==0) return start;
    if (eAns[0]+eAns[1]==0) return end;
    
    while(start + 1 < end && sAns[0]+sAns[1]!=maxVal) {
        sAns = ask(++start); 
        if (sAns[0]+sAns[1]==0) return start;
    }
    while(start + 1 < end && eAns[0]+eAns[1]!=maxVal) {
        eAns = ask(--end);
        if (eAns[0]+eAns[1]==0) return end;
    }

    if(start+1==end || sAns[0]==eAns[0]) return -1;

    int mid=(start+end+1)/2;
    vector<int> midAns = ask(mid);
    int result = bSearch97(start,mid,sAns,midAns,maxVal);
    if (result != -1) return result;
    return bSearch97(mid,end,midAns,eAns,maxVal);
}

int score97(int n) {
    int m = min(500,n), maxVal=0;
    vector<int> ans;
	for(int i=0; i<m; i++) {
        ans = ask(i);
        int sum = ans[0]+ans[1];
        if(sum==0) return i;
        if (maxVal<sum) maxVal=sum;
    }
	return bSearch97(0,n-1,ask(0),ask(n-1),maxVal);
}

int bSearch(int start, int end, std::vector<int> sAns, std::vector<int> eAns) {

    if (sAns[0]+sAns[1]==0) return start;
    if (eAns[0]+eAns[1]==0) return end;
    
    while(start + 1 < end && sAns[0]+sAns[1]!=eAns[0]+eAns[1]) {
        if (sAns[0]+sAns[1] < eAns[0]+eAns[1]) {
            sAns = ask(++start); 
            if (sAns[0]+sAns[1]==0) return start;
        }
        else {
            eAns = ask(--end);
            if (eAns[0]+eAns[1]==0) return end;
        }
    }
    if(start+1==end || sAns[0]==eAns[0]) return -1;

    int mid=(start+end+1)/2;
    vector<int> midAns = ask(mid);
    int result = bSearch(start,mid,sAns,midAns);
    if (result != -1) return result;
    return bSearch(mid,end,midAns,eAns);
}

int fulltask(int n) { 
	return bSearch(0,n-1,ask(0),ask(n-1));
}

int find_best(int n) {
    return fulltask(n);
    // return score97(n);
}

Compilation message

prize.cpp:10:12: warning: 'query_count' defined but not used [-Wunused-variable]
   10 | static int query_count = 0;
      |            ^~~~~~~~~~~
prize.cpp:9:12: warning: 'n' defined but not used [-Wunused-variable]
    9 | static int n;
      |            ^
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 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 1 ms 340 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 436 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 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 1 ms 344 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 2 ms 344 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 2 ms 344 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 3 ms 344 KB Output is correct
16 Correct 14 ms 344 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 20 ms 428 KB Output is correct
19 Correct 1 ms 344 KB Output is correct
20 Correct 6 ms 344 KB Output is correct
21 Correct 8 ms 344 KB Output is correct
22 Correct 2 ms 344 KB Output is correct
23 Correct 1 ms 344 KB Output is correct
24 Correct 1 ms 432 KB Output is correct
25 Correct 10 ms 344 KB Output is correct
26 Correct 10 ms 344 KB Output is correct
27 Correct 1 ms 344 KB Output is correct
28 Correct 15 ms 340 KB Output is correct
29 Correct 13 ms 344 KB Output is correct
30 Correct 20 ms 344 KB Output is correct
31 Correct 1 ms 344 KB Output is correct
32 Correct 2 ms 344 KB Output is correct
33 Correct 1 ms 344 KB Output is correct
34 Correct 7 ms 344 KB Output is correct
35 Correct 1 ms 344 KB Output is correct
36 Correct 4 ms 344 KB Output is correct
37 Correct 1 ms 344 KB Output is correct
38 Correct 1 ms 344 KB Output is correct
39 Correct 8 ms 344 KB Output is correct
40 Correct 19 ms 344 KB Output is correct
41 Correct 11 ms 436 KB Output is correct
42 Correct 11 ms 344 KB Output is correct
43 Correct 11 ms 600 KB Output is correct
44 Correct 9 ms 344 KB Output is correct
45 Correct 6 ms 344 KB Output is correct
46 Correct 1 ms 344 KB Output is correct
47 Correct 9 ms 344 KB Output is correct
48 Correct 15 ms 432 KB Output is correct
49 Correct 2 ms 344 KB Output is correct
50 Correct 21 ms 344 KB Output is correct
51 Correct 8 ms 344 KB Output is correct
52 Correct 1 ms 432 KB Output is correct
53 Correct 1 ms 436 KB Output is correct
54 Correct 10 ms 432 KB Output is correct
55 Correct 1 ms 344 KB Output is correct
56 Correct 22 ms 344 KB Output is correct
57 Correct 16 ms 344 KB Output is correct
58 Correct 14 ms 344 KB Output is correct
59 Correct 14 ms 340 KB Output is correct
60 Correct 13 ms 344 KB Output is correct
61 Correct 1 ms 340 KB Output is correct
62 Correct 1 ms 344 KB Output is correct
63 Correct 3 ms 344 KB Output is correct
64 Correct 1 ms 344 KB Output is correct
65 Correct 1 ms 344 KB Output is correct
66 Correct 1 ms 344 KB Output is correct
67 Correct 3 ms 344 KB Output is correct
68 Correct 2 ms 344 KB Output is correct
69 Correct 1 ms 344 KB Output is correct
70 Correct 2 ms 344 KB Output is correct
71 Correct 19 ms 436 KB Output is correct
72 Correct 2 ms 436 KB Output is correct
73 Correct 25 ms 344 KB Output is correct
74 Correct 21 ms 344 KB Output is correct
75 Correct 1 ms 344 KB Output is correct
76 Correct 18 ms 344 KB Output is correct
77 Correct 23 ms 344 KB Output is correct
78 Correct 3 ms 344 KB Output is correct
79 Correct 17 ms 344 KB Output is correct
80 Correct 19 ms 344 KB Output is correct
81 Correct 20 ms 344 KB Output is correct
82 Correct 20 ms 344 KB Output is correct
83 Correct 1 ms 344 KB Output is correct
84 Correct 18 ms 496 KB Output is correct
85 Correct 23 ms 344 KB Output is correct
86 Correct 2 ms 344 KB Output is correct
87 Correct 1 ms 344 KB Output is correct
88 Correct 2 ms 344 KB Output is correct
89 Correct 2 ms 344 KB Output is correct
90 Correct 1 ms 344 KB Output is correct
91 Correct 1 ms 436 KB Output is correct
92 Correct 1 ms 344 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