Submission #699549

# Submission time Handle Problem Language Result Execution time Memory
699549 2023-02-17T10:46:04 Z MasterTaster The Big Prize (IOI17_prize) C++14
100 / 100
59 ms 11684 KB
#include "prize.h"
#include <iostream>
#include <vector>
#include <cmath>
#include <set>

#define ll long long
#define pii pair<int, int>
#define xx first
#define yy second
#define pb push_back
#define MAXN 200010

using namespace std;

int n, l[MAXN], r[MAXN], maxx, ret=-1, sq=480;
vector<int> all;
set<int> s[MAXN];

/*bool check(int i, int k)
{
    vector<int> p=ask(i);
    int le=p[0], ri=p[1];
    if ((le+ri)<maxx) return true;
    if (le>k) return true;
    return false;
}*/

bool vis[MAXN];
void askk(int i)
{
    if (i==-1) return;
    if (i==n) { l[i]=maxx; return; }
    if (!vis[i]) { vector<int> p=ask(i); l[i]=p[0]; r[i]=p[1]; vis[i]=true; }
}
void ch()
{
    askk(all[all.size()-1]);
    if ((l[all[all.size()-1]]+r[all[all.size()-1]])==0) ret=all[all.size()-1];
}

void solve(int left, int right)
{
    //cout<<left<<" "<<right<<endl;
    if (ret!=-1) return;
    int mid=left+(right-left)/2;


    if (left>right) return;
    if (left==right) { askk(mid); s[l[mid]+r[mid]].insert(mid); if ((l[mid]+r[mid])==0) { ret=mid; return; } }
    if (left==(right-1))
    {
        askk(mid);
        s[l[mid]+r[mid]].insert(mid);
        if ((l[mid]+r[mid])==0) { ret=mid; return; }
        mid++;
        askk(mid);
        s[l[mid]+r[mid]].insert(mid);
        if ((l[mid]+r[mid])==0) { ret=mid; return; }
        return;
    }

    askk(mid); if ((l[mid]+r[mid])==0) { ret=mid; return; }
    int cnt=l[mid]+r[mid];
    s[cnt].insert(mid);
    auto it=s[cnt].find(mid);
    //cout<<s[cnt].size()<<endl;
    if (s[cnt].begin()==it || l[*prev(it)]!=l[mid]) { /*cout<<"ee"<<endl;*/ solve(left, mid-1); if (ret!=-1) return; }
    if ((--s[cnt].end())==it || l[*next(it)]!=l[mid]) { /*cout<<"eee"<<endl;*/ solve(mid+1, right); if (ret!=-1) return; }

    /*askk(left-1); askk(right+1);
    int pom;
    if (left==0) pom=0;
    else pom=l[left-1];
    if (l[mid]-pom) solve(left, mid-1);
    if (l[right+1]-l[mid]) solve(mid+1, right);*/
}

