#include<iostream>
#include<vector>
#include<set>
#include<bits/stdc++.h>
#define int long long
#define f first
#define s second
//#define int long long
#define pii pair<int,int>
using namespace std;
const int N = 2e5 + 5, inf = 2e9; // !
int tot[N];
vector<pair<int, pair<int,int>> > x[N];
signed main() {
int n, L;
cin >> n >> L;
for(int i = 1; i <= n; i++) {
vector<int> v(L + 2);
for(int j = 1; j <= L; j++) {
cin >> v[j];
tot[i] += v[j];
v[j] *= n;
}
int k = 0, p = 0, all = 0;
while((int)x[i].size() < n) {
int cur = 0;
if(v[k] - p >= tot[i]) {
p += tot[i];
x[i].push_back({k - 1, {p, v[k]}});
if(p == v[k]) ++k, p = 0;
continue;
} else cur = v[k] - p, ++k;
while(k <= L && cur + v[k] <= tot[i]) cur += v[k], ++k;
p = tot[i] - cur;
x[i].push_back({k - 1, {p, (p == 0 ? 1 : v[k])}});
}
}
vector<int> f(n + 2), ans;
int C = 0;
for(int i = 0; i + 1 < n; i++) {
int cur = 0;
for(int j = 1; j <= n; j++) {
if(f[j]) continue;
if(!cur || x[j][i].f < x[cur][i].f || (x[j][i].f == x[cur][i].f && x[j][i].s.f * x[cur][i].s.s < x[cur][i].s.f * x[j][i].s.s)) cur = j;
}
f[cur] = 1;
int g = __gcd(x[cur][i].s.f, x[cur][i].s.s);
x[cur][i].s.f /= g; x[cur][i].s.s /= g;
x[cur][i].s.f += x[cur][i].s.s * x[cur][i].f;
assert(x[cur][i].s.s <= 1e9);
cout << x[cur][i].s.f << " " << x[cur][i].s.s << "\n";
ans.push_back(cur);
}
for(int i = 1; i <= n; i++) if(!f[i]) ans.push_back(i);
for(int i = 0; i < ans.size(); i++) cout << ans[i] << " ";
}
Compilation message
naan.cpp: In function 'int main()':
naan.cpp:25:27: warning: unused variable 'all' [-Wunused-variable]
25 | int k = 0, p = 0, all = 0;
| ^~~
naan.cpp:58:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
58 | for(int i = 0; i < ans.size(); i++) cout << ans[i] << " ";
| ~~^~~~~~~~~~~~
naan.cpp:41:9: warning: unused variable 'C' [-Wunused-variable]
41 | int C = 0;
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Correct |
4 ms |
4948 KB |
Output is correct |
3 |
Correct |
4 ms |
4948 KB |
Output is correct |
4 |
Correct |
4 ms |
4948 KB |
Output is correct |
5 |
Correct |
3 ms |
4948 KB |
Output is correct |
6 |
Correct |
3 ms |
4948 KB |
Output is correct |
7 |
Correct |
3 ms |
4948 KB |
Output is correct |
8 |
Correct |
3 ms |
4948 KB |
Output is correct |
9 |
Correct |
3 ms |
5004 KB |
Output is correct |
10 |
Correct |
3 ms |
4948 KB |
Output is correct |
11 |
Correct |
4 ms |
4948 KB |
Output is correct |
12 |
Correct |
4 ms |
5012 KB |
Output is correct |
13 |
Correct |
4 ms |
5016 KB |
Output is correct |
14 |
Correct |
4 ms |
5012 KB |
Output is correct |
15 |
Correct |
4 ms |
4948 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Correct |
3 ms |
4948 KB |
Output is correct |
3 |
Correct |
4 ms |
4948 KB |
Output is correct |
4 |
Correct |
5 ms |
4948 KB |
Output is correct |
5 |
Correct |
4 ms |
4948 KB |
Output is correct |
6 |
Correct |
3 ms |
4948 KB |
Output is correct |
7 |
Correct |
3 ms |
4948 KB |
Output is correct |
8 |
Correct |
4 ms |
4948 KB |
Output is correct |
9 |
Correct |
4 ms |
4948 KB |
Output is correct |
10 |
Correct |
4 ms |
4948 KB |
Output is correct |
11 |
Correct |
3 ms |
4948 KB |
Output is correct |
12 |
Correct |
2 ms |
4948 KB |
Output is correct |
13 |
Correct |
4 ms |
4948 KB |
Output is correct |
14 |
Correct |
3 ms |
4948 KB |
Output is correct |
15 |
Correct |
4 ms |
4948 KB |
Output is correct |
16 |
Correct |
4 ms |
4948 KB |
Output is correct |
17 |
Correct |
4 ms |
4948 KB |
Output is correct |
18 |
Correct |
4 ms |
4948 KB |
Output is correct |
19 |
Correct |
4 ms |
4948 KB |
Output is correct |
20 |
Correct |
4 ms |
4948 KB |
Output is correct |
21 |
Correct |
4 ms |
4948 KB |
Output is correct |
22 |
Correct |
4 ms |
5016 KB |
Output is correct |
23 |
Correct |
3 ms |
4948 KB |
Output is correct |
24 |
Correct |
3 ms |
4948 KB |
Output is correct |
25 |
Correct |
3 ms |
4948 KB |
Output is correct |
26 |
Correct |
4 ms |
5012 KB |
Output is correct |
27 |
Correct |
4 ms |
4948 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Correct |
4 ms |
4948 KB |
Output is correct |
3 |
Correct |
4 ms |
4948 KB |
Output is correct |
4 |
Correct |
4 ms |
4948 KB |
Output is correct |
5 |
Correct |
3 ms |
4948 KB |
Output is correct |
6 |
Correct |
3 ms |
4948 KB |
Output is correct |
7 |
Correct |
3 ms |
4948 KB |
Output is correct |
8 |
Correct |
3 ms |
4948 KB |
Output is correct |
9 |
Correct |
3 ms |
5004 KB |
Output is correct |
10 |
Correct |
3 ms |
4948 KB |
Output is correct |
11 |
Correct |
4 ms |
4948 KB |
Output is correct |
12 |
Correct |
4 ms |
5012 KB |
Output is correct |
13 |
Correct |
4 ms |
5016 KB |
Output is correct |
14 |
Correct |
4 ms |
5012 KB |
Output is correct |
15 |
Correct |
4 ms |
4948 KB |
Output is correct |
16 |
Correct |
3 ms |
4948 KB |
Output is correct |
17 |
Correct |
3 ms |
4948 KB |
Output is correct |
18 |
Correct |
4 ms |
4948 KB |
Output is correct |
19 |
Correct |
5 ms |
4948 KB |
Output is correct |
20 |
Correct |
4 ms |
4948 KB |
Output is correct |
21 |
Correct |
3 ms |
4948 KB |
Output is correct |
22 |
Correct |
3 ms |
4948 KB |
Output is correct |
23 |
Correct |
4 ms |
4948 KB |
Output is correct |
24 |
Correct |
4 ms |
4948 KB |
Output is correct |
25 |
Correct |
4 ms |
4948 KB |
Output is correct |
26 |
Correct |
3 ms |
4948 KB |
Output is correct |
27 |
Correct |
2 ms |
4948 KB |
Output is correct |
28 |
Correct |
4 ms |
4948 KB |
Output is correct |
29 |
Correct |
3 ms |
4948 KB |
Output is correct |
30 |
Correct |
4 ms |
4948 KB |
Output is correct |
31 |
Correct |
4 ms |
4948 KB |
Output is correct |
32 |
Correct |
4 ms |
4948 KB |
Output is correct |
33 |
Correct |
4 ms |
4948 KB |
Output is correct |
34 |
Correct |
4 ms |
4948 KB |
Output is correct |
35 |
Correct |
4 ms |
4948 KB |
Output is correct |
36 |
Correct |
4 ms |
4948 KB |
Output is correct |
37 |
Correct |
4 ms |
5016 KB |
Output is correct |
38 |
Correct |
3 ms |
4948 KB |
Output is correct |
39 |
Correct |
3 ms |
4948 KB |
Output is correct |
40 |
Correct |
3 ms |
4948 KB |
Output is correct |
41 |
Correct |
4 ms |
5012 KB |
Output is correct |
42 |
Correct |
4 ms |
4948 KB |
Output is correct |
43 |
Correct |
89 ms |
16056 KB |
Output is correct |
44 |
Correct |
486 ms |
64152 KB |
Output is correct |
45 |
Correct |
324 ms |
26292 KB |
Output is correct |
46 |
Correct |
51 ms |
6428 KB |
Output is correct |
47 |
Correct |
376 ms |
36684 KB |
Output is correct |
48 |
Correct |
206 ms |
96868 KB |
Output is correct |
49 |
Correct |
88 ms |
26888 KB |
Output is correct |
50 |
Correct |
424 ms |
105432 KB |
Output is correct |
51 |
Correct |
246 ms |
38348 KB |
Output is correct |
52 |
Correct |
487 ms |
87740 KB |
Output is correct |
53 |
Correct |
376 ms |
83344 KB |
Output is correct |
54 |
Correct |
4 ms |
4948 KB |
Output is correct |
55 |
Correct |
77 ms |
57420 KB |
Output is correct |
56 |
Correct |
314 ms |
53852 KB |
Output is correct |
57 |
Correct |
277 ms |
47292 KB |
Output is correct |
58 |
Correct |
317 ms |
83724 KB |
Output is correct |
59 |
Correct |
300 ms |
42900 KB |
Output is correct |
60 |
Correct |
1084 ms |
123052 KB |
Output is correct |
61 |
Correct |
1064 ms |
123124 KB |
Output is correct |
62 |
Correct |
1068 ms |
122812 KB |
Output is correct |
63 |
Correct |
1325 ms |
123316 KB |
Output is correct |
64 |
Correct |
1133 ms |
123200 KB |
Output is correct |
65 |
Correct |
658 ms |
109764 KB |
Output is correct |
66 |
Correct |
612 ms |
109912 KB |
Output is correct |
67 |
Correct |
655 ms |
109972 KB |
Output is correct |
68 |
Correct |
348 ms |
61428 KB |
Output is correct |
69 |
Correct |
418 ms |
53708 KB |
Output is correct |
70 |
Correct |
412 ms |
75940 KB |
Output is correct |
71 |
Correct |
638 ms |
81680 KB |
Output is correct |