Submission #766824

# Submission time Handle Problem Language Result Execution time Memory
766824 2023-06-26T07:48:27 Z danikoynov The Big Prize (IOI17_prize) C++14
96.2 / 100
52 ms 1908 KB
#include "prize.h"
#include<bits/stdc++.h>
using namespace std;
map < int, vector < int > > mp;
map < int, int > used;
int cnt = 0;
vector < int > local_ask(int idx)
{
    if (used[idx])
        return mp[idx];
    cnt ++;
    //if (cnt == 1e4)
    //  while(true);
    used[idx] = 1;
    mp[idx] = ask(idx);
    return mp[idx];
}

const int maxn = 2e5 + 10;
vector < int > st;
int best;
bool done = false;
void solve_range(int l, int r)
{
    if (done)
        return;
    ///cout << l << " " << r << " " << cnt << endl;
    int m = (l + r) / 2;
    vector < int > lf = local_ask(l);
    vector < int > rf = local_ask(r);
    if (lf[1] == rf[1])
        return;
    while(m > l)
    {
        vector < int > mf = local_ask(m);
        if (mf[0] + mf[1] != best)
        {
            if (mf[0] + mf[1] == 0)
                done = true;
            st.push_back(m);
            m --;
        }
        else
        {
            break;
        }
    }
    if (m == l)
    {
        m = (l + r) / 2 + 1;
        while(m < r)
        {
            vector < int > mf = local_ask(m);
            if (mf[0] + mf[1] != best)
            {
                            if (mf[0] + mf[1] == 0)
                done = true;
                st.push_back(m), m ++;
            }
            else
                break;
        }
    }
    if (m == r)
        return;

    vector < int > mf = local_ask(m);
    if (lf[0] != mf[0])
        solve_range(l, m);
    if (rf[0] != mf[0])
        solve_range(m, r);
}
int find_best(int n)
{
    vector < int > idc;
    for (int i = 0; i < n; i ++)
        idc.push_back(i);
    int nec = min(n, (int)sqrt(n) + 50);
    int mx = -1;
    for (int i = 0; i < nec; i ++)
    {
        vector < int > cur = local_ask(i);
        if (cur[0] + cur[1] > best)
        {
            best = cur[0] + cur[1];
            mx = i;
        }
    }
    int pt = n - 1;
    while(true)
    {
        vector < int > cur = local_ask(pt);
        if (cur[0] + cur[1] == best)
            break;
        pt --;
    }


    for (int i = 0; i < mx; i ++)
        st.push_back(i);
    for (int i = pt + 1; i < n; i ++)
        st.push_back(i);
    solve_range(mx, pt);

    //cout << st.size() << " " << cnt << endl;
    for (int i = 0; i < st.size(); i ++)
    {
        vector < int > cur = local_ask(st[i]);
        if (cur[0] + cur[1] == 0)
            return st[i];
    }
    return -1;
}

Compilation message

prize.cpp: In function 'int find_best(int)':
prize.cpp:106:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  106 |     for (int i = 0; i < st.size(); i ++)
      |                     ~~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 6 ms 1352 KB Output is correct
