Submission #1321497

#TimeUsernameProblemLanguageResultExecution timeMemory
1321497modwweAncient Books (IOI17_books)C++20
50 / 100
73 ms12000 KiB
#pragma GCC optimize("Ofast,unroll-loops")
#include <bits/stdc++.h>
//#define int long long
#define ll long long
#define ull unsigned long long
#define down cout<<'\n';
#define debug cout<<" cucuucucuuu",down
#define modwwe  int t;cin>>t; while(t--)
#define bit(i,j) (i>>j&1)
#define sobit(a) __builtin_popcountll(a)
#define task2 "top1apio"
#define task "test"
#define fin(x) freopen(x".inp","r",stdin)
#define fou(x) freopen(x".out","w",stdout)
#define pb push_back
#define mask(k) (1ll<<k)
#define checktime   cerr <<  (double)clock() / CLOCKS_PER_SEC * 1000  << " ms";
using namespace std;
#define getchar_unlocked getchar
mt19937 rd(chrono::steady_clock::now().time_since_epoch().count());
using i128 = __int128;
int rand(int l, int r)
{
    return uniform_int_distribution<int>(l, r)(rd);
}
void phongbeo();
const int inf = 1e17;
const int mod2 = 998244353;
//const ll base=67;
ll  n, m, s1, s2, s4, s3, sf, k, s5, s6, s7, s8, s9, mx2, res, dem2 = 0, dem = 0, s33, dem3, dem4, mid, l2,
                                                               r2, center;
ll  i, s10, s12, k1, k2, k3, s11, w, l, r, dem5, dem6, dem7, dem9, root,q;
ll el = 19;
int pos[1000001];
ll minimum_walk(vector<int> a,int s)
{
    while(a.size()&&a.back()==a.size()-1)a.pop_back();
    if(a.size()==0)return 0;
    dem=0;
    while(dem<a.size()&&a[dem]==dem)dem++;
    for(auto x:a)pos[x]=dem2++;
    int x=s;
    int y=s;
    int i=s,j=s;
    while(true)
    {
        bool hihi=0;
        while(i>=x)
        {
            hihi=1;
            if(a[i]>y)
            {
                s4+=s2;
                s2=0;
                s3=0;
            }
            x=min(x,a[i]);
            y=max(y,a[i]);
            i--;
        }
        while(j<=y)
        {
            hihi=1;
            if(a[j]<x)
            {
                s4+=s3;
                s2=0;
                s3=0;
            }
            x=min(x,a[j]);
            y=max(y,a[j]);
            j++;
        }
        if(x<=dem&&y==a.size())break;
        if(x>dem&&!hihi)x--,s2+=2;
        if(y!=a.size()&&!hihi)y++,s3+=2;
    }
    s4+=s2+s3-2;
    for(int i=0;i<dem2;i++)s4=s4+abs(i-pos[i]);
    return s4;
}

Compilation message (stderr)

books.cpp:27:17: warning: overflow in conversion from 'double' to 'int' changes value from '1.0e+17' to '2147483647' [-Woverflow]
   27 | const int inf = 1e17;
      |                 ^~~~
#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...