Submission #805863

# Submission time Handle Problem Language Result Execution time Memory
805863 2023-08-04T01:23:52 Z resting Shortcut (IOI16_shortcut) C++17
Compilation error
0 ms 0 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<ll> p(n, 0);
    for (int i = 1; i < n; i++) p[i] = p[i - 1] + l[i - 1];

    vector<ll> distl(n, 0), distr(n, 0);
    ll 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, (ll)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, (ll)d[i]);
        if (i)
            cur += l[i - 1];
    }

    ll 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 = p.back() + 2e9 + 1;
    cout << left << endl;
    while (right - left > 1) {
        ll mid = (left + right) / 2;
        ll x1 = -inf, x2 = inf, y1 = -inf, y2 = inf;


        ll rangl = -inf, rangr = inf;
        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--;
            }
            // {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(3, { (int)1e9, (int)1e9 }, { (int)1e9, (int)1e9, (int)1e9 }, 1e9) << endl;
}

Compilation message

shortcut.cpp: In function 'long long int find_shortcut(int, std::vector<int>, std::vector<int>, int)':
shortcut.cpp:69: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]
   69 |         for (int i = 0; i < partl.size(); i++) {
      |                         ~~^~~~~~~~~~~~~~
/usr/bin/ld: /tmp/cccT6sbm.o: in function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/ccxQ7cgl.o:shortcut.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status