# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1148429 | mingga | Coin Collecting (JOI19_ho_t4) | C++20 | 24 ms | 1864 KiB |
#include "bits/stdc++.h"
using namespace std;
#define ln "\n"
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define int long long
const int mod = 1e9 + 7;
const int inf = 2e18;
const int N = 2e5 + 7;
int n, a[N][2];
signed main() {
cin.tie(0) -> sync_with_stdio(0);
#define task ""
if(fopen(task ".INP", "r")) {
freopen(task ".INP", "r", stdin);
freopen(task ".OUT", "w", stdout);
}
cin >> n;
int ans = 0;
for(int i = 1; i <= 2 * n; i++) {
int x, y; cin >> x >> y;
if(x > n) {
ans += (x - n);
x = n;
}
if(x < 1) {
ans += (1 - x);
x = 1;
}
if(y > 2) {
ans += (y - 2);
y = 2;
}
if(y < 1) {
ans += (1 - y);
y = 1;
}
a[x][y]++;
}
int d1 = 0, d2 = 0;
for(int i = 1; i <= n; i++) {
d1 += a[i][1] - 1;
d2 += a[i][2] - 1;
if(d1 > 0 and d2 < 0) {
int ext = min(d1, -d2);
ans += ext;
d1 -= ext;
d2 += ext;
}
if(d1 < 0 and d2 > 0) {
int ext = min(-d1, d2);
ans += ext;
d1 += ext;
d2 -= ext;
}
ans += abs(d1) + abs(d2);
}
cout << ans << ln;
cerr << "\nTime: " << clock() * 1000 / CLOCKS_PER_SEC;
}
컴파일 시 표준 에러 (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... |