이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
//#include "books.h"
#include <bits/stdc++.h>
#pragma optimization("unroll-loops")
#pragma optimization("-O3")
#pragma target("avx2")
using namespace std;
long long res;
void push(int& l, int& r, int& mn, int& mx, vector<int>& p){
while(l != mn || r != mx){
if(l != mn){
l--;
mn = min(mn, p[l]);
mx = max(mx, p[l]);
} else {
r++;
mn = min(mn, p[r]);
mx = max(mx, p[r]);
}
}
}
long long minimum_walk(vector<int> p, int s){
int L = 0, R = p.size() - 1;
while(R >= 0 && p[R] == R) R--;
if(R == -1) return 0;
while(p[L] = L) L++;
if(s > R){
res += (s - R) << 1;
s = R;
}
if(s < L){
res += (L - s) << 1;
s = L;
}
int tmn = s, tmx = s;
for(int i = L; i <= R; i++){
res += abs(p[i] - i);
if(1LL * (tmx - p[i]) * (tmx - i) <= 0 || 1LL * (tmn - p[i]) * (tmn - i) <= 0){
tmx = max(tmx, max(i, p[i]));
tmn = min(tmn, min(i, p[i]));
}
}
int l, r, mn = min(s, p[s]), mx = max(s, p[s]);
l = r = s;
push(l, r, tmn, tmx, p);
l = r = s;
push(l, r, mn, mx, p);
while(mn != tmn || mx != tmx){
res += 2;
if(mn != tmn)mn--;
if(mx != tmx)mx++;
push(l, r, mn, mx, p);
}
for(; l >= L; l--){
if(mn > l) res += 2;
mn = min(mn, p[l]);
}
for(; r <= R; r++){
if(mx < r) res+= 2;
mx = max(mx, p[r]);
}
return res;
}
컴파일 시 표준 에러 (stderr) 메시지
books.cpp:3:0: warning: ignoring #pragma optimization [-Wunknown-pragmas]
#pragma optimization("unroll-loops")
books.cpp:4:0: warning: ignoring #pragma optimization [-Wunknown-pragmas]
#pragma optimization("-O3")
books.cpp:5:0: warning: ignoring #pragma target [-Wunknown-pragmas]
#pragma target("avx2")
books.cpp: In function 'long long int minimum_walk(std::vector<int>, int)':
books.cpp:26:15: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
while(p[L] = L) L++;
# | 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... |