Submission #831887

#TimeUsernameProblemLanguageResultExecution timeMemory
831887KerimShortcut (IOI16_shortcut)C++17
71 / 100
2063 ms1364 KiB
#include "shortcut.h"
#include "bits/stdc++.h"
#define ll long long
using namespace std;
//x+y, y-x (45 degrees rotation)
//|x-xx|+|y-yy| -> max(|x-xx|, |y-yy|)
const ll INF = 1e18;
bool check(ll k, vector<int> &d, int c, vector<ll>&p){
    int n = d.size();
    ll X = -INF, Y = -INF;
    ll XX = INF, YY = INF; 
    for (int i = 0; i < n; i++)
        for (int j = i + 1; j < n; j++){
            if (d[i] + d[j] + p[j] - p[i] <= k)
                continue;
            ll r = k - c - d[i] - d[j];
            ll x = p[i] + p[j] - r, y = p[j] - p[i] - r;
            ll xx = p[i] + p[j] + r, yy = p[j] - p[i] + r;
            Y = max(Y, y);
            XX = min(XX, xx); YY = min(YY, yy);
        }
    
    for (int j = 1; j < n; j++)
        for (int i = 0; i < j; i++)
            if (d[i] - p[i] > k - d[j] - p[j]){
                X = max(X, p[i] + p[j] - (k - c - d[i] - d[j]));
            }

    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];
    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;
}

Compilation message (stderr)

shortcut.cpp: In function 'bool check(long long int, std::vector<int>&, int, std::vector<long long int>&)':
shortcut.cpp:17:16: warning: unused variable 'x' [-Wunused-variable]
   17 |             ll x = p[i] + p[j] - r, y = p[j] - p[i] - r;
      |                ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...