int find_best(int N) {
    n=N;
    sq=min(sq, n-1);//2*sqrt(n);
    /*for (int i=0; i<=sq; i++)
    {
        askk(i);
        if (l[i]+r[i]==0) return i;
        maxx=max(maxx, l[i]+r[i]);
    }*/

    int left=0, right=n-1;
    solve(left, right);

    /*int ret=0;
    for (int i=0; i<all.size(); i++) { askk(all[i]); if ((l[all[i]]+r[all[i]])==0) ret=all[i]; }*/
    //cout<<ret<<endl;
    return ret;
}
///1, 2, 5, 26, 677
/*
8
3 2 3 1 3 3 2 3
*/
# Verdict Execution time Memory Grader output
1 Correct 5 ms 9808 KB Output is correct
2 Correct 5 ms 9808 KB Output is correct
3 Correct 5 ms 9808 KB Output is correct
4 Correct 6 ms 9824 KB Output is correct
5 Correct 6 ms 9808 KB Output is correct
6 Correct 5 ms 9708 KB Output is correct
7 Correct 5 ms 9800 KB Output is correct
8 Correct 6 ms 9836 KB Output is correct
9 Correct 6 ms 9712 KB Output is correct
10 Correct 6 ms 9808 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 9704 KB Output is correct
2 Correct 5 ms 9832 KB Output is correct
3 Correct 5 ms 9808 KB Output is correct
4 Correct 7 ms 9832 KB Output is correct
5 Correct 7 ms 9800 KB Output is correct
6 Correct 5 ms 9680 KB Output is correct
7 Correct 7 ms 9844 KB Output is correct
8 Correct 6 ms 9824 KB Output is correct
9 Correct 5 ms 9692 KB Output is correct
10 Correct 5 ms 9808 KB Output is correct
11 Correct 7 ms 10220 KB Output is correct
12 Correct 5 ms 9696 KB Output is correct
13 Correct 11 ms 10836 KB Output is correct
14 Correct 7 ms 9680 KB Output is correct
15 Correct 10 ms 9960 KB Output is correct
16 Correct 45 ms 11256 KB Output is correct
17 Correct 5 ms 9704 KB Output is correct
18 Correct 52 ms 11616 KB Output is correct
19 Correct 5 ms 9680 KB Output is correct
20 Correct 15 ms 10056 KB Output is correct
21 Correct 14 ms 10444 KB Output is correct
22 Correct 8 ms 9832 KB Output is correct
23 Correct 5 ms 9808 KB Output is correct
24 Correct 6 ms 9680 KB Output is correct
25 Correct 34 ms 10708 KB Output is correct
26 Correct 21 ms 10676 KB Output is correct
27 Correct 7 ms 9820 KB Output is correct
28 Correct 45 ms 11516 KB Output is correct
29 Correct 45 ms 11412 KB Output is correct
30 Correct 50 ms 11592 KB Output is correct
31 Correct 5 ms 9708 KB Output is correct
32 Correct 11 ms 10460 KB Output is correct
33 Correct 6 ms 9708 KB Output is correct
34 Correct 19 ms 10372 KB Output is correct
35 Correct 6 ms 10092 KB Output is correct
36 Correct 16 ms 10056 KB Output is correct
37 Correct 7 ms 9836 KB Output is correct
38 Correct 7 ms 9704 KB Output is correct
39 Correct 16 ms 10584 KB Output is correct
40 Correct 34 ms 11508 KB Output is correct
41 Correct 31 ms 10824 KB Output is correct
42 Correct 31 ms 10852 KB Output is correct
43 Correct 30 ms 10720 KB Output is correct
44 Correct 22 ms 10448 KB Output is correct
45 Correct 17 ms 10204 KB Output is correct
46 Correct 5 ms 9684 KB Output is correct
47 Correct 26 ms 10488 KB Output is correct
48 Correct 39 ms 11064 KB Output is correct
49 Correct 9 ms 9832 KB Output is correct
50 Correct 39 ms 11600 KB Output is correct
51 Correct 24 ms 10468 KB Output is correct
52 Correct 7 ms 9696 KB Output is correct
53 Correct 7 ms 10096 KB Output is correct
54 Correct 15 ms 10572 KB Output is correct
55 Correct 5 ms 9704 KB Output is correct
56 Correct 53 ms 11592 KB Output is correct
57 Correct 38 ms 11068 KB Output is correct
58 Correct 31 ms 11108 KB Output is correct
59 Correct 22 ms 10840 KB Output is correct
60 Correct 28 ms 10744 KB Output is correct
61 Correct 6 ms 10188 KB Output is correct
62 Correct 5 ms 9708 KB Output is correct
63 Correct 6 ms 10076 KB Output is correct
64 Correct 6 ms 9960 KB Output is correct
65 Correct 6 ms 9820 KB Output is correct
66 Correct 7 ms 9824 KB Output is correct
67 Correct 7 ms 9820 KB Output is correct
68 Correct 6 ms 9700 KB Output is correct
69 Correct 5 ms 9860 KB Output is correct
70 Correct 5 ms 9816 KB Output is correct
71 Correct 37 ms 11612 KB Output is correct
72 Correct 9 ms 10832 KB Output is correct
73 Correct 31 ms 11684 KB Output is correct
74 Correct 43 ms 11568 KB Output is correct
75 Correct 7 ms 10192 KB Output is correct
76 Correct 50 ms 11556 KB Output is correct
77 Correct 59 ms 11660 KB Output is correct
78 Correct 10 ms 10764 KB Output is correct
79 Correct 27 ms 11524 KB Output is correct
80 Correct 48 ms 11592 KB Output is correct
81 Correct 44 ms 11536 KB Output is correct
82 Correct 48 ms 11592 KB Output is correct
83 Correct 6 ms 10192 KB Output is correct
84 Correct 45 ms 11504 KB Output is correct
85 Correct 45 ms 11584 KB Output is correct
86 Correct 9 ms 10692 KB Output is correct
87 Correct 10 ms 10320 KB Output is correct
88 Correct 9 ms 10572 KB Output is correct
89 Correct 10 ms 10600 KB Output is correct
90 Correct 7 ms 10192 KB Output is correct
91 Correct 8 ms 10320 KB Output is correct
92 Correct 6 ms 9808 KB Output is correct
93 Correct 8 ms 10320 KB Output is correct
94 Correct 8 ms 10484 KB Output is correct
95 Correct 9 ms 10448 KB Output is correct
96 Correct 9 ms 10320 KB Output is correct
97 Correct 6 ms 9808 KB Output is correct