답안 #581802

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
581802 2022-06-23T06:36:12 Z Koosha_mv 고대 책들 (IOI17_books) C++14
0 / 100
1 ms 212 KB
#include "books.h"
#include <bits/stdc++.h>
using namespace std;
#define dbgv(v) cout<<#v<<" = "; f(i,0,v.size()) cout<<v[i]<<" "; cout<<endl
#define dbga(a,x,y) cout<<#a<<" = "; f(i,x,y) cout<<a[i]<<" "; cout<<endl
#define erorp(x) cout<<#x<<"={"<<x.F<<" , "<<x.S<<"}"<<endl
#define eror(x) cout<<#x<<'='<<(x)<<endl
#define f_(i,a,b) for(int i=a;i>=b;i--)
#define f(i,a,b) for(int i=a;i<b;i++)
#define nb(x) __builtin_popcount(x)
#define all(v) v.begin(),v.end()
#define bit(n,k) (((n)>>(k))&1)
#define Add(x,y) x=(x+y)%mod
#define maxm(a,b) a=max(a,b)
#define minm(a,b) a=min(a,b)
#define lst(x) x[x.size()-1]
#define sz(x) int(x.size())
#define mp make_pair
#define ll long long
#define pb push_back
#define S second
#define F first
 
const int N=1e6+99;
const ll inf=1e15;
 
int n,p[N],vis[N];
ll Max[N];
 
ll minimum_walk(vector<int> p, int s) {
	n=p.size();
	int l=n,r=0;
	f(i,0,n){
		if(p[i]!=i) minm(l,i),maxm(r,i);
	}
	if(l==n) return 0;
	vector<int> v;
	f(i,l,r+1) v.pb(p[i]-l);
	p=v;
	n=p.size();
	ll mx=0,sum=0,ans=0;
	f(i,0,n){
		sum+=abs(i-p[i]);
		if(vis[i]) continue ;
		if(mx<i) ans+=2;
		int u=i;
		ll l=-inf,r=inf;
		maxm(mx,1ll*i);
		do{
			maxm(mx,1ll*u);
			vis[u]=1;
			if(u<=s) maxm(l,1ll*u);
			if(s<=u) minm(r,1ll*u);
			u=p[u];
		} while(!vis[u]);
		//vec.pb({l,r});
	}
	return ans+sum;
	/*sort(all(vec));
	Max[0]=vec[0].S;
	f(i,1,vec.size()) Max[i]=max(Max[i-1],vec[i].S);
	minm(ans,2ll*(s-vec[0].F));
	minm(ans,2ll*(Max[vec.size()-1]-s));
	f_(i,vec.size()-1,1){
		minm(ans,2ll*(s-vec[i].F)+2ll*(Max[i-1]-s));
	}
	return ans+sum;*/
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB 3rd lines differ - on the 1st token, expected: '6', found: '4'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB 3rd lines differ - on the 1st token, expected: '6', found: '4'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB 3rd lines differ - on the 1st token, expected: '6', found: '4'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 212 KB 3rd lines differ - on the 1st token, expected: '3304', found: '2744'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB 3rd lines differ - on the 1st token, expected: '6', found: '4'
2 Halted 0 ms 0 KB -