답안 #780565

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
780565 2023-07-12T10:17:58 Z CSQ31 고대 책들 (IOI17_books) C++17
0 / 100
1 ms 212 KB
#include "books.h"
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define sz(a) (int)(a.size())
#define all(a) a.begin(),a.end()
typedef long long int ll;
typedef pair<int,int> pii;
const int MAXN = 1e6+1;
int par[MAXN];
int find(int x){
	if(x==par[x])return x;
	return par[x] = find(par[x]);
}
ll minimum_walk(vector<int> p, int s) {
	int n = sz(p);
	ll ans = 0;
	for(int i=0;i<n;i++){
		ans+=abs(i-p[i]);
		par[i] = i;
	}
	for(int i=0;i<n;i++){
		if(i==p[i])continue;
		int mn = min(i,p[i]);
		int mx = max(i,p[i]);
		
		int j = mn;
		while(find(j)+1 <= mx){
			j = find(j);
			par[j] = j+1;
		}
	}
	vector<pii>lf,rg;
	rg.pb({s,s});
	for(int i=0;i<n;i++){
		if(i==p[i])continue;
		int j = i;
		while(j+1<n && find(i) == find(j+1))j++;
		if(j<=s)lf.pb({i,j});
		else if(i>=s)rg.pb({i,j});
		else{
			lf.pb({i,i});
			rg.pb({j,j});
		}
		i = j;
	}
	for(int i=0;i+1<sz(lf);i++)ans+=lf[i+1].fi - lf[i].se;
	for(int i=0;i+1<sz(rg);i++)ans+=rg[i+1].fi - rg[i].se;
	return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 212 KB 3rd lines differ - on the 1st token, expected: '6', found: '5'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 212 KB 3rd lines differ - on the 1st token, expected: '6', found: '5'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 212 KB 3rd lines differ - on the 1st token, expected: '6', found: '5'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB 3rd lines differ - on the 1st token, expected: '3304', found: '3318'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 212 KB 3rd lines differ - on the 1st token, expected: '6', found: '5'
2 Halted 0 ms 0 KB -