# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
110946 | PeppaPig | Palembang Bridges (APIO15_bridge) | C++14 | 4 ms | 384 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define long long long
#define pii pair<int, int>
#define x first
#define y second
using namespace std;
const int N = 1e5+5;
int k, n;
long ans;
vector<pii> v;
int main() {
scanf("%d %d", &k, &n);
for(int i = 1; i <= n; i++) {
char a, c; int b, d;
scanf(" %c %d %c %d", &a, &b, &c, &d);
if(b > d) swap(b, d);
if(a == c) ans += d - b;
else v.emplace_back(b, d);
}
n = v.size(), ans += n;
if(!v.empty()) {
sort(v.begin(), v.end(), [&](const pii &a, const pii &b) {
return a.x + a.y < b.x + b.y;
});
if(k == 1) {
int bridge = (v[(n - 1) / 2].x + v[(n - 1) / 2].y) / 2;
for(int i = 0; i < n; i++) {
ans += abs(bridge - v[i].x);
ans += abs(bridge - v[i].y);
}
}
}
printf("%lld\n", ans);
return 0;
}
컴파일 시 표준 에러 (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... |