Submission #711237

# Submission time Handle Problem Language Result Execution time Memory
711237 2023-03-16T10:53:26 Z youngyojun Naan (JOI19_naan) C++17
100 / 100
349 ms 79840 KB
#include <bits/stdc++.h>
#define fi first
#define se second
#define allv(V) (V).begin(),(V).end()
using namespace std;
typedef long long ll;
typedef __int128_t lll;
typedef pair<ll, ll> pll;
lll operator * (pll a, pll b) { return lll(a.fi)*b.se - lll(a.se)*b.fi; }

pll B[2005][2005];
ll A[2005];

int C[2005];

int N, L;

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

	cin >> N >> L;
	for(int i = 0; i < N; i++) {
		for(int j = 0; j < L; j++) {
			ll x; cin >> x;
			A[j+1] = A[j] + x;
		}
		ll S = A[L];
		int k = 1, n = 0;
		while(k < N) {
			while(A[n+1]*N <= S*k) n++;
			ll u = S*k - A[n]*N, d = (A[n+1]-A[n])*N;
			B[i][k++] = {u + d*n, d};
		}
	}

	vector<int> V(N); iota(allv(V), 0);
	for(int k = 1; k < N; k++)
		swap(V[k-1], *min_element(k-1+allv(V), [&](int a, int b) {
			return B[a][k] * B[b][k] < 0;
		}));
	
	for(int k = 1; k < N; k++) {
		pll p = B[V[k-1]][k];
		cout << p.fi << ' ' << p.se << '\n';
	}
	for(int v : V) cout << v+1 << ' ';
	cout << '\n';

	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 324 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 368 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 2 ms 336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 2 ms 340 KB Output is correct
10 Correct 2 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 376 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 2 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 2 ms 360 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 324 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 368 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 2 ms 336 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 2 ms 340 KB Output is correct
25 Correct 2 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 376 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 1 ms 340 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 1 ms 340 KB Output is correct
37 Correct 2 ms 340 KB Output is correct
38 Correct 1 ms 340 KB Output is correct
39 Correct 2 ms 360 KB Output is correct
40 Correct 1 ms 340 KB Output is correct
41 Correct 1 ms 340 KB Output is correct
42 Correct 1 ms 340 KB Output is correct
43 Correct 26 ms 7884 KB Output is correct
44 Correct 153 ms 35624 KB Output is correct
45 Correct 121 ms 11192 KB Output is correct
46 Correct 15 ms 1356 KB Output is correct
47 Correct 121 ms 19972 KB Output is correct
48 Correct 88 ms 59504 KB Output is correct
49 Correct 36 ms 15728 KB Output is correct
50 Correct 174 ms 62940 KB Output is correct
51 Correct 94 ms 25192 KB Output is correct
52 Correct 196 ms 59988 KB Output is correct
53 Correct 139 ms 56340 KB Output is correct
54 Correct 1 ms 340 KB Output is correct
55 Correct 34 ms 37116 KB Output is correct
56 Correct 116 ms 35976 KB Output is correct
57 Correct 97 ms 31320 KB Output is correct
58 Correct 127 ms 56308 KB Output is correct
59 Correct 110 ms 28220 KB Output is correct
60 Correct 330 ms 72872 KB Output is correct
61 Correct 333 ms 74664 KB Output is correct
62 Correct 341 ms 79840 KB Output is correct
63 Correct 334 ms 79172 KB Output is correct
64 Correct 349 ms 79344 KB Output is correct
65 Correct 244 ms 71776 KB Output is correct
66 Correct 234 ms 71736 KB Output is correct
67 Correct 243 ms 71752 KB Output is correct
68 Correct 116 ms 41676 KB Output is correct
69 Correct 142 ms 37064 KB Output is correct
70 Correct 139 ms 51696 KB Output is correct
71 Correct 207 ms 57220 KB Output is correct