# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
881441 |
2023-12-01T08:53:30 Z |
nima_aryan |
Naan (JOI19_naan) |
C++17 |
|
319 ms |
116564 KB |
/**
* author: NimaAryan
* created: 2023-12-01 08:14:38
**/
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "algo/debug.h"
#endif
using i64 = long long;
using i128 = __int128;
constexpr i64 inf = 1E14;
struct Z {
i64 A = 0;
i64 B = 1;
Z() { }
Z(i64 A, i64 B) : A(A), B(B) { }
bool operator<(const Z& other) const {
return (i128) A * other.B < (i128) other.A * B;
}
};
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int N, L;
cin >> N >> L;
vector V(N, vector<i64>(L));
for (int i = 0; i < N; ++i) {
for (int j = 0; j < L; ++j) {
cin >> V[i][j];
}
}
vector C(N, vector<Z>(N));
for (int i = 0; i < N; ++i) {
i64 sum = accumulate(V[i].begin(), V[i].end(), 0LL);
i64 pref = 0;
Z res{};
for (int j = 0, k = 0; j < N; ++j) {
while (k < L && pref * N < sum * (j + 1)) {
pref += V[i][k++];
}
if (Z(k, 1) < res) {
res.A += sum;
} else {
res = Z(1LL * N * V[i][k - 1] * (k - 1) + sum * (j + 1) - N * (pref - V[i][k - 1]), N * V[i][k - 1]);
}
C[i][j] = res;
}
}
vector<Z> H;
vector<bool> used(N);
vector<int> P;
for (int j = 0; j < N; ++j) {
Z best(inf, 1);
int who = -1;
for (int i = 0; i < N; ++i) {
if (!used[i] && C[i][j] < best) {
tie(best, who) = pair(C[i][j], i);
}
}
H.push_back(best);
P.push_back(who);
used[who] = true;
}
for (int i = 0; i < N - 1; ++i) {
cout << H[i].A << " " << H[i].B << "\n";
}
for (int i = 0; i < N; ++i) {
cout << P[i] + 1 << " \n"[i + 1 == N];
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
472 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
360 KB |
Output is correct |
11 |
Correct |
1 ms |
352 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
352 KB |
Output is correct |
14 |
Correct |
1 ms |
528 KB |
Output is correct |
15 |
Correct |
1 ms |
356 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
472 KB |
Output is correct |
4 |
Correct |
1 ms |
352 KB |
Output is correct |
5 |
Correct |
1 ms |
352 KB |
Output is correct |
6 |
Correct |
1 ms |
472 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
460 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
564 KB |
Output is correct |
11 |
Correct |
1 ms |
600 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
344 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
588 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
0 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
0 ms |
348 KB |
Output is correct |
27 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
472 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
360 KB |
Output is correct |
11 |
Correct |
1 ms |
352 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
352 KB |
Output is correct |
14 |
Correct |
1 ms |
528 KB |
Output is correct |
15 |
Correct |
1 ms |
356 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
472 KB |
Output is correct |
19 |
Correct |
1 ms |
352 KB |
Output is correct |
20 |
Correct |
1 ms |
352 KB |
Output is correct |
21 |
Correct |
1 ms |
472 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
460 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
564 KB |
Output is correct |
26 |
Correct |
1 ms |
600 KB |
Output is correct |
27 |
Correct |
0 ms |
348 KB |
Output is correct |
28 |
Correct |
1 ms |
348 KB |
Output is correct |
29 |
Correct |
1 ms |
348 KB |
Output is correct |
30 |
Correct |
1 ms |
344 KB |
Output is correct |
31 |
Correct |
1 ms |
348 KB |
Output is correct |
32 |
Correct |
1 ms |
348 KB |
Output is correct |
33 |
Correct |
1 ms |
348 KB |
Output is correct |
34 |
Correct |
1 ms |
348 KB |
Output is correct |
35 |
Correct |
1 ms |
348 KB |
Output is correct |
36 |
Correct |
1 ms |
588 KB |
Output is correct |
37 |
Correct |
1 ms |
348 KB |
Output is correct |
38 |
Correct |
0 ms |
348 KB |
Output is correct |
39 |
Correct |
1 ms |
348 KB |
Output is correct |
40 |
Correct |
1 ms |
348 KB |
Output is correct |
41 |
Correct |
0 ms |
348 KB |
Output is correct |
42 |
Correct |
1 ms |
348 KB |
Output is correct |
43 |
Correct |
23 ms |
9028 KB |
Output is correct |
44 |
Correct |
146 ms |
53096 KB |
Output is correct |
45 |
Correct |
97 ms |
25396 KB |
Output is correct |
46 |
Correct |
15 ms |
3156 KB |
Output is correct |
47 |
Correct |
102 ms |
34644 KB |
Output is correct |
48 |
Correct |
92 ms |
64172 KB |
Output is correct |
49 |
Correct |
36 ms |
17092 KB |
Output is correct |
50 |
Correct |
158 ms |
86880 KB |
Output is correct |
51 |
Correct |
90 ms |
34656 KB |
Output is correct |
52 |
Correct |
176 ms |
78876 KB |
Output is correct |
53 |
Correct |
127 ms |
67644 KB |
Output is correct |
54 |
Correct |
1 ms |
348 KB |
Output is correct |
55 |
Correct |
29 ms |
32932 KB |
Output is correct |
56 |
Correct |
112 ms |
48208 KB |
Output is correct |
57 |
Correct |
87 ms |
39828 KB |
Output is correct |
58 |
Correct |
117 ms |
65236 KB |
Output is correct |
59 |
Correct |
101 ms |
40900 KB |
Output is correct |
60 |
Correct |
319 ms |
116564 KB |
Output is correct |
61 |
Correct |
292 ms |
116408 KB |
Output is correct |
62 |
Correct |
301 ms |
115792 KB |
Output is correct |
63 |
Correct |
293 ms |
116560 KB |
Output is correct |
64 |
Correct |
309 ms |
116560 KB |
Output is correct |
65 |
Correct |
233 ms |
103128 KB |
Output is correct |
66 |
Correct |
238 ms |
103248 KB |
Output is correct |
67 |
Correct |
221 ms |
103124 KB |
Output is correct |
68 |
Correct |
104 ms |
49328 KB |
Output is correct |
69 |
Correct |
130 ms |
49108 KB |
Output is correct |
70 |
Correct |
120 ms |
59756 KB |
Output is correct |
71 |
Correct |
184 ms |
75188 KB |
Output is correct |