Submission #787868

# Submission time Handle Problem Language Result Execution time Memory
787868 2023-07-19T13:40:27 Z fatemetmhr Shortcut (IOI16_shortcut) C++17
0 / 100
2 ms 696 KB
//  ~ Be Name Khoda ~  //
 
#include "shortcut.h"
//#pragma GCC optimize ("O3")
#pragma GCC target("avx2")
#pragma GCC optimize("unroll-loops,Ofast")
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
 
#define pb       push_back
#define mp       make_pair
#define all(x)   x.begin(), x.end()
#define fi       first
#define se       second
 
const int maxn  =  1e6   + 10;
const int maxn5 =  3e3   + 10;
const int maxnt =  1.2e6 + 10;
const int maxn3 =  1e3   + 10;
const ll mod   =  1e9   + 7;
const int lg    =  20;
const ll  inf   =  1e18;
 
int n, pt[maxn5];
ll c;
vector <ll> d;
ll ps[maxn5];
vector <pair<ll, ll>> av[2][maxn5];
 
ll dis(int a, int b){
    if(a > b)
        swap(a, b);
    return ps[b] - ps[a];
}
 
bool check(int a, int b, int ty, ll lim){
    for(int i = 0; i < n; i++){
        if(pt[i] < av[ty][i].size() && c + d[i] + dis(a, i) + av[ty][i][pt[i]].se + (ty ? 1 : -1) * ps[b] > lim){
            //cout << "ha? " << a << ' ' << b << ' ' << ty << ' ' << lim << ' ' << pt[i][ty] << ' ' << i << ' ' << av[ty][i][pt[i][ty]].se << ' ' << av[i][ty][pt].fi  << ' ' << dis(a, i) << endl;
            return false;
        }
    }
    return true;
}
 
bool check(ll lim){
    for(int i = 0; i < n; i++){
        pt[i] = upper_bound(all(av[0][i]), mp(lim, inf)) - av[0][i].begin();
    }
    for(int i = 0; i < n; i++){
        int l = i + 1, r = n;
 
        int lo = i, hi = n;
        while(hi - lo > 1){
            int mid = (lo + hi) >> 1;
            if(check(i, mid, 0, lim))
                hi = mid;
            else
                lo = mid;
        }
        l = max(i + 1, hi);
 
        lo = i; hi = n;
        while(hi - lo > 1){
            int mid = (lo + hi) >> 1;
            if(check(i, mid, 1, lim))
                lo = mid;
            else
                hi = mid;
        }
        r = min(n, lo);
        //cout << "ok " << lim << ' ' << i << ' ' << l << ' ' << r << endl;
        if(l <= r)
            return true;
 
 
 
        /*
        bool re = true;
        for(int j = 0; j < n && re; j++) for(int k = j + 1; k < n && re; k++) if(dis(j, k) + d[j] + d[k] > lim){
            ll dis1 = dis(i, j);
            ll need = lim - c - d[j] - d[k] - dis1;
            if(need < 0)
                re = false;
            int ptl = k - (upper_bound(all(av[k][0]), need) - av[k][0].begin() - 1);
            int ptr = k + (upper_bound(all(av[k][1]), need) - av[k][1].begin() - 1);
            l = max(l, ptl);
            r = min(r, ptr);
            //cout << lim << ' ' << i << ' ' << j << ' ' << k << ' ' << l << ' ' << r << endl;
            if(l > r)
                re = false;
        }
        if(re)
            return true;
        */
    }
    //cout << "FAslse" << endl;
    return false;
}
 
long long find_shortcut(int N, std::vector<int> l, std::vector<int> D, int C)
{
    n = N;
    c = C;
    for(auto u : D)
        d.pb(u);
    ps[0] = 0;
    for(int i = 1; i < n; i++)
        ps[i] = ps[i - 1] + l[i - 1];
    for(int i = 0; i < n; i++){
        for(int j = i + 1; j < n; j++){
            av[0][i].pb({dis(i, j) + d[i] + d[j], d[j] + ps[j]});
            av[1][i].pb({dis(i, j) + d[i] + d[j], d[j] - ps[j]});
        }
        //if(i == 1)
        //    cout << av[i][1].back().se << ' ' << av[i][1].back().fi << endl;
        sort(all(av[0][i]));
        sort(all(av[1][i]));
        for(int j = int(av[i][0].size()) - 2; j >= 0; j--){
            //if(i == 1)
            //    cout << j << endl;
            av[0][i][j].se = max(av[0][i][j].se, av[0][i][j + 1].se);
            av[1][i][j].se = max(av[1][i][j].se, av[1][i][j + 1].se);
        }
        //if(i == 1)
        //    cout << av[i][1].back().se << ' ' << av[i][1].back().fi << endl;
    }
    ll lo = -1, hi = mod * (n + 3);
    while(hi - lo > 1){
        ll mid = (lo + hi) >> 1;
        if(check(mid))
            hi = mid;
        else
            lo = mid;
    }
    return hi;
}

Compilation message

shortcut.cpp: In function 'bool check(int, int, int, ll)':
shortcut.cpp:41:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   41 |         if(pt[i] < av[ty][i].size() && c + d[i] + dis(a, i) + av[ty][i][pt[i]].se + (ty ? 1 : -1) * ps[b] > lim){
      |            ~~~~~~^~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 696 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 696 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 696 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 696 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 696 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 696 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 696 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 696 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -