Submission #886418

# Submission time Handle Problem Language Result Execution time Memory
886418 2023-12-12T06:25:53 Z HuyQuang_re_Zero Shortcut (IOI16_shortcut) C++14
0 / 100
1 ms 6492 KB
#include <bits/stdc++.h>
#define ll long long
#define db long double
#define II pair <ll,ll>
#define III pair <ll,II>
#define IV pair <vector <int>,vector <int> >
#define IDB pair <db,int>
#define TII pair <treap*,treap*>
#define fst first
#define snd second
#define BIT(x,i) ((x>>i)&1)
#define pi acos(-1)
#define to_radian(x) (x*pi/180.0)
#define to_degree(x) (x*180.0/pi)
#define Log(x) (31-__builtin_clz((int)x))
#define LogLL(x) (63-__builtin_clzll((ll)x))
using namespace std;
#include "shortcut.h"
ll n,c,i,j,u,v,x[1000005],h[1000005],tight1,tight2,tight3,tight4;
II sum[1000005],sub[1000005];
const ll oo=round(1e18);
bool check(ll k)
{
    if(k==tight3) return 1;
    tight1=tight2=tight3=tight4=-1e18;
    for(i=1;i<=n;i++)
    {
        j=n-(sum[n].snd==sub[i].snd);
        if(h[sum[j].snd]+x[sum[j].snd]+h[sub[i].snd]-x[sub[i].snd]<=k) continue;
        tight1=max(tight1,h[sum[j].snd]+x[sum[j].snd]+h[sub[i].snd]+x[sub[i].snd]);
    }
    for(j=1;j<=n;j++)
    {
        i=n-(sub[n].snd==sum[j].snd);
        if(h[sum[j].snd]+x[sum[j].snd]+h[sub[i].snd]-x[sub[i].snd]<=k) continue;
        tight2=max(tight2,h[sum[j].snd]-x[sum[j].snd]+h[sub[i].snd]-x[sub[i].snd]);
    }
    for(i=1;i<n;i++)
        for(j=i+1;j<=n;j++)
            if(x[j]-x[i]+h[i]+h[j]>k)
            {
              //  tight1=max(tight1,x[i]+x[j]+h[i]+h[j]);
             //  tight2=max(tight2,-x[i]-x[j]+h[i]+h[j]);
               // tight3=max(tight3,x[j]-x[i]+h[i]+h[j]);
                tight4=max(tight4,-x[j]+x[i]+h[i]+h[j]);
            }
 //   cerr<<tight1<<" "<<tight2<<" "<<tight3<<" "<<tight4<<'\n';
    for(i=1;i<n;i++)
        for(j=i+1;j<=n;j++)
        {
            if(-x[i]-x[j]+tight1+c>k) continue;
            if(x[i]+x[j]+tight2+c>k) continue;
            if(x[i]-x[j]+tight3+c>k) continue;
            if(x[j]-x[i]+tight4+c>k) continue;
            return 1;
        }
    return 0;
}
ll find_shortcut(int _n,vector <int> len,vector <int> d,int _c)
{
    n=_n; c=_c;
    ll dis=0;
    for(i=0;i<len.size();i++) x[i+1]=dis,dis+=len[i];
    x[n]=dis;
    for(i=0;i<d.size();i++) h[i+1]=d[i];
    for(i=1;i<=n;i++) sum[i]={ h[i]+x[i],i },sub[i]={ h[i]-x[i],i };
    sort(sum+1,sum+n+1);
    sort(sub+1,sub+n+1);
    ll ma=-1e18;
    for(i=1;i<=n;i++)
    {
        tight3=max(tight3,h[i]+x[i]+ma);
        ma=max(ma,h[i]-x[i]);
    }

    ll l=0,r=tight3;
    while(l<r)
    {
        ll mid=(l+r)>>1;
        if(check(mid)) r=mid; else l=mid+1;
    }
    return l;
}
/*
int main()
{
    freopen("shortcut.inp","r",stdin);
    freopen("shortcut.out","w",stdout);
    int n,c,x;
    vector <int> l,d;
    cin>>n>>c;
    for(i=1;i<n;i++) cin>>x,l.push_back(x);
    for(i=1;i<=n;i++) cin>>x,d.push_back(x);
    cout<<find_shortcut(n,l,d,c);
}
*/

