#include <bits/stdc++.h>
#include <cassert>
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx,avx2,fma")
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
#define MAX 2020
#define MAXQ 101010
#define INF 1000000000000000000
#define MOD 998244353
#define bb ' '
#define ln '\n'
#define Ln '\n'
ll V[MAX][MAX];
ll sum[MAX][MAX];
int N, L;
bool operator>(pll p1, pll p2) { return (__int128)p1.first * p2.second > (__int128)p2.first * p1.second; }
bool operator<=(pll p1, ll p2) { return (__int128)p1.first <= (__int128)p2 * p1.second; }
pll get(int ind, int v) {
int l, r;
l = 0;
r = L;
while (r - l > 1) {
int m = l + r >> 1;
if (pll(v * sum[ind][L], N) <= sum[ind][m]) r = m;
else l = m;
}
r--;
return pll(V[ind][r + 1] * N * r + sum[ind][L] * v - sum[ind][r] * N, V[ind][r + 1] * N);
}
pll ans[MAX];
int P[MAX];
int vis[MAX];
signed main() {
ios::sync_with_stdio(false), cin.tie(0);
cin >> N >> L;
int i, j;
for (i = 1; i <= N; i++) for (j = 1; j <= L; j++) cin >> V[i][j], sum[i][j] = sum[i][j - 1] + V[i][j];
for (i = 1; i <= N; i++) {
pll mn = pll(L + 1, 1);
int mv = 0;
for (j = 1; j <= N; j++) {
if (vis[j]) continue;
pll v = get(j, i);
if (mn > v) mn = v, mv = j;
}
P[i] = mv;
vis[mv] = 1;
ans[i] = mn;
ll g = gcd(ans[i].first, ans[i].second);
ans[i].first /= g;
ans[i].second /= g;
if (i < N) cout << ans[i].first << bb << ans[i].second << ln;
}
for (i = 1; i <= N; i++) cout << P[i] << bb;
}
Compilation message
naan.cpp: In function 'pll get(int, int)':
naan.cpp:28:13: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
28 | int m = l + r >> 1;
| ~~^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
0 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2392 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
1 ms |
2396 KB |
Output is correct |
13 |
Correct |
1 ms |
2396 KB |
Output is correct |
14 |
Correct |
1 ms |
2396 KB |
Output is correct |
15 |
Correct |
1 ms |
2396 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
0 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
0 ms |
2520 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
1 ms |
2392 KB |
Output is correct |
12 |
Correct |
0 ms |
2396 KB |
Output is correct |
13 |
Correct |
1 ms |
2396 KB |
Output is correct |
14 |
Correct |
1 ms |
2396 KB |
Output is correct |
15 |
Correct |
1 ms |
2396 KB |
Output is correct |
16 |
Correct |
1 ms |
2396 KB |
Output is correct |
17 |
Correct |
1 ms |
2396 KB |
Output is correct |
18 |
Correct |
1 ms |
2396 KB |
Output is correct |
19 |
Correct |
1 ms |
2396 KB |
Output is correct |
20 |
Correct |
1 ms |
2588 KB |
Output is correct |
21 |
Correct |
2 ms |
2396 KB |
Output is correct |
22 |
Correct |
1 ms |
2396 KB |
Output is correct |
23 |
Correct |
0 ms |
2396 KB |
Output is correct |
24 |
Correct |
1 ms |
2396 KB |
Output is correct |
25 |
Correct |
1 ms |
2396 KB |
Output is correct |
26 |
Correct |
0 ms |
2396 KB |
Output is correct |
27 |
Correct |
1 ms |
2396 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
0 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2392 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
1 ms |
2396 KB |
Output is correct |
13 |
Correct |
1 ms |
2396 KB |
Output is correct |
14 |
Correct |
1 ms |
2396 KB |
Output is correct |
15 |
Correct |
1 ms |
2396 KB |
Output is correct |
16 |
Correct |
1 ms |
2396 KB |
Output is correct |
17 |
Correct |
0 ms |
2396 KB |
Output is correct |
18 |
Correct |
1 ms |
2396 KB |
Output is correct |
19 |
Correct |
1 ms |
2396 KB |
Output is correct |
20 |
Correct |
1 ms |
2396 KB |
Output is correct |
21 |
Correct |
1 ms |
2396 KB |
Output is correct |
22 |
Correct |
0 ms |
2520 KB |
Output is correct |
23 |
Correct |
1 ms |
2396 KB |
Output is correct |
24 |
Correct |
1 ms |
2396 KB |
Output is correct |
25 |
Correct |
1 ms |
2396 KB |
Output is correct |
26 |
Correct |
1 ms |
2392 KB |
Output is correct |
27 |
Correct |
0 ms |
2396 KB |
Output is correct |
28 |
Correct |
1 ms |
2396 KB |
Output is correct |
29 |
Correct |
1 ms |
2396 KB |
Output is correct |
30 |
Correct |
1 ms |
2396 KB |
Output is correct |
31 |
Correct |
1 ms |
2396 KB |
Output is correct |
32 |
Correct |
1 ms |
2396 KB |
Output is correct |
33 |
Correct |
1 ms |
2396 KB |
Output is correct |
34 |
Correct |
1 ms |
2396 KB |
Output is correct |
35 |
Correct |
1 ms |
2588 KB |
Output is correct |
36 |
Correct |
2 ms |
2396 KB |
Output is correct |
37 |
Correct |
1 ms |
2396 KB |
Output is correct |
38 |
Correct |
0 ms |
2396 KB |
Output is correct |
39 |
Correct |
1 ms |
2396 KB |
Output is correct |
40 |
Correct |
1 ms |
2396 KB |
Output is correct |
41 |
Correct |
0 ms |
2396 KB |
Output is correct |
42 |
Correct |
1 ms |
2396 KB |
Output is correct |
43 |
Correct |
26 ms |
16104 KB |
Output is correct |
44 |
Correct |
233 ms |
51596 KB |
Output is correct |
45 |
Correct |
92 ms |
32596 KB |
Output is correct |
46 |
Correct |
11 ms |
7772 KB |
Output is correct |
47 |
Correct |
132 ms |
40584 KB |
Output is correct |
48 |
Correct |
205 ms |
46156 KB |
Output is correct |
49 |
Correct |
50 ms |
27772 KB |
Output is correct |
50 |
Correct |
377 ms |
65364 KB |
Output is correct |
51 |
Correct |
128 ms |
39096 KB |
Output is correct |
52 |
Correct |
344 ms |
62652 KB |
Output is correct |
53 |
Correct |
291 ms |
57172 KB |
Output is correct |
54 |
Correct |
1 ms |
2396 KB |
Output is correct |
55 |
Correct |
52 ms |
26120 KB |
Output is correct |
56 |
Correct |
191 ms |
46660 KB |
Output is correct |
57 |
Correct |
158 ms |
41904 KB |
Output is correct |
58 |
Correct |
258 ms |
53328 KB |
Output is correct |
59 |
Correct |
170 ms |
40864 KB |
Output is correct |
60 |
Correct |
514 ms |
85840 KB |
Output is correct |
61 |
Correct |
491 ms |
85840 KB |
Output is correct |
62 |
Correct |
502 ms |
85836 KB |
Output is correct |
63 |
Correct |
567 ms |
86356 KB |
Output is correct |
64 |
Correct |
525 ms |
85840 KB |
Output is correct |
65 |
Correct |
438 ms |
72784 KB |
Output is correct |
66 |
Correct |
440 ms |
72592 KB |
Output is correct |
67 |
Correct |
476 ms |
72528 KB |
Output is correct |
68 |
Correct |
205 ms |
47184 KB |
Output is correct |
69 |
Correct |
197 ms |
48332 KB |
Output is correct |
70 |
Correct |
264 ms |
50768 KB |
Output is correct |
71 |
Correct |
330 ms |
62804 KB |
Output is correct |