Submission #832631

# Submission time Handle Problem Language Result Execution time Memory
832631 2023-08-21T12:48:06 Z Kerim Shortcut (IOI16_shortcut) C++17
0 / 100
1 ms 212 KB
#include "shortcut.h"
#include "bits/stdc++.h"
#define ff first
#define ss second
#define ll long long
using namespace std;
typedef pair<ll, ll> pll;
//x+y, y-x (45 degrees rotation)
//|x-xx|+|y-yy| -> max(|x-xx|, |y-yy|)
const ll INF = 1e18;
const ll N = 1e6+6;
vector<ll> id;
int sz;
int get_id(ll x){
    return 1 + int(lower_bound(id.begin(), id.end(), x) - id.begin());
}
struct node{
    ll x, y, xx, yy;
    node(){}
    node(ll _x, ll _y, ll _xx, ll _yy){
        x = _x; y = _y; yy = _yy; xx = _xx;
    }
}F[N];

node merge(node a, node b){
    return node(max(a.x, b.x), max(a.y, b.y), min(a.xx, b.xx), min(a.yy, b.yy));
}

node get(int x){
    node ans = node(-INF, -INF, INF, INF);
    for (; x <= sz; x += x&(-x))
        ans = merge(ans, F[x]);
    return ans;
}
void upd(int x, node v){
    for (;x;x -= x&(-x))
        F[x] = merge(F[x], v);
}

