Submission #1019825

# Submission time Handle Problem Language Result Execution time Memory
1019825 2024-07-11T09:17:55 Z andrei_iorgulescu The Big Prize (IOI17_prize) C++14
100 / 100
38 ms 5720 KB
#include "prize.h"
#include <bits/stdc++.h>

using namespace std;

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

vector<int> askk(int pos)
{
    //pos = N + 1 - 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)
{
    N = n;
    int sn = 500;
    //int sn = 1;
    sn = min(sn,n);
    int nrmax = 0,ret_sc;
    int seen = 0;
    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 (nrmax > 50)
        {
            sn = i;
            break;
        }
    }
    int cate = nrmax;
    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);
        int dr0 = dr;
        int cr = (n - st) / ret_sc + 10;
        dr = min(dr,st + cr);
        if (dr != dr0)
        {
            vector<int> lol = askk(dr);
            if (lol[0] + lol[1] == nrmax and lol[1] == ret_sc)
            {
                p = dr + 1;
                continue;
            }
            else if (lol[0] + lol[1] == 0)
                return dr - 1;
            else if (lol[0] + lol[1] < nrmax)
                pozi.insert(dr);
        }
        while (st < dr)
        {
            int mij = (st + dr) / 2;
            vector<int> cur = askk(mij);
            if (cur[0] + cur[1] < nrmax)
            {
                if (cur[0] + cur[1] == 0)
                    return mij - 1;
                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:32:9: warning: unused variable 'seen' [-Wunused-variable]
   32 |     int seen = 0;
      |         ^~~~
prize.cpp:47:9: warning: unused variable 'cate' [-Wunused-variable]
   47 |     int cate = nrmax;
      |         ^~~~
prize.cpp:59:27: warning: 'ret_sc' may be used uninitialized in this function [-Wmaybe-uninitialized]
   59 |         int cr = (n - st) / ret_sc + 10;
      |                  ~~~~~~~~~^~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 6 ms 5404 KB Output is correct
2 Correct 5 ms 4952 KB Output is correct
3 Correct 7 ms 5148 KB Output is correct
4 Correct 5 ms 5148 KB Output is correct
5 Correct 5 ms 4952 KB Output is correct
6 Correct 2 ms 4952 KB Output is correct
7 Correct 6 ms 4952 KB Output is correct
8 Correct 4 ms 4952 KB Output is correct
9 Correct 4 ms 4952 KB Output is correct
10 Correct 5 ms 4952 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 4952 KB Output is correct
2 Correct 5 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 5 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 4 ms 4952 KB Output is correct
9 Correct 5 ms 4952 KB Output is correct
10 Correct 5 ms 4952 KB Output is correct
11 Correct 6 ms 5208 KB Output is correct
12 Correct 6 ms 5208 KB Output is correct
13 Correct 6 ms 5208 KB Output is correct
14 Correct 3 ms 4952 KB Output is correct
15 Correct 5 ms 5132 KB Output is correct
16 Correct 16 ms 5208 KB Output is correct
17 Correct 2 ms 4952 KB Output is correct
18 Correct 25 ms 5456 KB Output is correct
19 Correct 2 ms 4952 KB Output is correct
20 Correct 8 ms 5208 KB Output is correct
21 Correct 11 ms 5456 KB Output is correct
22 Correct 4 ms 4952 KB Output is correct
23 Correct 5 ms 4952 KB Output is correct
24 Correct 4 ms 4952 KB Output is correct
25 Correct 16 ms 5208 KB Output is correct
26 Correct 20 ms 5464 KB Output is correct
27 Correct 5 ms 4952 KB Output is correct
28 Correct 23 ms 5448 KB Output is correct
29 Correct 17 ms 5392 KB Output is correct
30 Correct 31 ms 5468 KB Output is correct
31 Correct 2 ms 4952 KB Output is correct
32 Correct 6 ms 5156 KB Output is correct
33 Correct 2 ms 4952 KB Output is correct
34 Correct 8 ms 5208 KB Output is correct
35 Correct 5 ms 5208 KB Output is correct
36 Correct 8 ms 5208 KB Output is correct
37 Correct 7 ms 5464 KB Output is correct
38 Correct 5 ms 4952 KB Output is correct
39 Correct 9 ms 5208 KB Output is correct
40 Correct 24 ms 5452 KB Output is correct
41 Correct 16 ms 5400 KB Output is correct
42 Correct 21 ms 5208 KB Output is correct
43 Correct 14 ms 5456 KB Output is correct
44 Correct 12 ms 5232 KB Output is correct
45 Correct 9 ms 5208 KB Output is correct
46 Correct 2 ms 4952 KB Output is correct
47 Correct 12 ms 5268 KB Output is correct
48 Correct 18 ms 5712 KB Output is correct
49 Correct 4 ms 4952 KB Output is correct
50 Correct 34 ms 5484 KB Output is correct
51 Correct 13 ms 5208 KB Output is correct
52 Correct 3 ms 4952 KB Output is correct
53 Correct 5 ms 5148 KB Output is correct
54 Correct 8 ms 5208 KB Output is correct
55 Correct 3 ms 4952 KB Output is correct
56 Correct 38 ms 5472 KB Output is correct
57 Correct 21 ms 5208 KB Output is correct
58 Correct 17 ms 5352 KB Output is correct
59 Correct 14 ms 5208 KB Output is correct
60 Correct 14 ms 5464 KB Output is correct
61 Correct 5 ms 5208 KB Output is correct
62 Correct 5 ms 4952 KB Output is correct
63 Correct 4 ms 5208 KB Output is correct
64 Correct 4 ms 5144 KB Output is correct
65 Correct 5 ms 5144 KB Output is correct
66 Correct 18 ms 5476 KB Output is correct
67 Correct 11 ms 5464 KB Output is correct
68 Correct 3 ms 4952 KB Output is correct
69 Correct 11 ms 5208 KB Output is correct
70 Correct 11 ms 5208 KB Output is correct
71 Correct 23 ms 5480 KB Output is correct
72 Correct 8 ms 5204 KB Output is correct
73 Correct 22 ms 5720 KB Output is correct
74 Correct 30 ms 5448 KB Output is correct
75 Correct 5 ms 5208 KB Output is correct
76 Correct 29 ms 5456 KB Output is correct
77 Correct 24 ms 5444 KB Output is correct
78 Correct 8 ms 5208 KB Output is correct
79 Correct 14 ms 5312 KB Output is correct
80 Correct 26 ms 5456 KB Output is correct
81 Correct 22 ms 5272 KB Output is correct
82 Correct 24 ms 5464 KB Output is correct
83 Correct 5 ms 5208 KB Output is correct
84 Correct 28 ms 5544 KB Output is correct
85 Correct 28 ms 5564 KB Output is correct
86 Correct 4 ms 4952 KB Output is correct
87 Correct 7 ms 5472 KB Output is correct
88 Correct 4 ms 4952 KB Output is correct
89 Correct 5 ms 4952 KB Output is correct
90 Correct 5 ms 4952 KB Output is correct
91 Correct 3 ms 4952 KB Output is correct
92 Correct 5 ms 4952 KB Output is correct
93 Correct 7 ms 5208 KB Output is correct
94 Correct 6 ms 5208 KB Output is correct
95 Correct 4 ms 5208 KB Output is correct
96 Correct 6 ms 5208 KB Output is correct
97 Correct 4 ms 4952 KB Output is correct