# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1058698 | shenfe1 | 고대 책들 (IOI17_books) | C++17 | 2021 ms | 88928 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include "books.h"
#pragma GCC optimize("Ofast")
using namespace std;
#define pb push_back
#define pii pair<int,int>
#define sz(s) (int)s.size()
#define F first
#define S second
#define all(v) v.begin(),v.end()
#define ll long long
const int MAX=1e6+10;
int n;
vector<int> g[MAX];
bool use[MAX];
vector<int> vec;
int pref[MAX];
ll minimum_walk(vector<int> p,int s){
n=sz(p);
while(n>1&&p[n-1]==n-1)n--;
ll ans=0;
for(int i=0;i<n;i++){
ans+=abs(i-p[i]);
}
vector<vector<int>> x;
vector<pii> seg;
for(int i=0;i<n;i++){
if(!use[i]){
vec.clear();
int v=i;
while(!use[v]){
vec.pb(v);
use[v]=1;
v=p[v];
}
sort(all(vec));
seg.pb({vec[0],vec.back()});
x.pb(vec);
}
}
int L,R;
for(vector<int> v:x){
for(int f:v){
if(f==s){
L=v[0],R=v.back();
}
}
}
while(R-L+1!=n){
bool ok=0;
for(int i=0;i<sz(seg);i++){
auto [l,r]=seg[i];
for(int pos:x[i]){
if(L<=pos&&pos<=R){
if(l<L||r>R)ok=1;
L=min(L,l);
R=max(R,r);
}
}
}
if(!ok){
if(L-1>=0){
L--;
ans+=2;
}
if(R+1<n){
R++;
ans+=2;
}
}
}
return ans;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |