답안 #591793

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
591793 2022-07-07T23:21:26 Z FatihSolak Shortcut (IOI16_shortcut) C++17
0 / 100
14 ms 23804 KB
#include "shortcut.h"
#include <bits/stdc++.h>
#define N 1000005
using namespace std;
long long p[N];
long long d[N];
int n,nwedge;
vector<int> v[N];
vector<pair<long long,int>> a;
vector<pair<long long,int>> b;
bool ck(long long k){
    for(int i = 0;i<=n;i++){
        v[i].clear();
    }
    int pt = n;
    for(int i = 0;i<n;i++){
        while(pt && b[pt-1].first + a[i].first > k){
            pt--;
        }
        if(pt != n)
            v[max(a[i].second+1,b[pt].second)].push_back(a[i].second);
    }
    long long xl = -1e18, xr = 1e18;
    long long yl = -1e18, yr = 1e18;

    long long val1 = -1e18,val2 = 1e18;

    for(int i = 0;i<n;i++){
        for(auto u:v[i]){
            val1 = max(val1,p[u] + d[u]);
            val2 = min(val2,p[u] - d[u]);
        }
        xl = max(xl,+ p[i]  - (k - d[i] - nwedge) + val1);
        xr = min(xr,+ p[i]  + (k - d[i] - nwedge) + val2);
        yl = max(yl,- p[i]  - (k - d[i] - nwedge) + val1);
        yr = min(yr,- p[i]  + (k - d[i] - nwedge) + val2);
        /*
        for(int j = i+1;j<n;j++){
            if(-p[i]  + d[i] + p[j] + d[j] > k){
                xl = max(xl,p[i] + p[j]  - (k - d[i] - d[j] - nwedge));
                xr = min(xr,p[i] + p[j]  + (k - d[i] - d[j] - nwedge));
                yl = max(yl,p[i] - p[j]  - (k - d[i] - d[j] - nwedge));
                yr = min(yr,p[i] - p[j]  + (k - d[i] - d[j] - nwedge));
            }
        }*/
    }
    // cout << k << endl;
    // for(int i = 0;i<n;i++){
    //     cout << p[i] << " ";
    // }
    // cout << endl;
    // cout << xl << " " << xr << " " << yl << " " << yr << endl;
    if(xl > xr || yl > yr)return 0;
    int pt1 = n,pt2 = n-1;
    int pt3 = -1,pt4 = 0;
    for(int i = 0;i<n;i++){
        while(pt1 && p[pt1-1] + p[i] >= xl){
            pt1--;
        }
        while(pt2 &&  p[pt2] + p[i] > xr){
            pt2--;
        }

        while(pt3 + 1 != n && -p[pt3+1] + p[i] >= yl){
            pt3++;
        }
        while(pt4 != n &&  -p[pt4] + p[i] > yr){
            pt4++;
        }

        int l1 = pt1,r1 = pt2;
        int l2 = pt4,r2 = pt3;

        if(r1 < l1 || r2 < l2)continue;
        if(r1 < l2 || r2 < l1)continue;
        
        return 1;
    }
    return 0;
}
long long find_shortcut(int n_, vector<int> l_, vector<int> d_, int nwedge_)
{
    n = n_;
    nwedge = nwedge_;
    for(int i = 1;i<n;i++){
        p[i] = p[i-1] + l_[i-1];
    }
    for(int i = 0;i<n;i++){
        d[i] = d_[i];
    }
    for(int i = 0;i<n;i++){
        a.push_back({-p[i] + d[i],i});
    }
    for(int i = 0;i<n;i++){
        b.push_back({p[i] + d[i],i});
    }
    sort(a.begin(),a.end());
    sort(b.begin(),b.end());
    for(int i = b.size()-2;i>=0;i--){
        b[i].second = min(b[i].second,b[i+1].second);
    }
    long long l = 0, r = 1e18;
    while(l < r){
        long long m = (l + r)/2;
        if(ck(m)){
            r = m;
        }
        else l = m+1;
    }
    return l;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 23764 KB n = 4, 80 is a correct answer
2 Correct 11 ms 23716 KB n = 9, 110 is a correct answer
3 Correct 11 ms 23768 KB n = 4, 21 is a correct answer
4 Correct 11 ms 23764 KB n = 3, 4 is a correct answer
5 Correct 13 ms 23776 KB n = 2, 62 is a correct answer
6 Correct 12 ms 23740 KB n = 2, 3 is a correct answer
7 Correct 14 ms 23764 KB n = 3, 29 is a correct answer
8 Correct 13 ms 23756 KB n = 2, 3 is a correct answer
9 Correct 14 ms 23760 KB n = 2, 3 is a correct answer
10 Correct 14 ms 23764 KB n = 2, 2000000001 is a correct answer
11 Correct 12 ms 23804 KB n = 2, 3000000000 is a correct answer
12 Correct 12 ms 23764 KB n = 3, 3000000000 is a correct answer
13 Correct 12 ms 23764 KB n = 3, 3000000000 is a correct answer
14 Correct 11 ms 23764 KB n = 4, 3000000001 is a correct answer
15 Correct 12 ms 23800 KB n = 4, 4000000000 is a correct answer
16 Correct 11 ms 23764 KB n = 5, 4000000000 is a correct answer
17 Correct 13 ms 23696 KB n = 10, 1000000343 is a correct answer
18 Correct 11 ms 23764 KB n = 10, 3189 is a correct answer
19 Correct 11 ms 23744 KB n = 10, 7000000000 is a correct answer
20 Correct 12 ms 23764 KB n = 5, 12 is a correct answer
21 Correct 12 ms 23764 KB n = 5, 25 is a correct answer
22 Correct 13 ms 23748 KB n = 2, 122 is a correct answer
23 Correct 14 ms 23796 KB n = 10, 117 is a correct answer
24 Correct 12 ms 23772 KB n = 10, 336 is a correct answer
25 Correct 12 ms 23764 KB n = 10, 438 is a correct answer
26 Correct 12 ms 23764 KB n = 10, 206 is a correct answer
27 Correct 12 ms 23708 KB n = 10, 636 is a correct answer
28 Incorrect 11 ms 23764 KB n = 4, incorrect answer: jury 2399 vs contestant 2494
29 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 23764 KB n = 4, 80 is a correct answer
2 Correct 11 ms 23716 KB n = 9, 110 is a correct answer
3 Correct 11 ms 23768 KB n = 4, 21 is a correct answer
4 Correct 11 ms 23764 KB n = 3, 4 is a correct answer
5 Correct 13 ms 23776 KB n = 2, 62 is a correct answer
6 Correct 12 ms 23740 KB n = 2, 3 is a correct answer
7 Correct 14 ms 23764 KB n = 3, 29 is a correct answer
8 Correct 13 ms 23756 KB n = 2, 3 is a correct answer
9 Correct 14 ms 23760 KB n = 2, 3 is a correct answer
10 Correct 14 ms 23764 KB n = 2, 2000000001 is a correct answer
11 Correct 12 ms 23804 KB n = 2, 3000000000 is a correct answer
12 Correct 12 ms 23764 KB n = 3, 3000000000 is a correct answer
13 Correct 12 ms 23764 KB n = 3, 3000000000 is a correct answer
14 Correct 11 ms 23764 KB n = 4, 3000000001 is a correct answer
15 Correct 12 ms 23800 KB n = 4, 4000000000 is a correct answer
16 Correct 11 ms 23764 KB n = 5, 4000000000 is a correct answer
17 Correct 13 ms 23696 KB n = 10, 1000000343 is a correct answer
18 Correct 11 ms 23764 KB n = 10, 3189 is a correct answer
19 Correct 11 ms 23744 KB n = 10, 7000000000 is a correct answer
20 Correct 12 ms 23764 KB n = 5, 12 is a correct answer
21 Correct 12 ms 23764 KB n = 5, 25 is a correct answer
22 Correct 13 ms 23748 KB n = 2, 122 is a correct answer
23 Correct 14 ms 23796 KB n = 10, 117 is a correct answer
24 Correct 12 ms 23772 KB n = 10, 336 is a correct answer
25 Correct 12 ms 23764 KB n = 10, 438 is a correct answer
26 Correct 12 ms 23764 KB n = 10, 206 is a correct answer
27 Correct 12 ms 23708 KB n = 10, 636 is a correct answer
28 Incorrect 11 ms 23764 KB n = 4, incorrect answer: jury 2399 vs contestant 2494
29 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 23764 KB n = 4, 80 is a correct answer
2 Correct 11 ms 23716 KB n = 9, 110 is a correct answer
3 Correct 11 ms 23768 KB n = 4, 21 is a correct answer
4 Correct 11 ms 23764 KB n = 3, 4 is a correct answer
5 Correct 13 ms 23776 KB n = 2, 62 is a correct answer
6 Correct 12 ms 23740 KB n = 2, 3 is a correct answer
7 Correct 14 ms 23764 KB n = 3, 29 is a correct answer
8 Correct 13 ms 23756 KB n = 2, 3 is a correct answer
9 Correct 14 ms 23760 KB n = 2, 3 is a correct answer
10 Correct 14 ms 23764 KB n = 2, 2000000001 is a correct answer
11 Correct 12 ms 23804 KB n = 2, 3000000000 is a correct answer
12 Correct 12 ms 23764 KB n = 3, 3000000000 is a correct answer
13 Correct 12 ms 23764 KB n = 3, 3000000000 is a correct answer
14 Correct 11 ms 23764 KB n = 4, 3000000001 is a correct answer
15 Correct 12 ms 23800 KB n = 4, 4000000000 is a correct answer
16 Correct 11 ms 23764 KB n = 5, 4000000000 is a correct answer
17 Correct 13 ms 23696 KB n = 10, 1000000343 is a correct answer
18 Correct 11 ms 23764 KB n = 10, 3189 is a correct answer
19 Correct 11 ms 23744 KB n = 10, 7000000000 is a correct answer
20 Correct 12 ms 23764 KB n = 5, 12 is a correct answer
21 Correct 12 ms 23764 KB n = 5, 25 is a correct answer
22 Correct 13 ms 23748 KB n = 2, 122 is a correct answer
23 Correct 14 ms 23796 KB n = 10, 117 is a correct answer
24 Correct 12 ms 23772 KB n = 10, 336 is a correct answer
25 Correct 12 ms 23764 KB n = 10, 438 is a correct answer
26 Correct 12 ms 23764 KB n = 10, 206 is a correct answer
27 Correct 12 ms 23708 KB n = 10, 636 is a correct answer
28 Incorrect 11 ms 23764 KB n = 4, incorrect answer: jury 2399 vs contestant 2494
29 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 23764 KB n = 4, 80 is a correct answer
2 Correct 11 ms 23716 KB n = 9, 110 is a correct answer
3 Correct 11 ms 23768 KB n = 4, 21 is a correct answer
4 Correct 11 ms 23764 KB n = 3, 4 is a correct answer
5 Correct 13 ms 23776 KB n = 2, 62 is a correct answer
6 Correct 12 ms 23740 KB n = 2, 3 is a correct answer
7 Correct 14 ms 23764 KB n = 3, 29 is a correct answer
8 Correct 13 ms 23756 KB n = 2, 3 is a correct answer
9 Correct 14 ms 23760 KB n = 2, 3 is a correct answer
10 Correct 14 ms 23764 KB n = 2, 2000000001 is a correct answer
11 Correct 12 ms 23804 KB n = 2, 3000000000 is a correct answer
12 Correct 12 ms 23764 KB n = 3, 3000000000 is a correct answer
13 Correct 12 ms 23764 KB n = 3, 3000000000 is a correct answer
14 Correct 11 ms 23764 KB n = 4, 3000000001 is a correct answer
15 Correct 12 ms 23800 KB n = 4, 4000000000 is a correct answer
16 Correct 11 ms 23764 KB n = 5, 4000000000 is a correct answer
17 Correct 13 ms 23696 KB n = 10, 1000000343 is a correct answer
18 Correct 11 ms 23764 KB n = 10, 3189 is a correct answer
19 Correct 11 ms 23744 KB n = 10, 7000000000 is a correct answer
20 Correct 12 ms 23764 KB n = 5, 12 is a correct answer
21 Correct 12 ms 23764 KB n = 5, 25 is a correct answer
22 Correct 13 ms 23748 KB n = 2, 122 is a correct answer
23 Correct 14 ms 23796 KB n = 10, 117 is a correct answer
24 Correct 12 ms 23772 KB n = 10, 336 is a correct answer
25 Correct 12 ms 23764 KB n = 10, 438 is a correct answer
26 Correct 12 ms 23764 KB n = 10, 206 is a correct answer
27 Correct 12 ms 23708 KB n = 10, 636 is a correct answer
28 Incorrect 11 ms 23764 KB n = 4, incorrect answer: jury 2399 vs contestant 2494
29 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 23764 KB n = 4, 80 is a correct answer
2 Correct 11 ms 23716 KB n = 9, 110 is a correct answer
3 Correct 11 ms 23768 KB n = 4, 21 is a correct answer
4 Correct 11 ms 23764 KB n = 3, 4 is a correct answer
5 Correct 13 ms 23776 KB n = 2, 62 is a correct answer
6 Correct 12 ms 23740 KB n = 2, 3 is a correct answer
7 Correct 14 ms 23764 KB n = 3, 29 is a correct answer
8 Correct 13 ms 23756 KB n = 2, 3 is a correct answer
9 Correct 14 ms 23760 KB n = 2, 3 is a correct answer
10 Correct 14 ms 23764 KB n = 2, 2000000001 is a correct answer
11 Correct 12 ms 23804 KB n = 2, 3000000000 is a correct answer
12 Correct 12 ms 23764 KB n = 3, 3000000000 is a correct answer
13 Correct 12 ms 23764 KB n = 3, 3000000000 is a correct answer
14 Correct 11 ms 23764 KB n = 4, 3000000001 is a correct answer
15 Correct 12 ms 23800 KB n = 4, 4000000000 is a correct answer
16 Correct 11 ms 23764 KB n = 5, 4000000000 is a correct answer
17 Correct 13 ms 23696 KB n = 10, 1000000343 is a correct answer
18 Correct 11 ms 23764 KB n = 10, 3189 is a correct answer
19 Correct 11 ms 23744 KB n = 10, 7000000000 is a correct answer
20 Correct 12 ms 23764 KB n = 5, 12 is a correct answer
21 Correct 12 ms 23764 KB n = 5, 25 is a correct answer
22 Correct 13 ms 23748 KB n = 2, 122 is a correct answer
23 Correct 14 ms 23796 KB n = 10, 117 is a correct answer
24 Correct 12 ms 23772 KB n = 10, 336 is a correct answer
25 Correct 12 ms 23764 KB n = 10, 438 is a correct answer
26 Correct 12 ms 23764 KB n = 10, 206 is a correct answer
27 Correct 12 ms 23708 KB n = 10, 636 is a correct answer
28 Incorrect 11 ms 23764 KB n = 4, incorrect answer: jury 2399 vs contestant 2494
29 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 23764 KB n = 4, 80 is a correct answer
2 Correct 11 ms 23716 KB n = 9, 110 is a correct answer
3 Correct 11 ms 23768 KB n = 4, 21 is a correct answer
4 Correct 11 ms 23764 KB n = 3, 4 is a correct answer
5 Correct 13 ms 23776 KB n = 2, 62 is a correct answer
6 Correct 12 ms 23740 KB n = 2, 3 is a correct answer
7 Correct 14 ms 23764 KB n = 3, 29 is a correct answer
8 Correct 13 ms 23756 KB n = 2, 3 is a correct answer
9 Correct 14 ms 23760 KB n = 2, 3 is a correct answer
10 Correct 14 ms 23764 KB n = 2, 2000000001 is a correct answer
11 Correct 12 ms 23804 KB n = 2, 3000000000 is a correct answer
12 Correct 12 ms 23764 KB n = 3, 3000000000 is a correct answer
13 Correct 12 ms 23764 KB n = 3, 3000000000 is a correct answer
14 Correct 11 ms 23764 KB n = 4, 3000000001 is a correct answer
15 Correct 12 ms 23800 KB n = 4, 4000000000 is a correct answer
16 Correct 11 ms 23764 KB n = 5, 4000000000 is a correct answer
17 Correct 13 ms 23696 KB n = 10, 1000000343 is a correct answer
18 Correct 11 ms 23764 KB n = 10, 3189 is a correct answer
19 Correct 11 ms 23744 KB n = 10, 7000000000 is a correct answer
20 Correct 12 ms 23764 KB n = 5, 12 is a correct answer
21 Correct 12 ms 23764 KB n = 5, 25 is a correct answer
22 Correct 13 ms 23748 KB n = 2, 122 is a correct answer
23 Correct 14 ms 23796 KB n = 10, 117 is a correct answer
24 Correct 12 ms 23772 KB n = 10, 336 is a correct answer
25 Correct 12 ms 23764 KB n = 10, 438 is a correct answer
26 Correct 12 ms 23764 KB n = 10, 206 is a correct answer
27 Correct 12 ms 23708 KB n = 10, 636 is a correct answer
28 Incorrect 11 ms 23764 KB n = 4, incorrect answer: jury 2399 vs contestant 2494
29 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 23764 KB n = 4, 80 is a correct answer
2 Correct 11 ms 23716 KB n = 9, 110 is a correct answer
3 Correct 11 ms 23768 KB n = 4, 21 is a correct answer
4 Correct 11 ms 23764 KB n = 3, 4 is a correct answer
5 Correct 13 ms 23776 KB n = 2, 62 is a correct answer
6 Correct 12 ms 23740 KB n = 2, 3 is a correct answer
7 Correct 14 ms 23764 KB n = 3, 29 is a correct answer
8 Correct 13 ms 23756 KB n = 2, 3 is a correct answer
9 Correct 14 ms 23760 KB n = 2, 3 is a correct answer
10 Correct 14 ms 23764 KB n = 2, 2000000001 is a correct answer
11 Correct 12 ms 23804 KB n = 2, 3000000000 is a correct answer
12 Correct 12 ms 23764 KB n = 3, 3000000000 is a correct answer
13 Correct 12 ms 23764 KB n = 3, 3000000000 is a correct answer
14 Correct 11 ms 23764 KB n = 4, 3000000001 is a correct answer
15 Correct 12 ms 23800 KB n = 4, 4000000000 is a correct answer
16 Correct 11 ms 23764 KB n = 5, 4000000000 is a correct answer
17 Correct 13 ms 23696 KB n = 10, 1000000343 is a correct answer
18 Correct 11 ms 23764 KB n = 10, 3189 is a correct answer
19 Correct 11 ms 23744 KB n = 10, 7000000000 is a correct answer
20 Correct 12 ms 23764 KB n = 5, 12 is a correct answer
21 Correct 12 ms 23764 KB n = 5, 25 is a correct answer
22 Correct 13 ms 23748 KB n = 2, 122 is a correct answer
23 Correct 14 ms 23796 KB n = 10, 117 is a correct answer
24 Correct 12 ms 23772 KB n = 10, 336 is a correct answer
25 Correct 12 ms 23764 KB n = 10, 438 is a correct answer
26 Correct 12 ms 23764 KB n = 10, 206 is a correct answer
27 Correct 12 ms 23708 KB n = 10, 636 is a correct answer
28 Incorrect 11 ms 23764 KB n = 4, incorrect answer: jury 2399 vs contestant 2494
29 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 23764 KB n = 4, 80 is a correct answer
2 Correct 11 ms 23716 KB n = 9, 110 is a correct answer
3 Correct 11 ms 23768 KB n = 4, 21 is a correct answer
4 Correct 11 ms 23764 KB n = 3, 4 is a correct answer
5 Correct 13 ms 23776 KB n = 2, 62 is a correct answer
6 Correct 12 ms 23740 KB n = 2, 3 is a correct answer
7 Correct 14 ms 23764 KB n = 3, 29 is a correct answer
8 Correct 13 ms 23756 KB n = 2, 3 is a correct answer
9 Correct 14 ms 23760 KB n = 2, 3 is a correct answer
10 Correct 14 ms 23764 KB n = 2, 2000000001 is a correct answer
11 Correct 12 ms 23804 KB n = 2, 3000000000 is a correct answer
12 Correct 12 ms 23764 KB n = 3, 3000000000 is a correct answer
13 Correct 12 ms 23764 KB n = 3, 3000000000 is a correct answer
14 Correct 11 ms 23764 KB n = 4, 3000000001 is a correct answer
15 Correct 12 ms 23800 KB n = 4, 4000000000 is a correct answer
16 Correct 11 ms 23764 KB n = 5, 4000000000 is a correct answer
17 Correct 13 ms 23696 KB n = 10, 1000000343 is a correct answer
18 Correct 11 ms 23764 KB n = 10, 3189 is a correct answer
19 Correct 11 ms 23744 KB n = 10, 7000000000 is a correct answer
20 Correct 12 ms 23764 KB n = 5, 12 is a correct answer
21 Correct 12 ms 23764 KB n = 5, 25 is a correct answer
22 Correct 13 ms 23748 KB n = 2, 122 is a correct answer
23 Correct 14 ms 23796 KB n = 10, 117 is a correct answer
24 Correct 12 ms 23772 KB n = 10, 336 is a correct answer
25 Correct 12 ms 23764 KB n = 10, 438 is a correct answer
26 Correct 12 ms 23764 KB n = 10, 206 is a correct answer
27 Correct 12 ms 23708 KB n = 10, 636 is a correct answer
28 Incorrect 11 ms 23764 KB n = 4, incorrect answer: jury 2399 vs contestant 2494
29 Halted 0 ms 0 KB -