Submission #715837

# Submission time Handle Problem Language Result Execution time Memory
715837 2023-03-28T07:35:29 Z bin9638 The Big Prize (IOI17_prize) C++17
90 / 100
66 ms 336 KB
#include<bits/stdc++.h>

#ifndef SKY
#include "prize.h"
#endif // SKY

using namespace std;
#define N 200010
#define ll long long
#define ii pair<int,int>
#define fs first
#define sc second
#define pb push_back
#define iii pair<int,ii>

int n,lolipop;

#ifdef SKY
int p[N];
vector<int> ask(int i)
{
    cout<<"ask "<<i<<endl;
    vector<int>res(2,0);
    for(int j=0;j<i;j++)
        if(p[j]<p[i])
            res[0]++;
    for(int j=i+1;j<n;j++)
        if(p[j]<p[i])
            res[1]++;
    // cout<<i<<endl;
      //  for(int j=0;j<n;j++)cout<<p[j]<<" ";cout<<endl;
      //  cout<<res[0]<<" "<<res[1]<<endl;
    return res;
}
#endif // SKY

int query=0;

vector<int>myAsk(int i)
{
     query++;
    assert(query<=1e4);
    vector<int>res=ask(i);
    return res;
}

vector<int>lis;

void solve(int l,int r,int left_child,int right_child)
{
    if(l>r)
        return;
    int mid=(l+r)/2;
    for(int i=mid;i<=r;i++)
    {
        vector<int>s=myAsk(i);
        if(s[0]+s[1]!=lolipop)
        {
            lis.pb(i);
        }else
        {
            if(s[0]-left_child!=0)
            {
                solve(l,mid-1,left_child,s[1]);
            }
            if(s[1]-right_child!=0)
            {
                solve(i+1,r,s[0],right_child);
            }
            return;
        }
    }
    for(int i=mid-1;i>=l;i--)
    {
        vector<int>s=myAsk(i);
        if(s[0]+s[1]!=lolipop)
        {
            lis.pb(i);
        }else
        {
            if(s[0]-left_child!=0)
            {
                solve(l,i-1,left_child,s[1]);
            }
        }
    }
}

int find_best(int cc)
{
    n=cc;
    lis.clear();
    if(n<=7)
    {
        for(int i=0;i<n;i++)
        {
            vector<int>s=myAsk(i);
            if(s[0]==0&&s[1]==0)
                return i;
        }
    }
    lolipop=0;
    for(int i=0;i<sqrt(n)*2;i++)
    {
        vector<int>s=myAsk(i);
        lolipop=max(lolipop,s[0]+s[1]);
    }
    solve(0,n-1,0,0);
    for(auto i:lis)
    {
        vector<int>s=myAsk(i);
        if(s[0]==0&&s[1]==0)
            return i;
    }
}

#ifdef SKY
int main()
{
    freopen("A.inp","r",stdin);
    freopen("A.out","w",stdout);
    ios::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
    int n;
    cin>>n;
    for(int i=0;i<n;i++)
        cin>>p[i];
    cout<<find_best(n);
    cout<<endl<<query<<endl;
    return 0;
}
#endif // SKY

Compilation message

prize.cpp: In function 'int find_best(int)':
prize.cpp:115:1: warning: control reaches end of non-void function [-Wreturn-type]
  115 | }
      | ^
