이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "books.h"
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
typedef pair<int, int> pii;
typedef long long lld;
typedef long double ld;
template<typename Iter>
ostream& outIt(ostream& out, Iter b, Iter e){
for(Iter i = b; i != e; ++i)
out << (i == b?"":" ") << *i;
return out;
}
template<typename T1, typename T2>
ostream& operator<<(ostream& out, pair<T1, T2> p){
return out << '(' << p.ff << ", " << p.ss << ')';
}
template<typename T>
ostream& operator<<(ostream& out, vector<T> v){
return outIt(out << '[', all(v)) << ']';
}
vector<int> dsu, c;
int root(int i){
return dsu[i] == i ? i : (dsu[i] = root(dsu[i]));
}
void join(int i, int j){
dsu[root(i)] = root(j);
}
long long minimum_walk(vector<int> p, int s) {
lld ans = 0;
c.resize(p.size()+1);
for(int i = 0; i < p.size(); i++)if(p[i] != i)ans += abs(p[i]-i), c[min(i, p[i])]++, c[max(i, p[i])+1]--;
for(int i = 1; i <= p.size(); i++)c[i] += c[i-1];
for(int i = p.size(), x = 0; i >= 0; i--){
if(c[i])x = 1;
else if(x)ans += 2;
}
return ans;
}
컴파일 시 표준 에러 (stderr) 메시지
books.cpp: In function 'long long int minimum_walk(std::vector<int>, int)':
books.cpp:42:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
42 | for(int i = 0; i < p.size(); i++)if(p[i] != i)ans += abs(p[i]-i), c[min(i, p[i])]++, c[max(i, p[i])+1]--;
| ~~^~~~~~~~~~
books.cpp:43:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
43 | for(int i = 1; i <= p.size(); i++)c[i] += c[i-1];
| ~~^~~~~~~~~~~
# | 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... |