답안 #805855

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
805855 2023-08-04T01:12:14 Z resting Shortcut (IOI16_shortcut) C++17
0 / 100
1 ms 292 KB
//#include "shortcut.h"
#include <bits/stdc++.h>
using namespace std;
#define ll long long

const ll inf = 1e18;
ll find_shortcut(int n, vector<int> l, vector<int> d, int c) {
    vector<int> p(n, 0);
    for (int i = 1; i < n; i++) p[i] = p[i - 1] + l[i - 1];

    vector<int> distl(n, 0), distr(n, 0);
    int cur = 0;
    for (int i = 0; i < n; i++) {
        distl[i] = cur + d[i];
        if (i) distl[i] = max(distl[i], distl[i - 1]);
        cur = max(cur, d[i]);
        if (i + 1 < n)
            cur += l[i];
    }
    cur = 0;
    for (int i = n - 1; i >= 0; i--) {
        distr[i] = cur + d[i];
        if (i != n - 1) distr[i] = max(distr[i], distr[i + 1]);
        cur = max(cur, d[i]);
        if (i)
            cur += l[i - 1];
    }

    int mxmn = 0;
    for (int i = 0; i < n; i++) {
        mxmn = max(mxmn, min(distl[i], distr[i]));
    }

    vector<pair<ll, int>> partl, partr; //partition left, right
    int mud = 0;
    for (int i = 0; i < n; i++) {
        if (distl[i] == mxmn) {
            partl.push_back({ d[i], i });
            mud = p[i];
            break;
        }

        if (distr[i] == mxmn) {
            partr.push_back({ d[i], i });
            mud = p[i];
            break;
        }
    }

    for (int i = 0; i < n; i++) {
        if (p[i] < mud) partl.push_back({ mud - p[i] + d[i], i });
        if (p[i] > mud) partr.push_back({ p[i] - mud + d[i], i });
    }

    sort(partl.begin(), partl.end());
    sort(partr.begin(), partr.end());



    ll left = mxmn - 1, right = 3e9 + 5;
    while (right - left > 1) {
        ll mid = (left + right) / 2;
        ll x1 = -inf, x2 = inf, y1 = -inf, y2 = inf;


        ll rangl = -2e9, rangr = 2e9;
        int cur = partr.size() - 1;
        for (int i = 0; i < partl.size(); i++) {
            while (cur >= 0 && partr[cur].first + partl[i].first > mid) {
                rangl = max(rangl, (ll)p[partr[cur].second] - (mid - c - d[partr[cur].second]));
                rangr = min(rangr, (ll)p[partr[cur].second] + (mid - c - d[partr[cur].second]));
                //cout << "bruh" << (mid - c - d[partr[cur].second]) << endl;
                cur--;
            }
            //cout << mid << "," << rangl << "," << rangr << endl;
            // {p[i], rangl}, {p[i], rangr}
            //rangr > rangl
            //(x, y) -> (x + y, x - y)
            rangl += d[partl[i].second]; rangr -= d[partl[i].second];
            x1 = max(x1, p[partl[i].second] + rangl);
            x2 = min(x2, p[partl[i].second] + rangr);
            y1 = max(y1, p[partl[i].second] - rangr);
            y2 = min(y2, p[partl[i].second] - rangl);
            rangl -= d[partl[i].second]; rangr += d[partl[i].second];
        }
        if (x1 <= x2 && y1 <= y2) right = mid;
        else left = mid;
    }
    return right;
}

// int main() {
//     cout << find_shortcut(2, { (int)1e9 }, { (int)1e9, (int)1e9 }, 1) << endl;
// }

Compilation message

shortcut.cpp: In function 'long long int find_shortcut(int, std::vector<int>, std::vector<int>, int)':
shortcut.cpp:68:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   68 |         for (int i = 0; i < partl.size(); i++) {
      |                         ~~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 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 1 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 1 ms 292 KB n = 2, 3000000000 is a correct answer
12 Incorrect 1 ms 212 KB n = 3, incorrect answer: jury 3000000000 vs contestant 2000000001
13 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 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 1 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 1 ms 292 KB n = 2, 3000000000 is a correct answer
12 Incorrect 1 ms 212 KB n = 3, incorrect answer: jury 3000000000 vs contestant 2000000001
13 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 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 1 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 1 ms 292 KB n = 2, 3000000000 is a correct answer
12 Incorrect 1 ms 212 KB n = 3, incorrect answer: jury 3000000000 vs contestant 2000000001
13 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 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 1 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 1 ms 292 KB n = 2, 3000000000 is a correct answer
12 Incorrect 1 ms 212 KB n = 3, incorrect answer: jury 3000000000 vs contestant 2000000001
13 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 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 1 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 1 ms 292 KB n = 2, 3000000000 is a correct answer
12 Incorrect 1 ms 212 KB n = 3, incorrect answer: jury 3000000000 vs contestant 2000000001
13 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 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 1 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 1 ms 292 KB n = 2, 3000000000 is a correct answer
12 Incorrect 1 ms 212 KB n = 3, incorrect answer: jury 3000000000 vs contestant 2000000001
13 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 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 1 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 1 ms 292 KB n = 2, 3000000000 is a correct answer
12 Incorrect 1 ms 212 KB n = 3, incorrect answer: jury 3000000000 vs contestant 2000000001
13 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 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 1 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 1 ms 292 KB n = 2, 3000000000 is a correct answer
12 Incorrect 1 ms 212 KB n = 3, incorrect answer: jury 3000000000 vs contestant 2000000001
13 Halted 0 ms 0 KB -