답안 #532152

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
532152 2022-03-02T07:46:31 Z fhvirus Naan (JOI19_naan) C++17
29 / 100
65 ms 10408 KB
#include <bits/stdc++.h>
using namespace std;

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

	int N, L; cin >> N >> L;
	vector<int> V(L + 1);
	vector<vector<pair<int64_t, int64_t>>> cut(N + 1, vector<pair<int64_t, int64_t>>(L + 1));

	for (int i = 1; i <= N; ++i) {
		for (int j = 1; j <= L; ++j)
			cin >> V[j];

		int64_t tot = 0, sum = 0;
		for (int j = 1; j <= L; ++j) tot += V[j];
		for (int j = 1, k = 1; j <= N; ++j) {
			while (k < L and (sum + V[k]) * N < tot * j) sum += V[k++];
			int64_t a = 1ll * N * V[k] * (k - 1) + tot * j - sum * N;
			int64_t b = 1ll * N * V[k];
			int64_t g = gcd(a, b);
			cut[i][j] = make_pair(a / g, b / g);
		}
	}

	auto cmp = [&](int i, int j, int k) -> bool {
		return (__int128) cut[j][i].first * cut[k][i].second
		< (__int128) cut[k][i].first * cut[j][i].second;
	};

	vector<bool> vis(N + 1, false);
	vector<pair<int64_t, int64_t>> X(N + 1);
	vector<int> P(N + 1);
	for (int i = 1; i <= N; ++i) {
		int u = -1;
		for (int j = 1; j <= N; ++j)
			if (!vis[j] and (u == -1 or cmp(i, j, u)))
				u = j;
		vis[u] = true;
		X[i] = cut[u][i];
		P[i] = u;
	}

	for (int i = 1; i < N; ++i)
		cout << X[i].first << ' ' << X[i].second << '\n';
	for (int i = 1; i <= N; ++i)
		cout << P[i] << " \n"[i == N];

	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 324 KB Output is correct
3 Correct 1 ms 324 KB Output is correct
4 Correct 1 ms 452 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 0 ms 304 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 460 KB Output is correct
12 Correct 1 ms 452 KB Output is correct
13 Correct 1 ms 460 KB Output is correct
14 Correct 1 ms 452 KB Output is correct
15 Correct 1 ms 448 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 316 KB Output is correct
3 Correct 1 ms 460 KB Output is correct
4 Correct 1 ms 460 KB Output is correct
5 Correct 1 ms 460 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 460 KB Output is correct
10 Correct 2 ms 460 KB Output is correct
11 Correct 1 ms 460 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 448 KB Output is correct
15 Correct 1 ms 460 KB Output is correct
16 Correct 2 ms 496 KB Output is correct
17 Correct 2 ms 460 KB Output is correct
18 Correct 1 ms 588 KB Output is correct
19 Correct 2 ms 576 KB Output is correct
20 Correct 1 ms 460 KB Output is correct
21 Correct 1 ms 588 KB Output is correct
22 Correct 2 ms 580 KB Output is correct
23 Correct 1 ms 204 KB Output is correct
24 Correct 1 ms 460 KB Output is correct
25 Correct 1 ms 440 KB Output is correct
26 Correct 1 ms 316 KB Output is correct
27 Correct 2 ms 460 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 324 KB Output is correct
3 Correct 1 ms 324 KB Output is correct
4 Correct 1 ms 452 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 0 ms 304 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 460 KB Output is correct
12 Correct 1 ms 452 KB Output is correct
13 Correct 1 ms 460 KB Output is correct
14 Correct 1 ms 452 KB Output is correct
15 Correct 1 ms 448 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 316 KB Output is correct
18 Correct 1 ms 460 KB Output is correct
19 Correct 1 ms 460 KB Output is correct
20 Correct 1 ms 460 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 460 KB Output is correct
25 Correct 2 ms 460 KB Output is correct
26 Correct 1 ms 460 KB Output is correct
27 Correct 1 ms 204 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
29 Correct 1 ms 448 KB Output is correct
30 Correct 1 ms 460 KB Output is correct
31 Correct 2 ms 496 KB Output is correct
32 Correct 2 ms 460 KB Output is correct
33 Correct 1 ms 588 KB Output is correct
34 Correct 2 ms 576 KB Output is correct
35 Correct 1 ms 460 KB Output is correct
36 Correct 1 ms 588 KB Output is correct
37 Correct 2 ms 580 KB Output is correct
38 Correct 1 ms 204 KB Output is correct
39 Correct 1 ms 460 KB Output is correct
40 Correct 1 ms 440 KB Output is correct
41 Correct 1 ms 316 KB Output is correct
42 Correct 2 ms 460 KB Output is correct
43 Runtime error 65 ms 10408 KB Execution killed with signal 6
44 Halted 0 ms 0 KB -