답안 #832644

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
832644 2023-08-21T12:53:50 Z Kerim Shortcut (IOI16_shortcut) C++17
0 / 100
1 ms 308 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;
        // (p[j] +  d[j]) - (p[i] - d[i]) > k
    for (int i = 0; i < n; i++){
        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]));
    }
    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]);
    }

    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 = min(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;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB n = 4, 80 is a correct answer
2 Correct 0 ms 308 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 Incorrect 0 ms 212 KB n = 2, incorrect answer: jury 62 vs contestant 72
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB n = 4, 80 is a correct answer
2 Correct 0 ms 308 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 Incorrect 0 ms 212 KB n = 2, incorrect answer: jury 62 vs contestant 72
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB n = 4, 80 is a correct answer
2 Correct 0 ms 308 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 Incorrect 0 ms 212 KB n = 2, incorrect answer: jury 62 vs contestant 72
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB n = 4, 80 is a correct answer
2 Correct 0 ms 308 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 Incorrect 0 ms 212 KB n = 2, incorrect answer: jury 62 vs contestant 72
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB n = 4, 80 is a correct answer
2 Correct 0 ms 308 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 Incorrect 0 ms 212 KB n = 2, incorrect answer: jury 62 vs contestant 72
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB n = 4, 80 is a correct answer
2 Correct 0 ms 308 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 Incorrect 0 ms 212 KB n = 2, incorrect answer: jury 62 vs contestant 72
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB n = 4, 80 is a correct answer
2 Correct 0 ms 308 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 Incorrect 0 ms 212 KB n = 2, incorrect answer: jury 62 vs contestant 72
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB n = 4, 80 is a correct answer
2 Correct 0 ms 308 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 Incorrect 0 ms 212 KB n = 2, incorrect answer: jury 62 vs contestant 72
6 Halted 0 ms 0 KB -