#include<iostream>
#include<vector>
#include<set>
#include<bits/stdc++.h>
#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;
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:24:27: warning: unused variable 'all' [-Wunused-variable]
24 | int k = 0, p = 0, all = 0;
| ^~~
naan.cpp:56:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
56 | for(int i = 0; i < ans.size(); i++) cout << ans[i] << " ";
| ~~^~~~~~~~~~~~
naan.cpp:40:9: warning: unused variable 'C' [-Wunused-variable]
40 | 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 |
5032 KB |
Output is correct |
5 |
Correct |
3 ms |
4948 KB |
Output is correct |
6 |
Correct |
3 ms |
5004 KB |
Output is correct |
7 |
Correct |
3 ms |
5076 KB |
Output is correct |
8 |
Incorrect |
3 ms |
4948 KB |
Not a fair distribution. |
9 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Correct |
4 ms |
5008 KB |
Output is correct |
3 |
Correct |
4 ms |
5016 KB |
Output is correct |
4 |
Correct |
4 ms |
5008 KB |
Output is correct |
5 |
Correct |
4 ms |
4948 KB |
Output is correct |
6 |
Correct |
4 ms |
5004 KB |
Output is correct |
7 |
Correct |
4 ms |
5016 KB |
Output is correct |
8 |
Correct |
3 ms |
5008 KB |
Output is correct |
9 |
Correct |
4 ms |
5032 KB |
Output is correct |
10 |
Correct |
5 ms |
4948 KB |
Output is correct |
11 |
Correct |
4 ms |
4948 KB |
Output is correct |
12 |
Correct |
3 ms |
5000 KB |
Output is correct |
13 |
Correct |
4 ms |
4948 KB |
Output is correct |
14 |
Correct |
5 ms |
4948 KB |
Output is correct |
15 |
Correct |
5 ms |
5012 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 |
5 ms |
4948 KB |
Output is correct |
20 |
Correct |
5 ms |
5032 KB |
Output is correct |
21 |
Correct |
4 ms |
5016 KB |
Output is correct |
22 |
Correct |
4 ms |
4948 KB |
Output is correct |
23 |
Correct |
3 ms |
4948 KB |
Output is correct |
24 |
Correct |
4 ms |
4948 KB |
Output is correct |
25 |
Correct |
4 ms |
5016 KB |
Output is correct |
26 |
Correct |
3 ms |
5008 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 |
5032 KB |
Output is correct |
5 |
Correct |
3 ms |
4948 KB |
Output is correct |
6 |
Correct |
3 ms |
5004 KB |
Output is correct |
7 |
Correct |
3 ms |
5076 KB |
Output is correct |
8 |
Incorrect |
3 ms |
4948 KB |
Not a fair distribution. |
9 |
Halted |
0 ms |
0 KB |
- |