Submission #121077

# Submission time Handle Problem Language Result Execution time Memory
121077 2019-06-26T04:50:12 Z 윤지학(#2973) Coin Collecting (JOI19_ho_t4) C++14
0 / 100
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;
	int i, j, k;
	scanf("%d", &n);
	for (i = 0; i < n + n; i++) scanf("%d%d", &a[i].x, &a[i].y);
	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);
}

Compilation message

joi2019_ho_t4.cpp: In function 'int main()':
joi2019_ho_t4.cpp:28:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &n);
  ~~~~~^~~~~~~~~~
joi2019_ho_t4.cpp:29:35: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for (i = 0; i < n + n; i++) scanf("%d%d", &a[i].x, &a[i].y);
                              ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory 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 256 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 -
# Verdict Execution time Memory 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 256 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 -
# Verdict Execution time Memory 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 256 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 -