이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
int n;
long long ans = 0;
int cnt[maxn][3];
int main(){
//freopen("c.in", "r", stdin);
//freopen("c.out", "w", stdout);
scanf("%d", &n);
for(int i = 0; i < n * 2; ++i){
int x, y; scanf("%d%d", &x, &y);
int nx = max(1, min(n, x)), ny = max(1, min(2, y));
++cnt[nx][ny], ans += abs(nx - x) + abs(ny - y);
}
for(int i = 1; i <= n; ++i){
if(cnt[i][1] < 1 && cnt[i][2] > 1)
ans += 1 - cnt[i][1], cnt[i][2] += cnt[i][1] - 1, cnt[i][1] = 1;
if(cnt[i][2] < 1 && cnt[i][1] > 1)
ans += 1 - cnt[i][2], cnt[i][1] += cnt[i][2] - 1, cnt[i][2] = 1;
ans += abs(cnt[i][1] - 1), cnt[i + 1][1] += cnt[i][1] - 1, cnt[i][1] = 1;
ans += abs(cnt[i][2] - 1), cnt[i + 1][2] += cnt[i][2] - 1, cnt[i][2] = 1;
}
printf("%lld\n", ans);
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
joi2019_ho_t4.cpp: In function 'int main()':
joi2019_ho_t4.cpp:15:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
15 | scanf("%d", &n);
| ~~~~~^~~~~~~~~~
joi2019_ho_t4.cpp:17:20: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
17 | int x, y; scanf("%d%d", &x, &y);
| ~~~~~^~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |