Submission #99528

# Submission time Handle Problem Language Result Execution time Memory
99528 2019-03-04T17:17:36 Z MvC Ancient Books (IOI17_books) C++11
0 / 100
2 ms 384 KB
#pragma GCC optimize("O3")
#include "books.h"
#include<bits/stdc++.h>
#define rc(x) return cout<<x<<endl,0
#define pb push_back
#define in insert
#define er erase
#define fd find
#define fr first
#define sc second
typedef long long ll;
typedef long double ld;
const ll INF=0x3f3f3f3f3f3f3f3f;
const ll llinf=(1LL<<62);
const int inf=(1<<30);
const int nmax=1e6+50;
const int mod=1e9+7;
using namespace std;
int n,s,p[nmax],mn,mx,t,i,st[nmax],v[nmax],j;
ll ans,nr;
ll minimum_walk(vector<int>x,int s)
{
	n=(int)x.size();
	for(i=1;i<=n;i++)p[i]=x[i-1];
	for(i=1;i<=n;i++)ans+=1LL*abs(i-p[i]);
	for(i=1;i<=n;i++)
	{
		if(v[p[i]])continue;
		j=p[i];
		mn=1e9,mx=-1;
		while(!v[j])
		{
			v[j]=1;
			mn=min(mn,j);
			mx=max(mx,j);
			j=p[j];
		}
		st[mn]=mx;
		t=max(t,mx);
	}
	mx=st[1];
	for(i=1;i<=t;i++)
	{
		if(mx<st[i])nr++;
		mx=max(mx,st[i]);
	}
	return ans+2LL*nr;
}
/*int main()
{
	//freopen("sol.in","r",stdin);
	//freopen("sol.out","w",stdout);
	ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0);
	cin>>n>>s;
	for(i=1;i<=n;i++)cin>>p[i];
	for(i=1;i<=n;i++)ans+=abs(i-p[i]);
	for(i=1;i<=n;i++)
	{
		if(v[p[i]])continue;
		j=p[i];
		mn=1e9,mx=-1;
		while(!v[j])
		{
			v[j]=1;
			mn=min(mn,j);
			mx=max(mx,j);
			j=p[j];
		}
		st[mn]=mx;
		t=max(t,mx);
	}
	mx=st[1];
	for(i=1;i<=t;i++)
	{
		if(mx<st[i])nr++;
		mx=max(mx,st[i]);
	}
	cout<<ans+2*nr<<endl;
    return 0;
}
/*
4 1
1 3 4 2
*/

Compilation message

books.cpp:81:1: warning: "/*" within comment [-Wcomment]
 /*
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 384 KB 3rd lines differ - on the 1st token, expected: '6', found: '8'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 384 KB 3rd lines differ - on the 1st token, expected: '6', found: '8'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 384 KB 3rd lines differ - on the 1st token, expected: '6', found: '8'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 384 KB 3rd lines differ - on the 1st token, expected: '3304', found: '4892'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 384 KB 3rd lines differ - on the 1st token, expected: '6', found: '8'
2 Halted 0 ms 0 KB -