답안 #1022218

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1022218 2024-07-13T11:13:41 Z parsadox2 Shortcut (IOI16_shortcut) C++17
0 / 100
44 ms 94364 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);
    //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);
    //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;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 39 ms 94288 KB n = 4, 80 is a correct answer
2 Correct 38 ms 94292 KB n = 9, 110 is a correct answer
3 Correct 38 ms 94288 KB n = 4, 21 is a correct answer
4 Correct 39 ms 94296 KB n = 3, 4 is a correct answer
5 Correct 36 ms 94312 KB n = 2, 62 is a correct answer
6 Correct 38 ms 94296 KB n = 2, 3 is a correct answer
7 Correct 38 ms 94288 KB n = 3, 29 is a correct answer
8 Correct 38 ms 94232 KB n = 2, 3 is a correct answer
9 Correct 36 ms 94300 KB n = 2, 3 is a correct answer
10 Correct 38 ms 94304 KB n = 2, 2000000001 is a correct answer
11 Correct 37 ms 94300 KB n = 2, 3000000000 is a correct answer
12 Correct 37 ms 94292 KB n = 3, 3000000000 is a correct answer
13 Correct 37 ms 94364 KB n = 3, 3000000000 is a correct answer
14 Correct 38 ms 94300 KB n = 4, 3000000001 is a correct answer
15 Correct 38 ms 94300 KB n = 4, 4000000000 is a correct answer
16 Correct 38 ms 94292 KB n = 5, 4000000000 is a correct answer
17 Correct 37 ms 94340 KB n = 10, 1000000343 is a correct answer
18 Correct 36 ms 94300 KB n = 10, 3189 is a correct answer
19 Correct 39 ms 94160 KB n = 10, 7000000000 is a correct answer
20 Correct 38 ms 94292 KB n = 5, 12 is a correct answer
21 Correct 39 ms 94288 KB n = 5, 25 is a correct answer
22 Correct 36 ms 94292 KB n = 2, 122 is a correct answer
23 Correct 37 ms 94208 KB n = 10, 117 is a correct answer
24 Correct 38 ms 94292 KB n = 10, 336 is a correct answer
25 Correct 41 ms 94292 KB n = 10, 438 is a correct answer
26 Correct 44 ms 94180 KB n = 10, 206 is a correct answer
27 Incorrect 39 ms 94292 KB n = 10, incorrect answer: jury 636 vs contestant 1530
28 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 39 ms 94288 KB n = 4, 80 is a correct answer
2 Correct 38 ms 94292 KB n = 9, 110 is a correct answer
3 Correct 38 ms 94288 KB n = 4, 21 is a correct answer
4 Correct 39 ms 94296 KB n = 3, 4 is a correct answer
5 Correct 36 ms 94312 KB n = 2, 62 is a correct answer
6 Correct 38 ms 94296 KB n = 2, 3 is a correct answer
7 Correct 38 ms 94288 KB n = 3, 29 is a correct answer
8 Correct 38 ms 94232 KB n = 2, 3 is a correct answer
9 Correct 36 ms 94300 KB n = 2, 3 is a correct answer
10 Correct 38 ms 94304 KB n = 2, 2000000001 is a correct answer
11 Correct 37 ms 94300 KB n = 2, 3000000000 is a correct answer
12 Correct 37 ms 94292 KB n = 3, 3000000000 is a correct answer
13 Correct 37 ms 94364 KB n = 3, 3000000000 is a correct answer
14 Correct 38 ms 94300 KB n = 4, 3000000001 is a correct answer
15 Correct 38 ms 94300 KB n = 4, 4000000000 is a correct answer
16 Correct 38 ms 94292 KB n = 5, 4000000000 is a correct answer
17 Correct 37 ms 94340 KB n = 10, 1000000343 is a correct answer
18 Correct 36 ms 94300 KB n = 10, 3189 is a correct answer
19 Correct 39 ms 94160 KB n = 10, 7000000000 is a correct answer
20 Correct 38 ms 94292 KB n = 5, 12 is a correct answer
21 Correct 39 ms 94288 KB n = 5, 25 is a correct answer
22 Correct 36 ms 94292 KB n = 2, 122 is a correct answer
23 Correct 37 ms 94208 KB n = 10, 117 is a correct answer
24 Correct 38 ms 94292 KB n = 10, 336 is a correct answer
25 Correct 41 ms 94292 KB n = 10, 438 is a correct answer
26 Correct 44 ms 94180 KB n = 10, 206 is a correct answer
27 Incorrect 39 ms 94292 KB n = 10, incorrect answer: jury 636 vs contestant 1530
28 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 39 ms 94288 KB n = 4, 80 is a correct answer
2 Correct 38 ms 94292 KB n = 9, 110 is a correct answer
3 Correct 38 ms 94288 KB n = 4, 21 is a correct answer
4 Correct 39 ms 94296 KB n = 3, 4 is a correct answer
5 Correct 36 ms 94312 KB n = 2, 62 is a correct answer
6 Correct 38 ms 94296 KB n = 2, 3 is a correct answer
7 Correct 38 ms 94288 KB n = 3, 29 is a correct answer
8 Correct 38 ms 94232 KB n = 2, 3 is a correct answer
9 Correct 36 ms 94300 KB n = 2, 3 is a correct answer
10 Correct 38 ms 94304 KB n = 2, 2000000001 is a correct answer
11 Correct 37 ms 94300 KB n = 2, 3000000000 is a correct answer
12 Correct 37 ms 94292 KB n = 3, 3000000000 is a correct answer
13 Correct 37 ms 94364 KB n = 3, 3000000000 is a correct answer
14 Correct 38 ms 94300 KB n = 4, 3000000001 is a correct answer
15 Correct 38 ms 94300 KB n = 4, 4000000000 is a correct answer
16 Correct 38 ms 94292 KB n = 5, 4000000000 is a correct answer
17 Correct 37 ms 94340 KB n = 10, 1000000343 is a correct answer
18 Correct 36 ms 94300 KB n = 10, 3189 is a correct answer
19 Correct 39 ms 94160 KB n = 10, 7000000000 is a correct answer
20 Correct 38 ms 94292 KB n = 5, 12 is a correct answer
21 Correct 39 ms 94288 KB n = 5, 25 is a correct answer
22 Correct 36 ms 94292 KB n = 2, 122 is a correct answer
23 Correct 37 ms 94208 KB n = 10, 117 is a correct answer
24 Correct 38 ms 94292 KB n = 10, 336 is a correct answer
25 Correct 41 ms 94292 KB n = 10, 438 is a correct answer
26 Correct 44 ms 94180 KB n = 10, 206 is a correct answer
27 Incorrect 39 ms 94292 KB n = 10, incorrect answer: jury 636 vs contestant 1530
28 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 39 ms 94288 KB n = 4, 80 is a correct answer
2 Correct 38 ms 94292 KB n = 9, 110 is a correct answer
3 Correct 38 ms 94288 KB n = 4, 21 is a correct answer
4 Correct 39 ms 94296 KB n = 3, 4 is a correct answer
5 Correct 36 ms 94312 KB n = 2, 62 is a correct answer
6 Correct 38 ms 94296 KB n = 2, 3 is a correct answer
7 Correct 38 ms 94288 KB n = 3, 29 is a correct answer
8 Correct 38 ms 94232 KB n = 2, 3 is a correct answer
9 Correct 36 ms 94300 KB n = 2, 3 is a correct answer
10 Correct 38 ms 94304 KB n = 2, 2000000001 is a correct answer
11 Correct 37 ms 94300 KB n = 2, 3000000000 is a correct answer
12 Correct 37 ms 94292 KB n = 3, 3000000000 is a correct answer
13 Correct 37 ms 94364 KB n = 3, 3000000000 is a correct answer
14 Correct 38 ms 94300 KB n = 4, 3000000001 is a correct answer
15 Correct 38 ms 94300 KB n = 4, 4000000000 is a correct answer
16 Correct 38 ms 94292 KB n = 5, 4000000000 is a correct answer
17 Correct 37 ms 94340 KB n = 10, 1000000343 is a correct answer
18 Correct 36 ms 94300 KB n = 10, 3189 is a correct answer
19 Correct 39 ms 94160 KB n = 10, 7000000000 is a correct answer
20 Correct 38 ms 94292 KB n = 5, 12 is a correct answer
21 Correct 39 ms 94288 KB n = 5, 25 is a correct answer
22 Correct 36 ms 94292 KB n = 2, 122 is a correct answer
23 Correct 37 ms 94208 KB n = 10, 117 is a correct answer
24 Correct 38 ms 94292 KB n = 10, 336 is a correct answer
25 Correct 41 ms 94292 KB n = 10, 438 is a correct answer
26 Correct 44 ms 94180 KB n = 10, 206 is a correct answer
27 Incorrect 39 ms 94292 KB n = 10, incorrect answer: jury 636 vs contestant 1530
28 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 39 ms 94288 KB n = 4, 80 is a correct answer
2 Correct 38 ms 94292 KB n = 9, 110 is a correct answer
3 Correct 38 ms 94288 KB n = 4, 21 is a correct answer
4 Correct 39 ms 94296 KB n = 3, 4 is a correct answer
5 Correct 36 ms 94312 KB n = 2, 62 is a correct answer
6 Correct 38 ms 94296 KB n = 2, 3 is a correct answer
7 Correct 38 ms 94288 KB n = 3, 29 is a correct answer
8 Correct 38 ms 94232 KB n = 2, 3 is a correct answer
9 Correct 36 ms 94300 KB n = 2, 3 is a correct answer
10 Correct 38 ms 94304 KB n = 2, 2000000001 is a correct answer
11 Correct 37 ms 94300 KB n = 2, 3000000000 is a correct answer
12 Correct 37 ms 94292 KB n = 3, 3000000000 is a correct answer
13 Correct 37 ms 94364 KB n = 3, 3000000000 is a correct answer
14 Correct 38 ms 94300 KB n = 4, 3000000001 is a correct answer
15 Correct 38 ms 94300 KB n = 4, 4000000000 is a correct answer
16 Correct 38 ms 94292 KB n = 5, 4000000000 is a correct answer
17 Correct 37 ms 94340 KB n = 10, 1000000343 is a correct answer
18 Correct 36 ms 94300 KB n = 10, 3189 is a correct answer
19 Correct 39 ms 94160 KB n = 10, 7000000000 is a correct answer
20 Correct 38 ms 94292 KB n = 5, 12 is a correct answer
21 Correct 39 ms 94288 KB n = 5, 25 is a correct answer
22 Correct 36 ms 94292 KB n = 2, 122 is a correct answer
23 Correct 37 ms 94208 KB n = 10, 117 is a correct answer
24 Correct 38 ms 94292 KB n = 10, 336 is a correct answer
25 Correct 41 ms 94292 KB n = 10, 438 is a correct answer
26 Correct 44 ms 94180 KB n = 10, 206 is a correct answer
27 Incorrect 39 ms 94292 KB n = 10, incorrect answer: jury 636 vs contestant 1530
28 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 39 ms 94288 KB n = 4, 80 is a correct answer
2 Correct 38 ms 94292 KB n = 9, 110 is a correct answer
3 Correct 38 ms 94288 KB n = 4, 21 is a correct answer
4 Correct 39 ms 94296 KB n = 3, 4 is a correct answer
5 Correct 36 ms 94312 KB n = 2, 62 is a correct answer
6 Correct 38 ms 94296 KB n = 2, 3 is a correct answer
7 Correct 38 ms 94288 KB n = 3, 29 is a correct answer
8 Correct 38 ms 94232 KB n = 2, 3 is a correct answer
9 Correct 36 ms 94300 KB n = 2, 3 is a correct answer
10 Correct 38 ms 94304 KB n = 2, 2000000001 is a correct answer
11 Correct 37 ms 94300 KB n = 2, 3000000000 is a correct answer
12 Correct 37 ms 94292 KB n = 3, 3000000000 is a correct answer
13 Correct 37 ms 94364 KB n = 3, 3000000000 is a correct answer
14 Correct 38 ms 94300 KB n = 4, 3000000001 is a correct answer
15 Correct 38 ms 94300 KB n = 4, 4000000000 is a correct answer
16 Correct 38 ms 94292 KB n = 5, 4000000000 is a correct answer
17 Correct 37 ms 94340 KB n = 10, 1000000343 is a correct answer
18 Correct 36 ms 94300 KB n = 10, 3189 is a correct answer
19 Correct 39 ms 94160 KB n = 10, 7000000000 is a correct answer
20 Correct 38 ms 94292 KB n = 5, 12 is a correct answer
21 Correct 39 ms 94288 KB n = 5, 25 is a correct answer
22 Correct 36 ms 94292 KB n = 2, 122 is a correct answer
23 Correct 37 ms 94208 KB n = 10, 117 is a correct answer
24 Correct 38 ms 94292 KB n = 10, 336 is a correct answer
25 Correct 41 ms 94292 KB n = 10, 438 is a correct answer
26 Correct 44 ms 94180 KB n = 10, 206 is a correct answer
27 Incorrect 39 ms 94292 KB n = 10, incorrect answer: jury 636 vs contestant 1530
28 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 39 ms 94288 KB n = 4, 80 is a correct answer
2 Correct 38 ms 94292 KB n = 9, 110 is a correct answer
3 Correct 38 ms 94288 KB n = 4, 21 is a correct answer
4 Correct 39 ms 94296 KB n = 3, 4 is a correct answer
5 Correct 36 ms 94312 KB n = 2, 62 is a correct answer
6 Correct 38 ms 94296 KB n = 2, 3 is a correct answer
7 Correct 38 ms 94288 KB n = 3, 29 is a correct answer
8 Correct 38 ms 94232 KB n = 2, 3 is a correct answer
9 Correct 36 ms 94300 KB n = 2, 3 is a correct answer
10 Correct 38 ms 94304 KB n = 2, 2000000001 is a correct answer
11 Correct 37 ms 94300 KB n = 2, 3000000000 is a correct answer
12 Correct 37 ms 94292 KB n = 3, 3000000000 is a correct answer
13 Correct 37 ms 94364 KB n = 3, 3000000000 is a correct answer
14 Correct 38 ms 94300 KB n = 4, 3000000001 is a correct answer
15 Correct 38 ms 94300 KB n = 4, 4000000000 is a correct answer
16 Correct 38 ms 94292 KB n = 5, 4000000000 is a correct answer
17 Correct 37 ms 94340 KB n = 10, 1000000343 is a correct answer
18 Correct 36 ms 94300 KB n = 10, 3189 is a correct answer
19 Correct 39 ms 94160 KB n = 10, 7000000000 is a correct answer
20 Correct 38 ms 94292 KB n = 5, 12 is a correct answer
21 Correct 39 ms 94288 KB n = 5, 25 is a correct answer
22 Correct 36 ms 94292 KB n = 2, 122 is a correct answer
23 Correct 37 ms 94208 KB n = 10, 117 is a correct answer
24 Correct 38 ms 94292 KB n = 10, 336 is a correct answer
25 Correct 41 ms 94292 KB n = 10, 438 is a correct answer
26 Correct 44 ms 94180 KB n = 10, 206 is a correct answer
27 Incorrect 39 ms 94292 KB n = 10, incorrect answer: jury 636 vs contestant 1530
28 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 39 ms 94288 KB n = 4, 80 is a correct answer
2 Correct 38 ms 94292 KB n = 9, 110 is a correct answer
3 Correct 38 ms 94288 KB n = 4, 21 is a correct answer
4 Correct 39 ms 94296 KB n = 3, 4 is a correct answer
5 Correct 36 ms 94312 KB n = 2, 62 is a correct answer
6 Correct 38 ms 94296 KB n = 2, 3 is a correct answer
7 Correct 38 ms 94288 KB n = 3, 29 is a correct answer
8 Correct 38 ms 94232 KB n = 2, 3 is a correct answer
9 Correct 36 ms 94300 KB n = 2, 3 is a correct answer
10 Correct 38 ms 94304 KB n = 2, 2000000001 is a correct answer
11 Correct 37 ms 94300 KB n = 2, 3000000000 is a correct answer
12 Correct 37 ms 94292 KB n = 3, 3000000000 is a correct answer
13 Correct 37 ms 94364 KB n = 3, 3000000000 is a correct answer
14 Correct 38 ms 94300 KB n = 4, 3000000001 is a correct answer
15 Correct 38 ms 94300 KB n = 4, 4000000000 is a correct answer
16 Correct 38 ms 94292 KB n = 5, 4000000000 is a correct answer
17 Correct 37 ms 94340 KB n = 10, 1000000343 is a correct answer
18 Correct 36 ms 94300 KB n = 10, 3189 is a correct answer
19 Correct 39 ms 94160 KB n = 10, 7000000000 is a correct answer
20 Correct 38 ms 94292 KB n = 5, 12 is a correct answer
21 Correct 39 ms 94288 KB n = 5, 25 is a correct answer
22 Correct 36 ms 94292 KB n = 2, 122 is a correct answer
23 Correct 37 ms 94208 KB n = 10, 117 is a correct answer
24 Correct 38 ms 94292 KB n = 10, 336 is a correct answer
25 Correct 41 ms 94292 KB n = 10, 438 is a correct answer
26 Correct 44 ms 94180 KB n = 10, 206 is a correct answer
27 Incorrect 39 ms 94292 KB n = 10, incorrect answer: jury 636 vs contestant 1530
28 Halted 0 ms 0 KB -