Submission #1022216

# Submission time Handle Problem Language Result Execution time Memory
1022216 2024-07-13T11:11:14 Z parsadox2 Shortcut (IOI16_shortcut) C++17
0 / 100
54 ms 94308 KB
#include "shortcut.h"
#include <bits/stdc++.h>

using namespace std;

const int N = 1e6 + 10;
const long long int inf = 1e18;
long long n , c , d[N];
long long s[N];

struct NODE{
    long long mxp , mxm;
    long long ans;
    NODE(){
        mxp = mxm = ans = 0;
    }
};

struct SEG{
    NODE t[N << 2];
    NODE Merge(NODE aa , NODE bb)
    {
        NODE res;
        res.mxp = max(aa.mxp , bb.mxp);
        res.mxm = max(aa.mxm , bb.mxm);
        res.ans = max({aa.ans , bb.ans , 1LL * bb.mxp + aa.mxm});
        return res;
    }
    void Build(int node = 1 , int nl = 0 , int nr = n)
    {
        if(nr - nl == 1)
        {
            t[node].mxp = d[nl] + s[nl];
            t[node].mxm = d[nl] - s[nl];
            t[node].ans = 0;
            return;
        }
        int mid = (nl + nr) >> 1 , lc = node << 1 , rc = lc | 1;
        Build(lc , nl , mid);  Build(rc , mid , nr);
        t[node] = Merge(t[lc] , t[rc]);
    }
    NODE Get(int l , int r , int node = 1 , int nl = 0 , int nr = n)
    {
        if(r <= nl || nr <= l || r <= l)
        {
            NODE emp;
            emp.mxm = -inf;
            return emp;
        }
        if(l <= nl && nr <= r)
        {
            //cout << "WTFFF  " << nl << " " << nr << " " << t[node].mxm << endl;
            return t[node];
        }
        int mid = (nl + nr) >> 1 , lc = node << 1 , rc = lc | 1;
        return Merge(Get(l , r , lc , nl , mid) , Get(l , r , rc , mid , nr));
    }
} seg;

long long Solve(int a , int b)
{
    auto L = seg.Get(0 , a + 1) , R = seg.Get(b , n);
    long long res = max({L.ans , R.ans , R.mxp - s[b] + s[a] + L.mxm + min(c , s[b] - s[a])});
    //cout << a << " " << b << " " << res << endl;
    long long tmp = (c + s[a] + s[b]) / 2;
    int pos = upper_bound(s , s + n , tmp) - s;
    pos = min(pos , b + 1);
    auto L1 = seg.Get(0 , pos) , L2 = seg.Get(pos , b + 1);
    if(pos >= a && pos <= b)
    {
        //cout << "WTF " << L1.ans << " " << L.mxm << " " << L2.mxm << endl;
        res = max({res , L1.ans , c + s[b] + s[a] + L.mxm + L2.mxm});
    }
    //cout << a << " " << b << " p1 " << pos << " " << res << endl;
    tmp = (s[a] + s[b] - c) / 2;
    if(s[a] + s[b] - c < 0)
        tmp = -1;
    pos = upper_bound(s , s + n , tmp) - s;
    pos = max(pos , a);
    auto R1 = seg.Get(a , pos) , R2 = seg.Get(pos , n);
    if(pos >= a && pos <= b)
    {
        //cout << "WTF " << R2.ans << " " << R.mxp << " " << R1.mxp << endl;
        res = max({res , R2.ans , c - s[a] - s[b] + R.mxp + R1.mxp});
    }
    //cout << a << " " << b << " p2 " << pos << " " << res << endl; 
    for(int i = a ; i < b ; i++)  for(int j = i + 1 ; j < b ; j++)
        res = max(res , min(d[i] + d[j] + s[j] - s[i] , d[i] + d[j] + c + s[b] - s[a] - s[j] + s[i]));
    //cout << a << " " << b << " " << res << endl;
    return res;
}