set<ll> s;
bool check(ll k, vector<int> &d, int c, vector<ll>&p){
    for (int i = 0; i <= sz; i++)
        F[i] = node(-INF, -INF, INF, INF);
    s.clear();
    int n = d.size();
    ll X = -INF, Y = -INF;
    ll XX = INF, YY = INF;
    for (int j = 0; j < n; j++){
        int b = get_id(-d[j] - p[j]+k+1);
        node value = get(b);
        X = max(X, value.x + p[j] -k + c + d[j]);
        Y = max(Y, value.y + p[j] -k + c + d[j]);
        XX = min(XX, value.xx + p[j] + k - c - d[j]);
        YY = min(YY, value.yy + p[j] + k - c - d[j]);
        int i = j;
        int a = get_id(d[i] - p[i]);
        upd(a, node(p[i] + d[i], -p[i] + d[i], p[i] - d[i], -p[i] - d[i]));
    }

    if (X > XX or Y > YY)
        return 0;

    for (int j = 0; j < n; j++){
        ll l = max(X - p[j], -YY + p[j]);
        ll r = max(XX - p[j], -Y + p[j]);
        auto it = s.lower_bound(l);
        if (it != s.end() and *it <= r)
            return 1;
        s.insert(p[j]);
    }
    return 0;
}
ll find_shortcut(int n, vector<int> l, vector<int> d, int c){
    vector<ll> p(n);
    for (int i = 0; i < n-1; i++)
        p[i+1] = p[i] + l[i];
    for (int j = 0; j < n; j++)
        id.push_back(d[j] - p[j]);
    sort(id.begin(), id.end());
    id.erase(unique(id.begin(), id.end()), id.end());
    sz = id.size();
    ll st = 0, en = INF;
    while (st < en){
        ll mid = (st+en) >> 1;
        if (check(mid, d, c, p))
            en = mid;
        else 
            st = mid + 1;
    }
    return st;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB n = 4, 80 is a correct answer
2 Correct 0 ms 212 KB n = 9, 110 is a correct answer
3 Correct 0 ms 212 KB n = 4, 21 is a correct answer
4 Correct 0 ms 212 KB n = 3, 4 is a correct answer
5 Correct 0 ms 212 KB n = 2, 62 is a correct answer
6 Correct 0 ms 212 KB n = 2, 3 is a correct answer
7 Correct 0 ms 212 KB n = 3, 29 is a correct answer
8 Correct 0 ms 212 KB n = 2, 3 is a correct answer
9 Correct 0 ms 212 KB n = 2, 3 is a correct answer
10 Correct 0 ms 212 KB n = 2, 2000000001 is a correct answer
11 Correct 0 ms 212 KB n = 2, 3000000000 is a correct answer
12 Correct 0 ms 212 KB n = 3, 3000000000 is a correct answer
13 Correct 0 ms 212 KB n = 3, 3000000000 is a correct answer
14 Correct 0 ms 212 KB n = 4, 3000000001 is a correct answer
15 Correct 0 ms 212 KB n = 4, 4000000000 is a correct answer
16 Correct 0 ms 212 KB n = 5, 4000000000 is a correct answer
17 Incorrect 0 ms 212 KB n = 10, incorrect answer: jury 1000000343 vs contestant 1000000318
18 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB n = 4, 80 is a correct answer
2 Correct 0 ms 212 KB n = 9, 110 is a correct answer
3 Correct 0 ms 212 KB n = 4, 21 is a correct answer
4 Correct 0 ms 212 KB n = 3, 4 is a correct answer
5 Correct 0 ms 212 KB n = 2, 62 is a correct answer
6 Correct 0 ms 212 KB n = 2, 3 is a correct answer
7 Correct 0 ms 212 KB n = 3, 29 is a correct answer
8 Correct 0 ms 212 KB n = 2, 3 is a correct answer
9 Correct 0 ms 212 KB n = 2, 3 is a correct answer
10 Correct 0 ms 212 KB n = 2, 2000000001 is a correct answer
11 Correct 0 ms 212 KB n = 2, 3000000000 is a correct answer
12 Correct 0 ms 212 KB n = 3, 3000000000 is a correct answer
13 Correct 0 ms 212 KB n = 3, 3000000000 is a correct answer
14 Correct 0 ms 212 KB n = 4, 3000000001 is a correct answer
15 Correct 0 ms 212 KB n = 4, 4000000000 is a correct answer
16 Correct 0 ms 212 KB n = 5, 4000000000 is a correct answer
17 Incorrect 0 ms 212 KB n = 10, incorrect answer: jury 1000000343 vs contestant 1000000318
18 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB n = 4, 80 is a correct answer
2 Correct 0 ms 212 KB n = 9, 110 is a correct answer
3 Correct 0 ms 212 KB n = 4, 21 is a correct answer
4 Correct 0 ms 212 KB n = 3, 4 is a correct answer
5 Correct 0 ms 212 KB n = 2, 62 is a correct answer
6 Correct 0 ms 212 KB n = 2, 3 is a correct answer
7 Correct 0 ms 212 KB n = 3, 29 is a correct answer
8 Correct 0 ms 212 KB n = 2, 3 is a correct answer
9 Correct 0 ms 212 KB n = 2, 3 is a correct answer
10 Correct 0 ms 212 KB n = 2, 2000000001 is a correct answer
11 Correct 0 ms 212 KB n = 2, 3000000000 is a correct answer
12 Correct 0 ms 212 KB n = 3, 3000000000 is a correct answer
13 Correct 0 ms 212 KB n = 3, 3000000000 is a correct answer
14 Correct 0 ms 212 KB n = 4, 3000000001 is a correct answer
15 Correct 0 ms 212 KB n = 4, 4000000000 is a correct answer
16 Correct 0 ms 212 KB n = 5, 4000000000 is a correct answer
17 Incorrect 0 ms 212 KB n = 10, incorrect answer: jury 1000000343 vs contestant 1000000318
18 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB n = 4, 80 is a correct answer
2 Correct 0 ms 212 KB n = 9, 110 is a correct answer
3 Correct 0 ms 212 KB n = 4, 21 is a correct answer
4 Correct 0 ms 212 KB n = 3, 4 is a correct answer
5 Correct 0 ms 212 KB n = 2, 62 is a correct answer
6 Correct 0 ms 212 KB n = 2, 3 is a correct answer
7 Correct 0 ms 212 KB n = 3, 29 is a correct answer
8 Correct 0 ms 212 KB n = 2, 3 is a correct answer
9 Correct 0 ms 212 KB n = 2, 3 is a correct answer
10 Correct 0 ms 212 KB n = 2, 2000000001 is a correct answer
11 Correct 0 ms 212 KB n = 2, 3000000000 is a correct answer
12 Correct 0 ms 212 KB n = 3, 3000000000 is a correct answer
13 Correct 0 ms 212 KB n = 3, 3000000000 is a correct answer
14 Correct 0 ms 212 KB n = 4, 3000000001 is a correct answer
15 Correct 0 ms 212 KB n = 4, 4000000000 is a correct answer
16 Correct 0 ms 212 KB n = 5, 4000000000 is a correct answer
17 Incorrect 0 ms 212 KB n = 10, incorrect answer: jury 1000000343 vs contestant 1000000318
18 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB n = 4, 80 is a correct answer
2 Correct 0 ms 212 KB n = 9, 110 is a correct answer
3 Correct 0 ms 212 KB n = 4, 21 is a correct answer
4 Correct 0 ms 212 KB n = 3, 4 is a correct answer
5 Correct 0 ms 212 KB n = 2, 62 is a correct answer
6 Correct 0 ms 212 KB n = 2, 3 is a correct answer
7 Correct 0 ms 212 KB n = 3, 29 is a correct answer
8 Correct 0 ms 212 KB n = 2, 3 is a correct answer
9 Correct 0 ms 212 KB n = 2, 3 is a correct answer
10 Correct 0 ms 212 KB n = 2, 2000000001 is a correct answer
11 Correct 0 ms 212 KB n = 2, 3000000000 is a correct answer
12 Correct 0 ms 212 KB n = 3, 3000000000 is a correct answer
13 Correct 0 ms 212 KB n = 3, 3000000000 is a correct answer
14 Correct 0 ms 212 KB n = 4, 3000000001 is a correct answer
15 Correct 0 ms 212 KB n = 4, 4000000000 is a correct answer
16 Correct 0 ms 212 KB n = 5, 4000000000 is a correct answer
17 Incorrect 0 ms 212 KB n = 10, incorrect answer: jury 1000000343 vs contestant 1000000318
18 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB n = 4, 80 is a correct answer
2 Correct 0 ms 212 KB n = 9, 110 is a correct answer
3 Correct 0 ms 212 KB n = 4, 21 is a correct answer
4 Correct 0 ms 212 KB n = 3, 4 is a correct answer
5 Correct 0 ms 212 KB n = 2, 62 is a correct answer
6 Correct 0 ms 212 KB n = 2, 3 is a correct answer
7 Correct 0 ms 212 KB n = 3, 29 is a correct answer
8 Correct 0 ms 212 KB n = 2, 3 is a correct answer
9 Correct 0 ms 212 KB n = 2, 3 is a correct answer
10 Correct 0 ms 212 KB n = 2, 2000000001 is a correct answer
11 Correct 0 ms 212 KB n = 2, 3000000000 is a correct answer
12 Correct 0 ms 212 KB n = 3, 3000000000 is a correct answer
13 Correct 0 ms 212 KB n = 3, 3000000000 is a correct answer
14 Correct 0 ms 212 KB n = 4, 3000000001 is a correct answer
15 Correct 0 ms 212 KB n = 4, 4000000000 is a correct answer
16 Correct 0 ms 212 KB n = 5, 4000000000 is a correct answer
17 Incorrect 0 ms 212 KB n = 10, incorrect answer: jury 1000000343 vs contestant 1000000318
18 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB n = 4, 80 is a correct answer
2 Correct 0 ms 212 KB n = 9, 110 is a correct answer
3 Correct 0 ms 212 KB n = 4, 21 is a correct answer
4 Correct 0 ms 212 KB n = 3, 4 is a correct answer
5 Correct 0 ms 212 KB n = 2, 62 is a correct answer
6 Correct 0 ms 212 KB n = 2, 3 is a correct answer
7 Correct 0 ms 212 KB n = 3, 29 is a correct answer
8 Correct 0 ms 212 KB n = 2, 3 is a correct answer
9 Correct 0 ms 212 KB n = 2, 3 is a correct answer
10 Correct 0 ms 212 KB n = 2, 2000000001 is a correct answer
11 Correct 0 ms 212 KB n = 2, 3000000000 is a correct answer
12 Correct 0 ms 212 KB n = 3, 3000000000 is a correct answer
13 Correct 0 ms 212 KB n = 3, 3000000000 is a correct answer
14 Correct 0 ms 212 KB n = 4, 3000000001 is a correct answer
15 Correct 0 ms 212 KB n = 4, 4000000000 is a correct answer
16 Correct 0 ms 212 KB n = 5, 4000000000 is a correct answer
17 Incorrect 0 ms 212 KB n = 10, incorrect answer: jury 1000000343 vs contestant 1000000318
18 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB n = 4, 80 is a correct answer
2 Correct 0 ms 212 KB n = 9, 110 is a correct answer
3 Correct 0 ms 212 KB n = 4, 21 is a correct answer
4 Correct 0 ms 212 KB n = 3, 4 is a correct answer
5 Correct 0 ms 212 KB n = 2, 62 is a correct answer
6 Correct 0 ms 212 KB n = 2, 3 is a correct answer
7 Correct 0 ms 212 KB n = 3, 29 is a correct answer
8 Correct 0 ms 212 KB n = 2, 3 is a correct answer
9 Correct 0 ms 212 KB n = 2, 3 is a correct answer
10 Correct 0 ms 212 KB n = 2, 2000000001 is a correct answer
11 Correct 0 ms 212 KB n = 2, 3000000000 is a correct answer
12 Correct 0 ms 212 KB n = 3, 3000000000 is a correct answer
13 Correct 0 ms 212 KB n = 3, 3000000000 is a correct answer
14 Correct 0 ms 212 KB n = 4, 3000000001 is a correct answer
15 Correct 0 ms 212 KB n = 4, 4000000000 is a correct answer
16 Correct 0 ms 212 KB n = 5, 4000000000 is a correct answer
17 Incorrect 0 ms 212 KB n = 10, incorrect answer: jury 1000000343 vs contestant 1000000318
18 Halted 0 ms 0 KB -