# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
958785 | 2024-04-06T16:07:04 Z | raphaelp | Coin Collecting (JOI19_ho_t4) | C++14 | 1 ms | 364 KB |
#include <bits/stdc++.h> using namespace std; int main() { long long N; cin >> N; vector<long long> X(N * 2), Y(N * 2); for (long long i = 0; i < 2 * N; i++) { cin >> X[i] >> Y[i]; } long long tot = 0; for (long long i = 0; i < 2 * N; i++) { if (Y[i] > 2) { tot += Y[i] - 2; Y[i] = 2; } } for (long long i = 0; i < 2 * N; i++) { if (X[i] > N) { tot += X[i] - N; X[i] = N; } } for (long long i = 0; i < 2 * N; i++) { if (Y[i] <= 0) { tot -= Y[i] - 1; Y[i] = 1; } } for (long long i = 0; i < 2 * N; i++) { if (X[i] <= 0) { tot -= X[i] - 1; X[i] = 1; } } vector<long long> one, two; for (long long i = 0; i < 2 * N; i++) { if (Y[i] == 1) one.push_back(X[i]); else two.push_back(X[i]); } sort(one.begin(), one.end()); sort(two.begin(), two.end()); one.push_back(1234567890); two.push_back(1234567890); long long buff1 = 0, buff2 = 0; for (long long i = 1; i <= N; i++) { int done1 = 0, done2 = 0; if (one[buff1] == i) { done1 = 1; buff1++; } if (two[buff2] == i) { done2 = 1; buff2++; } if (!done1) if (one[buff1] <= two[buff2]) { tot += abs(one[buff1] - i); buff1++; } else { tot += abs(two[buff2] - i) + 1; buff2++; } if (!done2) if (one[buff1] < two[buff2]) { tot += abs(one[buff1] - i) + 1; buff1++; } else { tot += abs(two[buff2] - i); buff2++; } } cout << tot; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 348 KB | Output is correct |
2 | Correct | 1 ms | 364 KB | Output is correct |
3 | Correct | 0 ms | 348 KB | Output is correct |
4 | Correct | 0 ms | 348 KB | Output is correct |
5 | Correct | 0 ms | 348 KB | Output is correct |
6 | Incorrect | 1 ms | 348 KB | Output isn't correct |
7 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 348 KB | Output is correct |
2 | Correct | 1 ms | 364 KB | Output is correct |
3 | Correct | 0 ms | 348 KB | Output is correct |
4 | Correct | 0 ms | 348 KB | Output is correct |
5 | Correct | 0 ms | 348 KB | Output is correct |
6 | Incorrect | 1 ms | 348 KB | Output isn't correct |
7 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 348 KB | Output is correct |
2 | Correct | 1 ms | 364 KB | Output is correct |
3 | Correct | 0 ms | 348 KB | Output is correct |
4 | Correct | 0 ms | 348 KB | Output is correct |
5 | Correct | 0 ms | 348 KB | Output is correct |
6 | Incorrect | 1 ms | 348 KB | Output isn't correct |
7 | Halted | 0 ms | 0 KB | - |