Compilation message

shortcut.cpp: In function 'long long int find_shortcut(int, std::vector<int>, std::vector<int>, int)':
shortcut.cpp:63:14: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   63 |     for(i=0;i<len.size();i++) x[i+1]=dis,dis+=len[i];
      |             ~^~~~~~~~~~~
shortcut.cpp:65:14: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   65 |     for(i=0;i<d.size();i++) h[i+1]=d[i];
      |             ~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6492 KB n = 4, 80 is a correct answer
2 Correct 1 ms 6492 KB n = 9, 110 is a correct answer
3 Correct 1 ms 6492 KB n = 4, 21 is a correct answer
4 Correct 1 ms 6492 KB n = 3, 4 is a correct answer
5 Correct 1 ms 6492 KB n = 2, 62 is a correct answer
6 Correct 1 ms 6492 KB n = 2, 3 is a correct answer
7 Correct 1 ms 6492 KB n = 3, 29 is a correct answer
8 Correct 1 ms 6492 KB n = 2, 3 is a correct answer
9 Correct 1 ms 6492 KB n = 2, 3 is a correct answer
10 Correct 1 ms 6488 KB n = 2, 2000000001 is a correct answer
11 Correct 1 ms 6492 KB n = 2, 3000000000 is a correct answer
12 Correct 1 ms 6492 KB n = 3, 3000000000 is a correct answer
13 Correct 1 ms 6492 KB n = 3, 3000000000 is a correct answer
14 Correct 1 ms 6492 KB n = 4, 3000000001 is a correct answer
15 Correct 1 ms 6492 KB n = 4, 4000000000 is a correct answer
16 Correct 1 ms 6492 KB n = 5, 4000000000 is a correct answer
17 Incorrect 1 ms 6488 KB n = 10, incorrect answer: jury 1000000343 vs contestant 1000000318
18 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6492 KB n = 4, 80 is a correct answer
2 Correct 1 ms 6492 KB n = 9, 110 is a correct answer
3 Correct 1 ms 6492 KB n = 4, 21 is a correct answer
4 Correct 1 ms 6492 KB n = 3, 4 is a correct answer
5 Correct 1 ms 6492 KB n = 2, 62 is a correct answer
6 Correct 1 ms 6492 KB n = 2, 3 is a correct answer
7 Correct 1 ms 6492 KB n = 3, 29 is a correct answer
8 Correct 1 ms 6492 KB n = 2, 3 is a correct answer
9 Correct 1 ms 6492 KB n = 2, 3 is a correct answer
10 Correct 1 ms 6488 KB n = 2, 2000000001 is a correct answer
11 Correct 1 ms 6492 KB n = 2, 3000000000 is a correct answer
12 Correct 1 ms 6492 KB n = 3, 3000000000 is a correct answer
13 Correct 1 ms 6492 KB n = 3, 3000000000 is a correct answer
14 Correct 1 ms 6492 KB n = 4, 3000000001 is a correct answer
15 Correct 1 ms 6492 KB n = 4, 4000000000 is a correct answer
16 Correct 1 ms 6492 KB n = 5, 4000000000 is a correct answer
17 Incorrect 1 ms 6488 KB n = 10, incorrect answer: jury 1000000343 vs contestant 1000000318
18 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6492 KB n = 4, 80 is a correct answer
2 Correct 1 ms 6492 KB n = 9, 110 is a correct answer
3 Correct 1 ms 6492 KB n = 4, 21 is a correct answer
4 Correct 1 ms 6492 KB n = 3, 4 is a correct answer
5 Correct 1 ms 6492 KB n = 2, 62 is a correct answer
6 Correct 1 ms 6492 KB n = 2, 3 is a correct answer
7 Correct 1 ms 6492 KB n = 3, 29 is a correct answer
8 Correct 1 ms 6492 KB n = 2, 3 is a correct answer
9 Correct 1 ms 6492 KB n = 2, 3 is a correct answer
10 Correct 1 ms 6488 KB n = 2, 2000000001 is a correct answer
11 Correct 1 ms 6492 KB n = 2, 3000000000 is a correct answer
12 Correct 1 ms 6492 KB n = 3, 3000000000 is a correct answer
13 Correct 1 ms 6492 KB n = 3, 3000000000 is a correct answer
14 Correct 1 ms 6492 KB n = 4, 3000000001 is a correct answer
15 Correct 1 ms 6492 KB n = 4, 4000000000 is a correct answer
16 Correct 1 ms 6492 KB n = 5, 4000000000 is a correct answer
17 Incorrect 1 ms 6488 KB n = 10, incorrect answer: jury 1000000343 vs contestant 1000000318
18 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6492 KB n = 4, 80 is a correct answer
2 Correct 1 ms 6492 KB n = 9, 110 is a correct answer
3 Correct 1 ms 6492 KB n = 4, 21 is a correct answer
4 Correct 1 ms 6492 KB n = 3, 4 is a correct answer
5 Correct 1 ms 6492 KB n = 2, 62 is a correct answer
6 Correct 1 ms 6492 KB n = 2, 3 is a correct answer
7 Correct 1 ms 6492 KB n = 3, 29 is a correct answer
8 Correct 1 ms 6492 KB n = 2, 3 is a correct answer
9 Correct 1 ms 6492 KB n = 2, 3 is a correct answer
10 Correct 1 ms 6488 KB n = 2, 2000000001 is a correct answer
11 Correct 1 ms 6492 KB n = 2, 3000000000 is a correct answer
12 Correct 1 ms 6492 KB n = 3, 3000000000 is a correct answer
13 Correct 1 ms 6492 KB n = 3, 3000000000 is a correct answer
14 Correct 1 ms 6492 KB n = 4, 3000000001 is a correct answer
15 Correct 1 ms 6492 KB n = 4, 4000000000 is a correct answer
16 Correct 1 ms 6492 KB n = 5, 4000000000 is a correct answer
17 Incorrect 1 ms 6488 KB n = 10, incorrect answer: jury 1000000343 vs contestant 1000000318
18 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6492 KB n = 4, 80 is a correct answer
2 Correct 1 ms 6492 KB n = 9, 110 is a correct answer
3 Correct 1 ms 6492 KB n = 4, 21 is a correct answer
4 Correct 1 ms 6492 KB n = 3, 4 is a correct answer
5 Correct 1 ms 6492 KB n = 2, 62 is a correct answer
6 Correct 1 ms 6492 KB n = 2, 3 is a correct answer
7 Correct 1 ms 6492 KB n = 3, 29 is a correct answer
8 Correct 1 ms 6492 KB n = 2, 3 is a correct answer
9 Correct 1 ms 6492 KB n = 2, 3 is a correct answer
10 Correct 1 ms 6488 KB n = 2, 2000000001 is a correct answer
11 Correct 1 ms 6492 KB n = 2, 3000000000 is a correct answer
12 Correct 1 ms 6492 KB n = 3, 3000000000 is a correct answer
13 Correct 1 ms 6492 KB n = 3, 3000000000 is a correct answer
14 Correct 1 ms 6492 KB n = 4, 3000000001 is a correct answer
15 Correct 1 ms 6492 KB n = 4, 4000000000 is a correct answer
16 Correct 1 ms 6492 KB n = 5, 4000000000 is a correct answer
17 Incorrect 1 ms 6488 KB n = 10, incorrect answer: jury 1000000343 vs contestant 1000000318
18 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6492 KB n = 4, 80 is a correct answer
2 Correct 1 ms 6492 KB n = 9, 110 is a correct answer
3 Correct 1 ms 6492 KB n = 4, 21 is a correct answer
4 Correct 1 ms 6492 KB n = 3, 4 is a correct answer
5 Correct 1 ms 6492 KB n = 2, 62 is a correct answer
6 Correct 1 ms 6492 KB n = 2, 3 is a correct answer
7 Correct 1 ms 6492 KB n = 3, 29 is a correct answer
8 Correct 1 ms 6492 KB n = 2, 3 is a correct answer
9 Correct 1 ms 6492 KB n = 2, 3 is a correct answer
10 Correct 1 ms 6488 KB n = 2, 2000000001 is a correct answer
11 Correct 1 ms 6492 KB n = 2, 3000000000 is a correct answer
12 Correct 1 ms 6492 KB n = 3, 3000000000 is a correct answer
13 Correct 1 ms 6492 KB n = 3, 3000000000 is a correct answer
14 Correct 1 ms 6492 KB n = 4, 3000000001 is a correct answer
15 Correct 1 ms 6492 KB n = 4, 4000000000 is a correct answer
16 Correct 1 ms 6492 KB n = 5, 4000000000 is a correct answer
17 Incorrect 1 ms 6488 KB n = 10, incorrect answer: jury 1000000343 vs contestant 1000000318
18 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6492 KB n = 4, 80 is a correct answer
2 Correct 1 ms 6492 KB n = 9, 110 is a correct answer
3 Correct 1 ms 6492 KB n = 4, 21 is a correct answer
4 Correct 1 ms 6492 KB n = 3, 4 is a correct answer
5 Correct 1 ms 6492 KB n = 2, 62 is a correct answer
6 Correct 1 ms 6492 KB n = 2, 3 is a correct answer
7 Correct 1 ms 6492 KB n = 3, 29 is a correct answer
8 Correct 1 ms 6492 KB n = 2, 3 is a correct answer
9 Correct 1 ms 6492 KB n = 2, 3 is a correct answer
10 Correct 1 ms 6488 KB n = 2, 2000000001 is a correct answer
11 Correct 1 ms 6492 KB n = 2, 3000000000 is a correct answer
12 Correct 1 ms 6492 KB n = 3, 3000000000 is a correct answer
13 Correct 1 ms 6492 KB n = 3, 3000000000 is a correct answer
14 Correct 1 ms 6492 KB n = 4, 3000000001 is a correct answer
15 Correct 1 ms 6492 KB n = 4, 4000000000 is a correct answer
16 Correct 1 ms 6492 KB n = 5, 4000000000 is a correct answer
17 Incorrect 1 ms 6488 KB n = 10, incorrect answer: jury 1000000343 vs contestant 1000000318
18 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6492 KB n = 4, 80 is a correct answer
2 Correct 1 ms 6492 KB n = 9, 110 is a correct answer
3 Correct 1 ms 6492 KB n = 4, 21 is a correct answer
4 Correct 1 ms 6492 KB n = 3, 4 is a correct answer
5 Correct 1 ms 6492 KB n = 2, 62 is a correct answer
6 Correct 1 ms 6492 KB n = 2, 3 is a correct answer
7 Correct 1 ms 6492 KB n = 3, 29 is a correct answer
8 Correct 1 ms 6492 KB n = 2, 3 is a correct answer
9 Correct 1 ms 6492 KB n = 2, 3 is a correct answer
10 Correct 1 ms 6488 KB n = 2, 2000000001 is a correct answer
11 Correct 1 ms 6492 KB n = 2, 3000000000 is a correct answer
12 Correct 1 ms 6492 KB n = 3, 3000000000 is a correct answer
13 Correct 1 ms 6492 KB n = 3, 3000000000 is a correct answer
14 Correct 1 ms 6492 KB n = 4, 3000000001 is a correct answer
15 Correct 1 ms 6492 KB n = 4, 4000000000 is a correct answer
16 Correct 1 ms 6492 KB n = 5, 4000000000 is a correct answer
17 Incorrect 1 ms 6488 KB n = 10, incorrect answer: jury 1000000343 vs contestant 1000000318
18 Halted 0 ms 0 KB -