# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
121082 | 2019-06-26T05:17:31 Z | 윤지학(#2973) | Coin Collecting (JOI19_ho_t4) | C++14 | 2 ms | 384 KB |
#pragma GCC optimize("O3") //#pragma GCC target("arch=skylake") #include <cstdio> #include <algorithm> #define x first #define y second using namespace std; typedef pair<int, int> pii; int n; pii a[2002]; bool cmp(const pii &u, const pii &v) { if ((u.y > 1) != (v.y > 1)) return u.y > 1; return (u.y * 2 - 3ll) * (v.x * 2 - n - 1) < (v.y * 2 - 3ll) * (u.x * 2 - n - 1); } inline int abs(int x) { return x < 0 ? -x : x; } int main() { long long t, r = 9e18, s = 0; int i, j, k; scanf("%d", &n); for (i = 0; i < n + n; i++) { scanf("%d%d", &a[i].x, &a[i].y); if (a[i].x < 1) { s += 1 - a[i].x; a[i].x = 1; } if (a[i].x > n) { s += a[i].x - n; a[i].x = n; } if (a[i].y < 1) { s += 1 - a[i].y; a[i].y = 1; } if (a[i].y > 2) { s += a[i].y - 2; a[i].y = 2; } } sort(a, a + n + n, cmp); for (i = 0; i < n + n; i++) { t = 0; for (j = 0; j < n + n; j++) { k = (i + j) % (n + n); t += abs(a[j].x - (k < n ? k + 1 : n + n - k)) + abs(a[j].y - (k < n ? 1 : 2)); } if (t < r) r = t; } printf("%lld\n", r + s); }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 384 KB | Output is correct |
2 | Correct | 2 ms | 384 KB | Output is correct |
3 | Correct | 2 ms | 256 KB | Output is correct |
4 | Correct | 2 ms | 384 KB | Output is correct |
5 | Correct | 2 ms | 256 KB | Output is correct |
6 | Incorrect | 2 ms | 384 KB | Output isn't correct |
7 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 384 KB | Output is correct |
2 | Correct | 2 ms | 384 KB | Output is correct |
3 | Correct | 2 ms | 256 KB | Output is correct |
4 | Correct | 2 ms | 384 KB | Output is correct |
5 | Correct | 2 ms | 256 KB | Output is correct |
6 | Incorrect | 2 ms | 384 KB | Output isn't correct |
7 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 384 KB | Output is correct |
2 | Correct | 2 ms | 384 KB | Output is correct |
3 | Correct | 2 ms | 256 KB | Output is correct |
4 | Correct | 2 ms | 384 KB | Output is correct |
5 | Correct | 2 ms | 256 KB | Output is correct |
6 | Incorrect | 2 ms | 384 KB | Output isn't correct |
7 | Halted | 0 ms | 0 KB | - |