답안 #392850

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
392850 2021-04-22T00:33:57 Z faresbasbs 고대 책들 (IOI17_books) C++14
컴파일 오류
0 ms 0 KB
#include <bits/stdc++.h>
#include "books.h"
using namespace std;
long long n,ans,mini,maxi,num,cyc[1000001],L[1000001],R[1000001];
map<pair<int,int>,long long> mp;
bool seen[1000001];
vector<int> p;

void dfs(long long curr){
	seen[curr] = 1 , L[num] = min(L[num],curr) , R[num] = max(R[num],curr) , cyc[curr] = num;
	mini = min(mini,curr) , maxi = max(maxi,curr);
	if(!seen[p[curr]]){
		dfs(p[curr]);
	}
}

void extend(long long &l , long long &r){
	long long ll = min({l,L[cyc[l]],L[cyc[r]]}) , rr = max({r,R[cyc[l]],R[cyc[r]]});
	while(ll < l || r < rr){
		if(ll < l){
			l -= 1;
			ll = min(ll,L[cyc[l]]);
			rr = max(rr,R[cyc[l]]);
		}else{
			r += 1;
			ll = min(ll,L[cyc[r]]);
			rr = max(rr,R[cyc[r]]);
		}
	}
}

long long getans(long long l , long long r){
	extend(l,r);
	if(mp.find({l,r}) != mp.end()){
		return mp[{l,r}];
	}
	long long nl , nr , ret = 1000000000000000000;
	if(l){
		nl = l-1 , nr = r;
		ret = min(ret,2+getans(nl,nr));
	}
	if(r+1 < n){
		nl = l , nr = r+1;
		ret = min(ret,2+getans(nl,nr));
	}
	return mp[{l,r}] = ret;
}

long long minimum_walk(vector<int> P , int s){
	p = P , n = p.size() , mini = maxi = s;
	for(long long i = 0 ; i < n ; i += 1){
		ans += abs(p[i]-i);
		if(seen[i]){
			cont
		L[num] = R[num] = i , cyc[i] = num;
		if(i != p[i]){
			dfs(i);
		}
		num += 1;
	}
	mp[{mini,maxi}] = 0;
	return ans+getans(s,s);
}

Compilation message

books.cpp: In function 'long long int minimum_walk(std::vector<int>, int)':
books.cpp:54:4: error: 'cont' was not declared in this scope
   54 |    cont
      |    ^~~~
books.cpp:63:1: error: expected '}' at end of input
   63 | }
      | ^
books.cpp:49:46: note: to match this '{'
   49 | long long minimum_walk(vector<int> P , int s){
      |                                              ^
books.cpp:63:1: warning: control reaches end of non-void function [-Wreturn-type]
   63 | }
      | ^