long long find_shortcut(int nn, std::vector<int> l, std::vector<int> D, int C)
{
    n = nn;
    c = C;
    for(int i = 1 ; i < n ; i++)
        s[i] = s[i - 1] + l[i - 1];
    for(int i = 0 ; i < n ; i++)
        d[i] = D[i];
    seg.Build();
    long long res = inf;
    for(int a = 0 ; a + 1 < n ; a++)  for(int b = a + 1 ; b < n ; b++)
    {
        //cout << a << " " << b << endl;
        res = min(res , Solve(a , b));
    }
    return res;
}
# Verdict Execution time Memory Grader output
1 Correct 53 ms 94292 KB n = 4, 80 is a correct answer
2 Correct 37 ms 94232 KB n = 9, 110 is a correct answer
3 Correct 39 ms 94288 KB n = 4, 21 is a correct answer
4 Correct 54 ms 94288 KB n = 3, 4 is a correct answer
5 Correct 38 ms 94176 KB n = 2, 62 is a correct answer
6 Correct 36 ms 94308 KB n = 2, 3 is a correct answer
7 Correct 40 ms 94288 KB n = 3, 29 is a correct answer
8 Correct 42 ms 94260 KB n = 2, 3 is a correct answer
9 Correct 36 ms 94292 KB n = 2, 3 is a correct answer
10 Correct 38 ms 94292 KB n = 2, 2000000001 is a correct answer
11 Correct 38 ms 94288 KB n = 2, 3000000000 is a correct answer
12 Correct 38 ms 94292 KB n = 3, 3000000000 is a correct answer
13 Correct 37 ms 94292 KB n = 3, 3000000000 is a correct answer
14 Correct 37 ms 94132 KB n = 4, 3000000001 is a correct answer
15 Correct 39 ms 94296 KB n = 4, 4000000000 is a correct answer
16 Correct 38 ms 94280 KB n = 5, 4000000000 is a correct answer
17 Correct 52 ms 94292 KB n = 10, 1000000343 is a correct answer
18 Correct 43 ms 94196 KB n = 10, 3189 is a correct answer
19 Correct 38 ms 94292 KB n = 10, 7000000000 is a correct answer
20 Correct 39 ms 94288 KB n = 5, 12 is a correct answer
21 Correct 38 ms 94256 KB n = 5, 25 is a correct answer
22 Correct 38 ms 94132 KB n = 2, 122 is a correct answer
23 Incorrect 40 ms 94228 KB n = 10, incorrect answer: jury 117 vs contestant 109
24 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 53 ms 94292 KB n = 4, 80 is a correct answer
2 Correct 37 ms 94232 KB n = 9, 110 is a correct answer
3 Correct 39 ms 94288 KB n = 4, 21 is a correct answer
4 Correct 54 ms 94288 KB n = 3, 4 is a correct answer
5 Correct 38 ms 94176 KB n = 2, 62 is a correct answer
6 Correct 36 ms 94308 KB n = 2, 3 is a correct answer
7 Correct 40 ms 94288 KB n = 3, 29 is a correct answer
8 Correct 42 ms 94260 KB n = 2, 3 is a correct answer
9 Correct 36 ms 94292 KB n = 2, 3 is a correct answer
10 Correct 38 ms 94292 KB n = 2, 2000000001 is a correct answer
11 Correct 38 ms 94288 KB n = 2, 3000000000 is a correct answer
12 Correct 38 ms 94292 KB n = 3, 3000000000 is a correct answer
13 Correct 37 ms 94292 KB n = 3, 3000000000 is a correct answer
14 Correct 37 ms 94132 KB n = 4, 3000000001 is a correct answer
15 Correct 39 ms 94296 KB n = 4, 4000000000 is a correct answer
16 Correct 38 ms 94280 KB n = 5, 4000000000 is a correct answer
17 Correct 52 ms 94292 KB n = 10, 1000000343 is a correct answer
18 Correct 43 ms 94196 KB n = 10, 3189 is a correct answer
19 Correct 38 ms 94292 KB n = 10, 7000000000 is a correct answer
20 Correct 39 ms 94288 KB n = 5, 12 is a correct answer
21 Correct 38 ms 94256 KB n = 5, 25 is a correct answer
22 Correct 38 ms 94132 KB n = 2, 122 is a correct answer
23 Incorrect 40 ms 94228 KB n = 10, incorrect answer: jury 117 vs contestant 109
24 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 53 ms 94292 KB n = 4, 80 is a correct answer
2 Correct 37 ms 94232 KB n = 9, 110 is a correct answer
3 Correct 39 ms 94288 KB n = 4, 21 is a correct answer
4 Correct 54 ms 94288 KB n = 3, 4 is a correct answer
5 Correct 38 ms 94176 KB n = 2, 62 is a correct answer
6 Correct 36 ms 94308 KB n = 2, 3 is a correct answer
7 Correct 40 ms 94288 KB n = 3, 29 is a correct answer
8 Correct 42 ms 94260 KB n = 2, 3 is a correct answer
9 Correct 36 ms 94292 KB n = 2, 3 is a correct answer
10 Correct 38 ms 94292 KB n = 2, 2000000001 is a correct answer
11 Correct 38 ms 94288 KB n = 2, 3000000000 is a correct answer
12 Correct 38 ms 94292 KB n = 3, 3000000000 is a correct answer
13 Correct 37 ms 94292 KB n = 3, 3000000000 is a correct answer
14 Correct 37 ms 94132 KB n = 4, 3000000001 is a correct answer
15 Correct 39 ms 94296 KB n = 4, 4000000000 is a correct answer
16 Correct 38 ms 94280 KB n = 5, 4000000000 is a correct answer
17 Correct 52 ms 94292 KB n = 10, 1000000343 is a correct answer
18 Correct 43 ms 94196 KB n = 10, 3189 is a correct answer
19 Correct 38 ms 94292 KB n = 10, 7000000000 is a correct answer
20 Correct 39 ms 94288 KB n = 5, 12 is a correct answer
21 Correct 38 ms 94256 KB n = 5, 25 is a correct answer
22 Correct 38 ms 94132 KB n = 2, 122 is a correct answer
23 Incorrect 40 ms 94228 KB n = 10, incorrect answer: jury 117 vs contestant 109
24 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 53 ms 94292 KB n = 4, 80 is a correct answer
2 Correct 37 ms 94232 KB n = 9, 110 is a correct answer
3 Correct 39 ms 94288 KB n = 4, 21 is a correct answer
4 Correct 54 ms 94288 KB n = 3, 4 is a correct answer
5 Correct 38 ms 94176 KB n = 2, 62 is a correct answer
6 Correct 36 ms 94308 KB n = 2, 3 is a correct answer
7 Correct 40 ms 94288 KB n = 3, 29 is a correct answer
8 Correct 42 ms 94260 KB n = 2, 3 is a correct answer
9 Correct 36 ms 94292 KB n = 2, 3 is a correct answer
10 Correct 38 ms 94292 KB n = 2, 2000000001 is a correct answer
11 Correct 38 ms 94288 KB n = 2, 3000000000 is a correct answer
12 Correct 38 ms 94292 KB n = 3, 3000000000 is a correct answer
13 Correct 37 ms 94292 KB n = 3, 3000000000 is a correct answer
14 Correct 37 ms 94132 KB n = 4, 3000000001 is a correct answer
15 Correct 39 ms 94296 KB n = 4, 4000000000 is a correct answer
16 Correct 38 ms 94280 KB n = 5, 4000000000 is a correct answer
17 Correct 52 ms 94292 KB n = 10, 1000000343 is a correct answer
18 Correct 43 ms 94196 KB n = 10, 3189 is a correct answer
19 Correct 38 ms 94292 KB n = 10, 7000000000 is a correct answer
20 Correct 39 ms 94288 KB n = 5, 12 is a correct answer
21 Correct 38 ms 94256 KB n = 5, 25 is a correct answer
22 Correct 38 ms 94132 KB n = 2, 122 is a correct answer
23 Incorrect 40 ms 94228 KB n = 10, incorrect answer: jury 117 vs contestant 109
24 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 53 ms 94292 KB n = 4, 80 is a correct answer
2 Correct 37 ms 94232 KB n = 9, 110 is a correct answer
3 Correct 39 ms 94288 KB n = 4, 21 is a correct answer
4 Correct 54 ms 94288 KB n = 3, 4 is a correct answer
5 Correct 38 ms 94176 KB n = 2, 62 is a correct answer
6 Correct 36 ms 94308 KB n = 2, 3 is a correct answer
7 Correct 40 ms 94288 KB n = 3, 29 is a correct answer
8 Correct 42 ms 94260 KB n = 2, 3 is a correct answer
9 Correct 36 ms 94292 KB n = 2, 3 is a correct answer
10 Correct 38 ms 94292 KB n = 2, 2000000001 is a correct answer
11 Correct 38 ms 94288 KB n = 2, 3000000000 is a correct answer
12 Correct 38 ms 94292 KB n = 3, 3000000000 is a correct answer
13 Correct 37 ms 94292 KB n = 3, 3000000000 is a correct answer
14 Correct 37 ms 94132 KB n = 4, 3000000001 is a correct answer
15 Correct 39 ms 94296 KB n = 4, 4000000000 is a correct answer
16 Correct 38 ms 94280 KB n = 5, 4000000000 is a correct answer
17 Correct 52 ms 94292 KB n = 10, 1000000343 is a correct answer
18 Correct 43 ms 94196 KB n = 10, 3189 is a correct answer
19 Correct 38 ms 94292 KB n = 10, 7000000000 is a correct answer
20 Correct 39 ms 94288 KB n = 5, 12 is a correct answer
21 Correct 38 ms 94256 KB n = 5, 25 is a correct answer
22 Correct 38 ms 94132 KB n = 2, 122 is a correct answer
23 Incorrect 40 ms 94228 KB n = 10, incorrect answer: jury 117 vs contestant 109
24 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 53 ms 94292 KB n = 4, 80 is a correct answer
2 Correct 37 ms 94232 KB n = 9, 110 is a correct answer
3 Correct 39 ms 94288 KB n = 4, 21 is a correct answer
4 Correct 54 ms 94288 KB n = 3, 4 is a correct answer
5 Correct 38 ms 94176 KB n = 2, 62 is a correct answer
6 Correct 36 ms 94308 KB n = 2, 3 is a correct answer
7 Correct 40 ms 94288 KB n = 3, 29 is a correct answer
8 Correct 42 ms 94260 KB n = 2, 3 is a correct answer
9 Correct 36 ms 94292 KB n = 2, 3 is a correct answer
10 Correct 38 ms 94292 KB n = 2, 2000000001 is a correct answer
11 Correct 38 ms 94288 KB n = 2, 3000000000 is a correct answer
12 Correct 38 ms 94292 KB n = 3, 3000000000 is a correct answer
13 Correct 37 ms 94292 KB n = 3, 3000000000 is a correct answer
14 Correct 37 ms 94132 KB n = 4, 3000000001 is a correct answer
15 Correct 39 ms 94296 KB n = 4, 4000000000 is a correct answer
16 Correct 38 ms 94280 KB n = 5, 4000000000 is a correct answer
17 Correct 52 ms 94292 KB n = 10, 1000000343 is a correct answer
18 Correct 43 ms 94196 KB n = 10, 3189 is a correct answer
19 Correct 38 ms 94292 KB n = 10, 7000000000 is a correct answer
20 Correct 39 ms 94288 KB n = 5, 12 is a correct answer
21 Correct 38 ms 94256 KB n = 5, 25 is a correct answer
22 Correct 38 ms 94132 KB n = 2, 122 is a correct answer
23 Incorrect 40 ms 94228 KB n = 10, incorrect answer: jury 117 vs contestant 109
24 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 53 ms 94292 KB n = 4, 80 is a correct answer
2 Correct 37 ms 94232 KB n = 9, 110 is a correct answer
3 Correct 39 ms 94288 KB n = 4, 21 is a correct answer
4 Correct 54 ms 94288 KB n = 3, 4 is a correct answer
5 Correct 38 ms 94176 KB n = 2, 62 is a correct answer
6 Correct 36 ms 94308 KB n = 2, 3 is a correct answer
7 Correct 40 ms 94288 KB n = 3, 29 is a correct answer
8 Correct 42 ms 94260 KB n = 2, 3 is a correct answer
9 Correct 36 ms 94292 KB n = 2, 3 is a correct answer
10 Correct 38 ms 94292 KB n = 2, 2000000001 is a correct answer
11 Correct 38 ms 94288 KB n = 2, 3000000000 is a correct answer
12 Correct 38 ms 94292 KB n = 3, 3000000000 is a correct answer
13 Correct 37 ms 94292 KB n = 3, 3000000000 is a correct answer
14 Correct 37 ms 94132 KB n = 4, 3000000001 is a correct answer
15 Correct 39 ms 94296 KB n = 4, 4000000000 is a correct answer
16 Correct 38 ms 94280 KB n = 5, 4000000000 is a correct answer
17 Correct 52 ms 94292 KB n = 10, 1000000343 is a correct answer
18 Correct 43 ms 94196 KB n = 10, 3189 is a correct answer
19 Correct 38 ms 94292 KB n = 10, 7000000000 is a correct answer
20 Correct 39 ms 94288 KB n = 5, 12 is a correct answer
21 Correct 38 ms 94256 KB n = 5, 25 is a correct answer
22 Correct 38 ms 94132 KB n = 2, 122 is a correct answer
23 Incorrect 40 ms 94228 KB n = 10, incorrect answer: jury 117 vs contestant 109
24 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 53 ms 94292 KB n = 4, 80 is a correct answer
2 Correct 37 ms 94232 KB n = 9, 110 is a correct answer
3 Correct 39 ms 94288 KB n = 4, 21 is a correct answer
4 Correct 54 ms 94288 KB n = 3, 4 is a correct answer
5 Correct 38 ms 94176 KB n = 2, 62 is a correct answer
6 Correct 36 ms 94308 KB n = 2, 3 is a correct answer
7 Correct 40 ms 94288 KB n = 3, 29 is a correct answer
8 Correct 42 ms 94260 KB n = 2, 3 is a correct answer
9 Correct 36 ms 94292 KB n = 2, 3 is a correct answer
10 Correct 38 ms 94292 KB n = 2, 2000000001 is a correct answer
11 Correct 38 ms 94288 KB n = 2, 3000000000 is a correct answer
12 Correct 38 ms 94292 KB n = 3, 3000000000 is a correct answer
13 Correct 37 ms 94292 KB n = 3, 3000000000 is a correct answer
14 Correct 37 ms 94132 KB n = 4, 3000000001 is a correct answer
15 Correct 39 ms 94296 KB n = 4, 4000000000 is a correct answer
16 Correct 38 ms 94280 KB n = 5, 4000000000 is a correct answer
17 Correct 52 ms 94292 KB n = 10, 1000000343 is a correct answer
18 Correct 43 ms 94196 KB n = 10, 3189 is a correct answer
19 Correct 38 ms 94292 KB n = 10, 7000000000 is a correct answer
20 Correct 39 ms 94288 KB n = 5, 12 is a correct answer
21 Correct 38 ms 94256 KB n = 5, 25 is a correct answer
22 Correct 38 ms 94132 KB n = 2, 122 is a correct answer
23 Incorrect 40 ms 94228 KB n = 10, incorrect answer: jury 117 vs contestant 109
24 Halted 0 ms 0 KB -