답안 #832618

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
832618 2023-08-21T12:41:10 Z Kerim Shortcut (IOI16_shortcut) C++17
0 / 100
1 ms 312 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);
}
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);
    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]);
        node value = get(b+1);
        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] - k);
        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 i = 0; i < n; i++)
        for (int j = i + 1; j < n; j++){
            ll x = p[i] + p[j], y = p[j] - p[i];
            if (X <= x and x <= XX and Y <= y and y <= YY)
                return 1;
        }
    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 312 KB n = 9, 110 is a correct answer
3 Correct 1 ms 212 KB n = 4, 21 is a correct answer
4 Correct 1 ms 308 KB n = 3, 4 is a correct answer
5 Incorrect 0 ms 212 KB n = 2, incorrect answer: jury 62 vs contestant 0
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 312 KB n = 9, 110 is a correct answer
3 Correct 1 ms 212 KB n = 4, 21 is a correct answer
4 Correct 1 ms 308 KB n = 3, 4 is a correct answer
5 Incorrect 0 ms 212 KB n = 2, incorrect answer: jury 62 vs contestant 0
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 312 KB n = 9, 110 is a correct answer
3 Correct 1 ms 212 KB n = 4, 21 is a correct answer
4 Correct 1 ms 308 KB n = 3, 4 is a correct answer
5 Incorrect 0 ms 212 KB n = 2, incorrect answer: jury 62 vs contestant 0
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 312 KB n = 9, 110 is a correct answer
3 Correct 1 ms 212 KB n = 4, 21 is a correct answer
4 Correct 1 ms 308 KB n = 3, 4 is a correct answer
5 Incorrect 0 ms 212 KB n = 2, incorrect answer: jury 62 vs contestant 0
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 312 KB n = 9, 110 is a correct answer
3 Correct 1 ms 212 KB n = 4, 21 is a correct answer
4 Correct 1 ms 308 KB n = 3, 4 is a correct answer
5 Incorrect 0 ms 212 KB n = 2, incorrect answer: jury 62 vs contestant 0
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 312 KB n = 9, 110 is a correct answer
3 Correct 1 ms 212 KB n = 4, 21 is a correct answer
4 Correct 1 ms 308 KB n = 3, 4 is a correct answer
5 Incorrect 0 ms 212 KB n = 2, incorrect answer: jury 62 vs contestant 0
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 312 KB n = 9, 110 is a correct answer
3 Correct 1 ms 212 KB n = 4, 21 is a correct answer
4 Correct 1 ms 308 KB n = 3, 4 is a correct answer
5 Incorrect 0 ms 212 KB n = 2, incorrect answer: jury 62 vs contestant 0
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 312 KB n = 9, 110 is a correct answer
3 Correct 1 ms 212 KB n = 4, 21 is a correct answer
4 Correct 1 ms 308 KB n = 3, 4 is a correct answer
5 Incorrect 0 ms 212 KB n = 2, incorrect answer: jury 62 vs contestant 0
6 Halted 0 ms 0 KB -