# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
117950 | sealnot123 | 고대 책들 (IOI17_books) | C++14 | 251 ms | 19960 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "books.h"
//#include "grader.cpp"
#include<bits/stdc++.h>
#define x first
#define y second
#define pb push_back
#define eb emplace_back
#define all(a) (a).begin(),(a).end()
#define SZ(a) (int)(a).size()
using namespace std;
typedef long long LL;
typedef pair<LL,LL> PLL;
typedef pair<int,int> PII;
typedef double D;
typedef long double LD;
const int N = 1000007;
int n;
int mk[N];
vector<PII> inter,interx;
int L[N],R[N],G[N];
void extend(int &l, int &r, int ll, int rr){
ll = min(ll, min(L[G[l]], L[G[r]]));
rr = max(rr, max(R[G[l]], R[G[r]]));
while(ll < l || r < rr){
if(ll < l){
l--;
ll = min(ll, L[G[l]]);
rr = max(rr, R[G[l]]);
}else{
r++;
ll = min(ll, L[G[r]]);
rr = max(rr, R[G[r]]);
}
}
}
LL step(int l, int r, int ll, int rr){
LL ans = 0;
int i,j,k,a,b,c;
while(ll < l || r < rr){
int stepl = 0, stepr = 0, ch = 0;
int xll, xrr, xl, xr;
xl = xll = l;
xr = xrr = r;
while(xl > ll && xrr == r){
stepl += 2;
xl--;
extend(xl, xr, xll, xrr);
}
if(xrr == r) ch = 1;
xl = xll = l;
xr = xrr = r;
while(xr < rr && xll == l){
stepr += 2;
xr++;
extend(xl, xr, xll, xrr);
}
if(xll == l) ch = 1;
if(ch){
ans += stepl + stepr;
break;
}else{
ans += min(stepl, stepr);
extend(l, r, xll, xrr);
}
}
return ans;
}
long long minimum_walk(vector<int> p, int s) {
int a, b, c = 0, d, i, j, k;
int l = s, r = s;
LL ans = 0;
n = SZ(p);
for(i=0; i<n; i++){
ans += abs(i - p[i]);
if(!G[i]){
c++;
a = i;
L[c] = R[c] = i;
do{
G[a] = c;
L[c] = min(L[c], a);
R[c] = max(R[c], a);
a = p[a];
}while(a != i);
if(i != p[i]){
l = min(l, L[c]);
r = max(r, R[c]);
}
}
}
int ll=s, rr=s;
extend(ll, rr, L[G[s]], R[G[s]]);
// printf("%lld %d %d : %d %d\n", ans, l, r, ll, rr);
return ans + step(ll, rr, l, r);
}
/*
4 0
2 0 1 3
7 4
1 0 6 5 4 2 3
8 4
7 1 2 0 3 5 6 4
8 4
7 5 6 0 3 2 1 4
5 2
3 4 2 0 1
*/
컴파일 시 표준 에러 (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... |