Submission #1019738

# Submission time Handle Problem Language Result Execution time Memory
1019738 2024-07-11T08:26:34 Z andrei_iorgulescu The Big Prize (IOI17_prize) C++17
90 / 100
55 ms 5972 KB
#include "prize.h"
#include <bits/stdc++.h>

using namespace std;

vector<int> f[200005];
bool viz[200005];

vector<int> askk(int pos)
{
    if (viz[pos])
        return f[pos];
    viz[pos] = true;
    f[pos] = ask(pos - 1);
    return f[pos];
}

/*
8
3 2 3 1 3 3 2 3
*/

int find_best(int n)
{
    int sn = 2 * sqrt(n) + 1;
    sn = min(sn,n);
    int nrmax = 0,ret_sc;
    for (int i = 1; i <= sn; i++)
    {
        vector<int> cur = askk(i);
        if (cur[0] + cur[1] == 0)
            return i - 1;
        nrmax = max(nrmax,cur[0] + cur[1]);
        if (cur[0] + cur[1] == nrmax)
            ret_sc = cur[1];
    }
    if (n - nrmax <= 500)
        assert(false);
    set<int> pozi;
    int p = sn + 1;
    while (true)
    {
        int st = p;
        int dr;
        if (pozi.empty() or ((*pozi.rbegin()) < p))
            dr = n;
        else
            dr = *pozi.lower_bound(st);
        while (st < dr)
        {
            int mij = (st + dr) / 2;
            vector<int> cur = askk(mij);
            if (cur[0] + cur[1] < nrmax)
                pozi.insert(mij),dr = mij;
            else
            {
                if (cur[1] == ret_sc)
                    st = mij + 1;
                else
                    dr = mij;
            }
        }
        while (true)
        {
            vector<int> cur = askk(st);
            if (cur[0] + cur[1] == 0)
                return st - 1;
            st++;
            p = st;
            if (cur[0] + cur[1] == nrmax)
            {
                ret_sc = cur[1];
                break;
            }
        }
    }
}

///a[i] = tipul lui i, nu prea imi pasa cat e V dar ce stiu e ca sunt sub sqrt(N) a[i] < V
///o sa incerc sa le gasesc pe fiecare in parte si dau query in ele
///pai mai intai gasesc primul de tip V, apoi voi tot incerca sa gasesc primul de tip < V de dupa si apoi brut pana la urmatorul de tip V
///asta cu binara, sigur da 90 ca e sqrtlog dar poate mai mult

Compilation message

prize.cpp: In function 'int find_best(int)':
prize.cpp:57:17: warning: 'ret_sc' may be used uninitialized in this function [-Wmaybe-uninitialized]
   57 |                 if (cur[1] == ret_sc)
      |                 ^~
# Verdict Execution time Memory Grader output
1 Correct 8 ms 4952 KB Output is correct
2 Correct 6 ms 4952 KB Output is correct
3 Correct 5 ms 4952 KB Output is correct
4 Correct 5 ms 4952 KB Output is correct
5 Correct 8 ms 4952 KB Output is correct
6 Correct 2 ms 4952 KB Output is correct
7 Correct 6 ms 5208 KB Output is correct
8 Correct 5 ms 5208 KB Output is correct
9 Correct 7 ms 4952 KB Output is correct
10 Correct 6 ms 4952 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 5156 KB Output is correct
2 Correct 6 ms 4952 KB Output is correct
3 Correct 6 ms 5208 KB Output is correct
4 Correct 6 ms 5152 KB Output is correct
5 Correct 6 ms 5208 KB Output is correct
6 Correct 2 ms 4952 KB Output is correct
7 Correct 8 ms 4952 KB Output is correct
8 Correct 6 ms 4952 KB Output is correct
9 Correct 6 ms 4952 KB Output is correct
10 Correct 6 ms 4952 KB Output is correct
11 Correct 8 ms 5156 KB Output is correct
12 Correct 6 ms 4952 KB Output is correct
13 Correct 8 ms 5208 KB Output is correct
14 Correct 5 ms 4952 KB Output is correct
15 Correct 13 ms 5404 KB Output is correct
16 Partially correct 44 ms 5456 KB Partially correct - number of queries: 7166
17 Correct 3 ms 4952 KB Output is correct
18 Partially correct 41 ms 5648 KB Partially correct - number of queries: 8340
19 Correct 6 ms 4952 KB Output is correct
20 Correct 18 ms 5452 KB Output is correct
21 Correct 17 ms 5208 KB Output is correct
22 Correct 8 ms 5208 KB Output is correct
23 Correct 6 ms 5208 KB Output is correct
24 Correct 5 ms 4952 KB Output is correct
25 Correct 17 ms 5272 KB Output is correct
26 Correct 25 ms 5208 KB Output is correct
27 Correct 5 ms 5208 KB Output is correct
28 Partially correct 32 ms 5472 KB Partially correct - number of queries: 7415
29 Partially correct 41 ms 5412 KB Partially correct - number of queries: 5937
30 Partially correct 52 ms 5668 KB Partially correct - number of queries: 8581
31 Correct 4 ms 4952 KB Output is correct
32 Correct 11 ms 5208 KB Output is correct
33 Correct 3 ms 4952 KB Output is correct
34 Correct 17 ms 5160 KB Output is correct
35 Correct 9 ms 5208 KB Output is correct
36 Correct 13 ms 5464 KB Output is correct
37 Correct 9 ms 5208 KB Output is correct
38 Correct 6 ms 4952 KB Output is correct
39 Correct 20 ms 5208 KB Output is correct
40 Partially correct 52 ms 5552 KB Partially correct - number of queries: 7492
41 Partially correct 40 ms 5412 KB Partially correct - number of queries: 5421
42 Partially correct 30 ms 5600 KB Partially correct - number of queries: 5421
43 Partially correct 26 ms 5412 KB Partially correct - number of queries: 5057
44 Correct 20 ms 5548 KB Output is correct
45 Correct 20 ms 5668 KB Output is correct
46 Correct 4 ms 4952 KB Output is correct
47 Correct 20 ms 5208 KB Output is correct
48 Partially correct 36 ms 5528 KB Partially correct - number of queries: 6330
49 Correct 12 ms 5132 KB Output is correct
50 Partially correct 50 ms 5972 KB Partially correct - number of queries: 8327
51 Correct 20 ms 5208 KB Output is correct
52 Correct 6 ms 4952 KB Output is correct
53 Correct 7 ms 5208 KB Output is correct
54 Correct 22 ms 5480 KB Output is correct
55 Correct 3 ms 4952 KB Output is correct
56 Partially correct 49 ms 5796 KB Partially correct - number of queries: 8303
57 Partially correct 38 ms 5744 KB Partially correct - number of queries: 6537
58 Partially correct 32 ms 5456 KB Partially correct - number of queries: 6418
59 Partially correct 29 ms 5208 KB Partially correct - number of queries: 5418
60 Correct 30 ms 5756 KB Output is correct
61 Correct 8 ms 5208 KB Output is correct
62 Correct 8 ms 4952 KB Output is correct
63 Correct 7 ms 5208 KB Output is correct
64 Correct 8 ms 5156 KB Output is correct
65 Correct 8 ms 4952 KB Output is correct
66 Correct 14 ms 5160 KB Output is correct
67 Correct 5 ms 5148 KB Output is correct
68 Correct 4 ms 4952 KB Output is correct
69 Correct 8 ms 4952 KB Output is correct
70 Correct 5 ms 5144 KB Output is correct
71 Partially correct 40 ms 5708 KB Partially correct - number of queries: 8692
72 Correct 7 ms 5208 KB Output is correct
73 Partially correct 52 ms 5592 KB Partially correct - number of queries: 8579
74 Partially correct 42 ms 5764 KB Partially correct - number of queries: 8624
75 Correct 6 ms 5204 KB Output is correct
76 Partially correct 43 ms 5728 KB Partially correct - number of queries: 7525
77 Partially correct 47 ms 5544 KB Partially correct - number of queries: 8175
78 Correct 11 ms 5348 KB Output is correct
79 Correct 15 ms 5396 KB Output is correct
80 Partially correct 50 ms 5568 KB Partially correct - number of queries: 8505
81 Partially correct 51 ms 5712 KB Partially correct - number of queries: 8227
82 Partially correct 36 ms 5684 KB Partially correct - number of queries: 8274
83 Correct 8 ms 5208 KB Output is correct
84 Partially correct 55 ms 5456 KB Partially correct - number of queries: 6601
85 Partially correct 52 ms 5456 KB Partially correct - number of queries: 8358
86 Correct 6 ms 4952 KB Output is correct
87 Correct 6 ms 5408 KB Output is correct
88 Correct 6 ms 4952 KB Output is correct
89 Correct 6 ms 4952 KB Output is correct
90 Correct 8 ms 5224 KB Output is correct
91 Correct 6 ms 4952 KB Output is correct
92 Correct 7 ms 4952 KB Output is correct
93 Correct 11 ms 5208 KB Output is correct
94 Correct 6 ms 5208 KB Output is correct
95 Correct 8 ms 5208 KB Output is correct
96 Correct 6 ms 5168 KB Output is correct
97 Correct 7 ms 5144 KB Output is correct