2 Correct 3 ms 1424 KB Output is correct
3 Correct 3 ms 1432 KB Output is correct
4 Correct 5 ms 1436 KB Output is correct
5 Correct 5 ms 1436 KB Output is correct
6 Correct 3 ms 1480 KB Output is correct
7 Correct 5 ms 1436 KB Output is correct
8 Correct 6 ms 1432 KB Output is correct
9 Correct 3 ms 1432 KB Output is correct
10 Correct 6 ms 1352 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 1432 KB Output is correct
2 Correct 4 ms 1480 KB Output is correct
3 Correct 3 ms 1436 KB Output is correct
4 Correct 5 ms 1436 KB Output is correct
5 Correct 7 ms 1352 KB Output is correct
6 Correct 7 ms 1352 KB Output is correct
7 Correct 5 ms 1416 KB Output is correct
8 Correct 5 ms 1436 KB Output is correct
9 Correct 4 ms 1436 KB Output is correct
10 Correct 5 ms 1352 KB Output is correct
11 Correct 8 ms 1436 KB Output is correct
12 Correct 3 ms 1424 KB Output is correct
13 Correct 6 ms 1440 KB Output is correct
14 Correct 4 ms 464 KB Output is correct
15 Correct 10 ms 1436 KB Output is correct
16 Correct 42 ms 1732 KB Output is correct
17 Correct 3 ms 1352 KB Output is correct
18 Partially correct 25 ms 1860 KB Partially correct - number of queries: 5253
19 Correct 5 ms 1352 KB Output is correct
20 Correct 9 ms 932 KB Output is correct
21 Correct 20 ms 1408 KB Output is correct
22 Correct 4 ms 1432 KB Output is correct
23 Correct 3 ms 1352 KB Output is correct
24 Correct 3 ms 1480 KB Output is correct
25 Correct 27 ms 1424 KB Output is correct
26 Correct 20 ms 1468 KB Output is correct
27 Correct 5 ms 1352 KB Output is correct
28 Correct 42 ms 1716 KB Output is correct
29 Correct 35 ms 1588 KB Output is correct
30 Partially correct 23 ms 1908 KB Partially correct - number of queries: 5222
31 Correct 3 ms 1436 KB Output is correct
32 Correct 4 ms 1416 KB Output is correct
33 Correct 1 ms 208 KB Output is correct
34 Correct 9 ms 1472 KB Output is correct
35 Correct 4 ms 1428 KB Output is correct
36 Correct 14 ms 1352 KB Output is correct
37 Correct 4 ms 1432 KB Output is correct
38 Correct 5 ms 1352 KB Output is correct
39 Correct 12 ms 1496 KB Output is correct
40 Correct 20 ms 1796 KB Output is correct
41 Correct 15 ms 1592 KB Output is correct
42 Correct 29 ms 1596 KB Output is correct
43 Correct 14 ms 1520 KB Output is correct
44 Correct 11 ms 1476 KB Output is correct
45 Correct 18 ms 1432 KB Output is correct
46 Correct 3 ms 1352 KB Output is correct
47 Correct 17 ms 1376 KB Output is correct
48 Correct 33 ms 1680 KB Output is correct
49 Correct 8 ms 1352 KB Output is correct
50 Partially correct 23 ms 1908 KB Partially correct - number of queries: 5257
51 Correct 22 ms 1352 KB Output is correct
52 Correct 5 ms 1352 KB Output is correct
53 Correct 7 ms 1440 KB Output is correct
54 Correct 11 ms 1440 KB Output is correct
55 Correct 6 ms 1352 KB Output is correct
56 Partially correct 42 ms 1804 KB Partially correct - number of queries: 5245
57 Correct 29 ms 1600 KB Output is correct
58 Correct 36 ms 1680 KB Output is correct
59 Correct 23 ms 1552 KB Output is correct
60 Correct 30 ms 1484 KB Output is correct
61 Correct 6 ms 1436 KB Output is correct
62 Correct 5 ms 1432 KB Output is correct
63 Correct 8 ms 1428 KB Output is correct
64 Correct 5 ms 1432 KB Output is correct
65 Correct 5 ms 1436 KB Output is correct
66 Correct 8 ms 1352 KB Output is correct
67 Correct 5 ms 1472 KB Output is correct
68 Correct 6 ms 1352 KB Output is correct
69 Correct 5 ms 1432 KB Output is correct
70 Correct 9 ms 1432 KB Output is correct
71 Partially correct 47 ms 1896 KB Partially correct - number of queries: 5256
72 Correct 11 ms 1352 KB Output is correct
73 Partially correct 49 ms 1876 KB Partially correct - number of queries: 5193
74 Partially correct 45 ms 1780 KB Partially correct - number of queries: 5220
75 Correct 7 ms 1352 KB Output is correct
76 Correct 30 ms 1768 KB Output is correct
77 Partially correct 52 ms 1840 KB Partially correct - number of queries: 5374
78 Correct 14 ms 1440 KB Output is correct
79 Correct 27 ms 1420 KB Output is correct
80 Partially correct 46 ms 1852 KB Partially correct - number of queries: 5380
81 Partially correct 36 ms 1856 KB Partially correct - number of queries: 5364
82 Partially correct 39 ms 1896 KB Partially correct - number of queries: 5318
83 Correct 6 ms 1352 KB Output is correct
84 Correct 39 ms 1700 KB Output is correct
85 Partially correct 40 ms 1840 KB Partially correct - number of queries: 5337
86 Correct 5 ms 1352 KB Output is correct
87 Correct 3 ms 1440 KB Output is correct
88 Correct 5 ms 1352 KB Output is correct
89 Correct 4 ms 1352 KB Output is correct
90 Correct 7 ms 1352 KB Output is correct
91 Correct 3 ms 1436 KB Output is correct
92 Correct 6 ms 1352 KB Output is correct
93 Correct 8 ms 1352 KB Output is correct
94 Correct 8 ms 1352 KB Output is correct
95 Correct 7 ms 1352 KB Output is correct
96 Correct 8 ms 1352 KB Output is correct
97 Correct 4 ms 1432 KB Output is correct