이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "books.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
typedef pair<ll, ll> pll;
typedef pair<ll, pll> plll;
#define fi first
#define se second
const int INF = 1e9+1;
const int P = 1000000007;
const ll LLINF = (ll)1e18+1;
template <typename T1, typename T2>
ostream& operator<<(ostream& os, const pair<T1, T2>& p) { os << p.fi << " " << p.se; return os; }
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v) { for(auto i : v) os << i << " "; os << "\n"; return os; }
void f(int i, int j, bool &x, int &idx) {
if(x) return;
if(i != j) {
idx = i;
x = true;
}
}
ll minimum_walk(vector<int> p, int s) {
int idx = s, hand = p[s];
ll ans = 0LL;
do {
int tmp = hand;
if(tmp == s) {
bool x = false;
if(idx > s) {
for(int i = idx-1; i > s; i--) f(i, p[i], x, tmp);
} else {
for(int i = idx+1; i < s; i++) f(i, p[i], x, tmp);
}
for(int i = 1; i < p.size(); i++) {
int j = min(idx, s)-i, k = max(idx, s)+i;
if(j >= 0 && j < p.size()) f(j, p[j], x, tmp);
if(k >= 0 && k < p.size()) f(k, p[k], x, tmp);
}
}
swap(p[tmp], hand);
ans += abs(idx-tmp);
idx = tmp;
} while(idx != s);
return ans;
}
컴파일 시 표준 에러 (stderr) 메시지
books.cpp: In function 'll minimum_walk(std::vector<int>, int)':
books.cpp:39:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
39 | for(int i = 1; i < p.size(); i++) {
| ~~^~~~~~~~~~
books.cpp:41:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
41 | if(j >= 0 && j < p.size()) f(j, p[j], x, tmp);
| ~~^~~~~~~~~~
books.cpp:42:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
42 | if(k >= 0 && k < p.size()) f(k, p[k], x, tmp);
| ~~^~~~~~~~~~
# | 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... |