Submission #1062488

# Submission time Handle Problem Language Result Execution time Memory
1062488 2024-08-17T07:53:40 Z Faisal_Saqib The Big Prize (IOI17_prize) C++17
90 / 100
67 ms 1504 KB
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define vll vector<ll>
#define all(x) begin(x),end(x)
#define pb push_back

std::vector<int> ask(int i);
map<int,vector<int>> mp;
vector<int> ask1(int i)
{
    if(mp.find(i)!=mp.end())return mp[i];
    return mp[i]=ask(i);
}
int find_best(int n)
{
    int ans=-1;
    int i=0;
    auto it1=ask1(0);
    while(1)
    {
        // cout<<"Starting from "<<i<<endl;
        int s=i,e=n;
        auto lasp=it1;
        if(lasp[0]==0 and lasp[1]==0)
            return i;
        while(s+1<e){
            int mid=(s+e)/2;
            auto it=ask1(mid);
            // cout<<"Checking "<<mid<<endl;
            // cout<<it1[0]<<' '<<it1[1]<<endl;
            // cout<<it[0]<<' '<<it[1]<<endl;
            if((it1[0]==it[0] and it1[1]==it[1]))
            {
                s=mid;
            }
            else{
                int cur_sum=it[0]+it[1];
                int back_sum=it1[0]+it1[1];
                // We want to know if there is any element greater than i in the [i,mid]
                if(back_sum<cur_sum)
                {
                    // it is smaller than current element
                    // can't  solve from here
                    // ll rp=rand()%2;
                    // if(rp)
                    // s=mid;
                    // Recursively call for both side
                    // or maybe stop binary search
                    e=i+1;
                    lasp=ask1(i+1);
                    break;
                }
                else{
                    e=mid;
                    lasp=it;                    
                }
            }
            // if((it[0]+it[1])!=((it1[0]+it1[1])))
            // {
            //     e=mid;
            // }
            // else{
            //     // if max(a1,a2,a3,..,an) <= k  
            //     // if this is the case
            //     // then it1[1]==it[1]
            //     // also it1[0]==it[0]
            //     s=mid;

            // }
        }
        // cout<<"Solved for "<<i<<' '<<s<<' '<<e<<endl;
        if(e==n)
        {
            break;
        }
        i=e;
        it1=lasp;
    }
    return i;
}

Compilation message

prize.cpp: In function 'int find_best(int)':
prize.cpp:18:9: warning: unused variable 'ans' [-Wunused-variable]
   18 |     int ans=-1;
      |         ^~~
# 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 0 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 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
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 1 ms 428 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 428 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 2 ms 464 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 3 ms 468 KB Output is correct
14 Correct 2 ms 344 KB Output is correct
15 Correct 6 ms 544 KB Output is correct
16 Partially correct 28 ms 1148 KB Partially correct - number of queries: 6977
17 Correct 0 ms 344 KB Output is correct
18 Partially correct 55 ms 1160 KB Partially correct - number of queries: 8143
19 Correct 0 ms 344 KB Output is correct
20 Correct 13 ms 600 KB Output is correct
21 Correct 18 ms 596 KB Output is correct
22 Correct 3 ms 344 KB Output is correct
23 Correct 0 ms 344 KB Output is correct
24 Correct 0 ms 344 KB Output is correct
25 Correct 15 ms 848 KB Output is correct
26 Correct 25 ms 740 KB Output is correct
27 Correct 1 ms 344 KB Output is correct
28 Partially correct 46 ms 1104 KB Partially correct - number of queries: 7637
29 Partially correct 44 ms 1104 KB Partially correct - number of queries: 5817
30 Partially correct 57 ms 1244 KB Partially correct - number of queries: 8215
31 Correct 0 ms 344 KB Output is correct
32 Correct 2 ms 344 KB Output is correct
33 Correct 0 ms 340 KB Output is correct
34 Correct 12 ms 600 KB Output is correct
35 Correct 1 ms 344 KB Output is correct
36 Correct 11 ms 524 KB Output is correct
37 Correct 1 ms 344 KB Output is correct
38 Correct 0 ms 344 KB Output is correct
39 Correct 16 ms 824 KB Output is correct
40 Partially correct 54 ms 1360 KB Partially correct - number of queries: 6969
41 Correct 33 ms 760 KB Output is correct
42 Correct 23 ms 848 KB Output is correct
43 Correct 27 ms 696 KB Output is correct
44 Correct 19 ms 900 KB Output is correct
45 Correct 13 ms 692 KB Output is correct
46 Correct 0 ms 344 KB Output is correct
47 Correct 24 ms 844 KB Output is correct
48 Partially correct 30 ms 848 KB Partially correct - number of queries: 6045
49 Correct 3 ms 340 KB Output is correct
50 Partially correct 67 ms 1232 KB Partially correct - number of queries: 8163
51 Correct 24 ms 844 KB Output is correct
52 Correct 1 ms 344 KB Output is correct
53 Correct 1 ms 344 KB Output is correct
54 Correct 22 ms 600 KB Output is correct
55 Correct 1 ms 344 KB Output is correct
56 Partially correct 49 ms 1504 KB Partially correct - number of queries: 8157
57 Partially correct 31 ms 1176 KB Partially correct - number of queries: 5936
58 Partially correct 38 ms 968 KB Partially correct - number of queries: 6001
59 Correct 22 ms 1076 KB Output is correct
60 Correct 29 ms 768 KB Output is correct
61 Correct 1 ms 436 KB Output is correct
62 Correct 1 ms 424 KB Output is correct
63 Correct 1 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 0 ms 344 KB Output is correct
67 Correct 1 ms 344 KB Output is correct
68 Correct 3 ms 344 KB Output is correct
69 Correct 1 ms 432 KB Output is correct
70 Correct 1 ms 344 KB Output is correct
71 Partially correct 48 ms 1300 KB Partially correct - number of queries: 7957
72 Correct 4 ms 468 KB Output is correct
73 Partially correct 57 ms 1140 KB Partially correct - number of queries: 7877
74 Partially correct 46 ms 1140 KB Partially correct - number of queries: 7936
75 Correct 1 ms 344 KB Output is correct
76 Partially correct 37 ms 1104 KB Partially correct - number of queries: 6829
77 Partially correct 49 ms 1196 KB Partially correct - number of queries: 8144
78 Correct 3 ms 344 KB Output is correct
79 Correct 26 ms 948 KB Output is correct
80 Partially correct 41 ms 1244 KB Partially correct - number of queries: 8152
81 Partially correct 38 ms 1364 KB Partially correct - number of queries: 8168
82 Partially correct 39 ms 1244 KB Partially correct - number of queries: 8096
83 Correct 1 ms 340 KB Output is correct
84 Partially correct 42 ms 1136 KB Partially correct - number of queries: 6688
85 Partially correct 39 ms 1364 KB Partially correct - number of queries: 8130
86 Correct 18 ms 600 KB Output is correct
87 Correct 3 ms 344 KB Output is correct
88 Correct 17 ms 756 KB Output is correct
89 Correct 23 ms 848 KB Output is correct
90 Correct 1 ms 344 KB Output is correct
91 Correct 10 ms 588 KB Output is correct
92 Correct 5 ms 492 KB Output is correct
93 Correct 3 ms 344 KB Output is correct
94 Correct 3 ms 468 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