# Verdict Execution time Memory Grader output
1 Correct 9 ms 292 KB Output is correct
2 Correct 6 ms 208 KB Output is correct
3 Correct 6 ms 288 KB Output is correct
4 Correct 12 ms 288 KB Output is correct
5 Correct 12 ms 288 KB Output is correct
6 Correct 9 ms 208 KB Output is correct
7 Correct 8 ms 300 KB Output is correct
8 Correct 7 ms 292 KB Output is correct
9 Correct 13 ms 208 KB Output is correct
10 Correct 9 ms 208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 336 KB Output is correct
2 Correct 7 ms 208 KB Output is correct
3 Correct 7 ms 288 KB Output is correct
4 Correct 7 ms 292 KB Output is correct
5 Correct 5 ms 288 KB Output is correct
6 Correct 4 ms 288 KB Output is correct
7 Correct 8 ms 292 KB Output is correct
8 Correct 8 ms 292 KB Output is correct
9 Correct 5 ms 208 KB Output is correct
10 Correct 6 ms 208 KB Output is correct
11 Correct 12 ms 292 KB Output is correct
12 Correct 15 ms 288 KB Output is correct
13 Correct 13 ms 288 KB Output is correct
14 Correct 14 ms 208 KB Output is correct
15 Partially correct 23 ms 336 KB Partially correct - number of queries: 5651
16 Partially correct 66 ms 280 KB Partially correct - number of queries: 6204
17 Partially correct 53 ms 208 KB Partially correct - number of queries: 5818
18 Partially correct 49 ms 208 KB Partially correct - number of queries: 6278
19 Partially correct 38 ms 292 KB Partially correct - number of queries: 5528
20 Correct 31 ms 276 KB Output is correct
21 Partially correct 45 ms 208 KB Partially correct - number of queries: 5953
22 Correct 44 ms 292 KB Output is correct
23 Correct 5 ms 328 KB Output is correct
24 Correct 14 ms 292 KB Output is correct
25 Partially correct 52 ms 288 KB Partially correct - number of queries: 5708
26 Partially correct 62 ms 288 KB Partially correct - number of queries: 5681
27 Correct 10 ms 272 KB Output is correct
28 Partially correct 41 ms 288 KB Partially correct - number of queries: 5821
29 Correct 33 ms 288 KB Output is correct
30 Partially correct 35 ms 292 KB Partially correct - number of queries: 6245
31 Partially correct 47 ms 276 KB Partially correct - number of queries: 5775
32 Correct 12 ms 292 KB Output is correct
33 Correct 1 ms 208 KB Output is correct
34 Partially correct 27 ms 336 KB Partially correct - number of queries: 5946
35 Correct 8 ms 208 KB Output is correct
36 Partially correct 62 ms 280 KB Partially correct - number of queries: 5888
37 Correct 15 ms 208 KB Output is correct
38 Correct 4 ms 292 KB Output is correct
39 Partially correct 60 ms 208 KB Partially correct - number of queries: 5994
40 Partially correct 50 ms 292 KB Partially correct - number of queries: 5541
41 Partially correct 35 ms 284 KB Partially correct - number of queries: 6094
42 Partially correct 48 ms 284 KB Partially correct - number of queries: 6094
43 Partially correct 49 ms 208 KB Partially correct - number of queries: 5918
44 Partially correct 52 ms 208 KB Partially correct - number of queries: 5991
45 Partially correct 44 ms 296 KB Partially correct - number of queries: 5584
46 Partially correct 51 ms 280 KB Partially correct - number of queries: 5808
47 Partially correct 46 ms 284 KB Partially correct - number of queries: 5662
48 Partially correct 54 ms 208 KB Partially correct - number of queries: 6145
49 Partially correct 29 ms 288 KB Partially correct - number of queries: 5847
50 Partially correct 38 ms 208 KB Partially correct - number of queries: 6291
51 Partially correct 50 ms 208 KB Partially correct - number of queries: 6002
52 Partially correct 50 ms 296 KB Partially correct - number of queries: 5827
53 Correct 8 ms 208 KB Output is correct
54 Partially correct 63 ms 292 KB Partially correct - number of queries: 5965
55 Partially correct 46 ms 284 KB Partially correct - number of queries: 5815
56 Partially correct 25 ms 288 KB Partially correct - number of queries: 6285
57 Partially correct 25 ms 292 KB Partially correct - number of queries: 6112
58 Partially correct 51 ms 276 KB Partially correct - number of queries: 6149
59 Partially correct 46 ms 288 KB Partially correct - number of queries: 6095
60 Partially correct 51 ms 280 KB Partially correct - number of queries: 6018
61 Correct 5 ms 292 KB Output is correct
62 Correct 9 ms 208 KB Output is correct
63 Correct 12 ms 208 KB Output is correct
64 Correct 6 ms 208 KB Output is correct
65 Correct 10 ms 208 KB Output is correct
66 Correct 25 ms 288 KB Output is correct
67 Correct 15 ms 328 KB Output is correct
68 Correct 10 ms 288 KB Output is correct
69 Correct 17 ms 208 KB Output is correct
70 Correct 13 ms 292 KB Output is correct
71 Partially correct 40 ms 280 KB Partially correct - number of queries: 6125
72 Correct 13 ms 208 KB Output is correct
73 Partially correct 61 ms 280 KB Partially correct - number of queries: 6055
74 Partially correct 61 ms 208 KB Partially correct - number of queries: 6085
75 Correct 7 ms 208 KB Output is correct
76 Partially correct 51 ms 208 KB Partially correct - number of queries: 5405
77 Partially correct 64 ms 208 KB Partially correct - number of queries: 6360
78 Correct 13 ms 296 KB Output is correct
79 Correct 17 ms 296 KB Output is correct
80 Partially correct 42 ms 208 KB Partially correct - number of queries: 6374
81 Partially correct 66 ms 288 KB Partially correct - number of queries: 6345
82 Partially correct 63 ms 208 KB Partially correct - number of queries: 6328
83 Correct 11 ms 296 KB Output is correct
84 Partially correct 52 ms 208 KB Partially correct - number of queries: 5453
85 Partially correct 53 ms 280 KB Partially correct - number of queries: 6352
86 Correct 16 ms 292 KB Output is correct
87 Correct 5 ms 288 KB Output is correct
88 Correct 18 ms 292 KB Output is correct
89 Correct 20 ms 208 KB Output is correct
90 Correct 10 ms 240 KB Output is correct
91 Correct 8 ms 288 KB Output is correct
92 Correct 22 ms 280 KB Output is correct
93 Correct 27 ms 208 KB Output is correct
94 Correct 23 ms 304 KB Output is correct
95 Correct 18 ms 280 KB Output is correct
96 Correct 17 ms 208 KB Output is correct
97 Correct 16 ms 208 KB Output is correct