#include <bits/stdc++.h>
using namespace std;
using namespace std::placeholders;
#define llong long long
#define xx first
#define yy second
#define len(x) ((int)x.size())
#define rep(i,n) for (int i = -1; ++ i < n; )
#define rep1(i,n) for (int i = 0; i ++ < n; )
#define all(x) x.begin(), x.end()
// #define rand __rand
// mt19937 rng(chrono::system_clock::now().time_since_epoch().count()); // or mt19937_64
// template<class T = int> T rand(T range = numeric_limits<T>::max()) {
// return (T)(rng() % range);
// }
struct frac_with_num {
llong int_part, numerator, denominator;
frac_with_num(llong num = 0): int_part(num), numerator(0), denominator(1) {}
frac_with_num(llong whole, llong num, llong den): int_part(whole), numerator(num), denominator(den) {
norm();
}
frac_with_num(llong num, llong den): frac_with_num(0, num, den) {}
frac_with_num& norm() {
if (numerator > denominator) {
int_part += numerator / denominator;
numerator %= denominator;
}
llong g = __gcd(numerator, denominator);
numerator /= g;
denominator /= g;
return *this;
}
};
bool operator < (const frac_with_num& u, const frac_with_num& v) {
if (u.int_part == v.int_part) return u.numerator * v.denominator < u.denominator * v.numerator;
return u.int_part < v.int_part;
}
ostream& operator<<(ostream& cout, const frac_with_num& u) {
return cout << u.int_part * u.denominator + u.numerator << ' ' << u.denominator;
}
#define maxn 2020
int n, l;
llong v[maxn][maxn];
llong sum[maxn];
vector<frac_with_num> split[maxn];
int main(void) {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> n >> l;
rep(i, n) {
sum[i] = 0;
rep(f, l) {
cin >> v[i][f];
sum[i] += v[i][f];
}
}
rep(i, n) {
llong cur_sum_nan = 0;
int cur_nan = 0;
rep1(num_cur_part, n - 1) {
for (; (cur_sum_nan + v[i][cur_nan]) * n <= sum[i] * num_cur_part; ++cur_nan)
cur_sum_nan += v[i][cur_nan];
llong rest = sum[i] * num_cur_part - cur_sum_nan * n;
split[i].emplace_back(cur_nan, rest, n * v[i][cur_nan]);
// clog << cur_nan << ' ' << rest << ' ' << cur_sum_nan << endl;
}
split[i].emplace_back(l);
// clog << i << ": ";
// for (auto f: split[i]) clog << f << "; ";
// clog << endl;
}
vector<int> ans;
set<int> has;
rep(i, n) has.insert(i);
rep(cur_part, n) {
auto cur = *min_element(has.begin(), has.end(), [&](int lhs, int rhs) {return split[lhs][cur_part] < split[rhs][cur_part]; } );
ans.emplace_back(cur);
has.erase(cur);
if (cur_part != n - 1) cout << split[cur][cur_part] << '\n';
}
for (auto i: ans) cout << i + 1 << ' ';
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
504 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
448 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
380 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
2 ms |
376 KB |
Output is correct |
15 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
3 ms |
504 KB |
Output is correct |
4 |
Correct |
3 ms |
504 KB |
Output is correct |
5 |
Correct |
3 ms |
504 KB |
Output is correct |
6 |
Correct |
2 ms |
504 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
504 KB |
Output is correct |
9 |
Correct |
3 ms |
504 KB |
Output is correct |
10 |
Correct |
3 ms |
504 KB |
Output is correct |
11 |
Correct |
3 ms |
504 KB |
Output is correct |
12 |
Correct |
2 ms |
380 KB |
Output is correct |
13 |
Correct |
2 ms |
504 KB |
Output is correct |
14 |
Correct |
3 ms |
508 KB |
Output is correct |
15 |
Correct |
3 ms |
532 KB |
Output is correct |
16 |
Correct |
3 ms |
504 KB |
Output is correct |
17 |
Correct |
3 ms |
504 KB |
Output is correct |
18 |
Correct |
3 ms |
504 KB |
Output is correct |
19 |
Correct |
3 ms |
504 KB |
Output is correct |
20 |
Correct |
3 ms |
504 KB |
Output is correct |
21 |
Correct |
3 ms |
532 KB |
Output is correct |
22 |
Correct |
3 ms |
504 KB |
Output is correct |
23 |
Correct |
2 ms |
376 KB |
Output is correct |
24 |
Correct |
3 ms |
504 KB |
Output is correct |
25 |
Correct |
3 ms |
504 KB |
Output is correct |
26 |
Correct |
2 ms |
504 KB |
Output is correct |
27 |
Correct |
3 ms |
508 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
504 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
448 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
380 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
2 ms |
376 KB |
Output is correct |
15 |
Correct |
2 ms |
376 KB |
Output is correct |
16 |
Correct |
2 ms |
376 KB |
Output is correct |
17 |
Correct |
2 ms |
376 KB |
Output is correct |
18 |
Correct |
3 ms |
504 KB |
Output is correct |
19 |
Correct |
3 ms |
504 KB |
Output is correct |
20 |
Correct |
3 ms |
504 KB |
Output is correct |
21 |
Correct |
2 ms |
504 KB |
Output is correct |
22 |
Correct |
2 ms |
376 KB |
Output is correct |
23 |
Correct |
2 ms |
504 KB |
Output is correct |
24 |
Correct |
3 ms |
504 KB |
Output is correct |
25 |
Correct |
3 ms |
504 KB |
Output is correct |
26 |
Correct |
3 ms |
504 KB |
Output is correct |
27 |
Correct |
2 ms |
380 KB |
Output is correct |
28 |
Correct |
2 ms |
504 KB |
Output is correct |
29 |
Correct |
3 ms |
508 KB |
Output is correct |
30 |
Correct |
3 ms |
532 KB |
Output is correct |
31 |
Correct |
3 ms |
504 KB |
Output is correct |
32 |
Correct |
3 ms |
504 KB |
Output is correct |
33 |
Correct |
3 ms |
504 KB |
Output is correct |
34 |
Correct |
3 ms |
504 KB |
Output is correct |
35 |
Correct |
3 ms |
504 KB |
Output is correct |
36 |
Correct |
3 ms |
532 KB |
Output is correct |
37 |
Correct |
3 ms |
504 KB |
Output is correct |
38 |
Correct |
2 ms |
376 KB |
Output is correct |
39 |
Correct |
3 ms |
504 KB |
Output is correct |
40 |
Correct |
3 ms |
504 KB |
Output is correct |
41 |
Correct |
2 ms |
504 KB |
Output is correct |
42 |
Correct |
3 ms |
508 KB |
Output is correct |
43 |
Correct |
151 ms |
15968 KB |
Output is correct |
44 |
Correct |
896 ms |
78712 KB |
Output is correct |
45 |
Correct |
314 ms |
32780 KB |
Output is correct |
46 |
Correct |
60 ms |
3836 KB |
Output is correct |
47 |
Correct |
520 ms |
47224 KB |
Output is correct |
48 |
Correct |
1369 ms |
106732 KB |
Output is correct |
49 |
Correct |
293 ms |
29944 KB |
Output is correct |
50 |
Correct |
1597 ms |
128804 KB |
Output is correct |
51 |
Correct |
527 ms |
50396 KB |
Output is correct |
52 |
Correct |
1305 ms |
110504 KB |
Output is correct |
53 |
Correct |
1206 ms |
103420 KB |
Output is correct |
54 |
Correct |
3 ms |
504 KB |
Output is correct |
55 |
Correct |
666 ms |
59872 KB |
Output is correct |
56 |
Correct |
732 ms |
70008 KB |
Output is correct |
57 |
Correct |
606 ms |
60984 KB |
Output is correct |
58 |
Correct |
1108 ms |
101428 KB |
Output is correct |
59 |
Correct |
586 ms |
56492 KB |
Output is correct |
60 |
Correct |
1409 ms |
150392 KB |
Output is correct |
61 |
Correct |
1475 ms |
150212 KB |
Output is correct |
62 |
Correct |
1678 ms |
150000 KB |
Output is correct |
63 |
Correct |
1552 ms |
150504 KB |
Output is correct |
64 |
Correct |
1478 ms |
150340 KB |
Output is correct |
65 |
Correct |
1841 ms |
137088 KB |
Output is correct |
66 |
Correct |
1678 ms |
137096 KB |
Output is correct |
67 |
Correct |
1464 ms |
137084 KB |
Output is correct |
68 |
Correct |
594 ms |
75472 KB |
Output is correct |
69 |
Correct |
562 ms |
68952 KB |
Output is correct |
70 |
Correct |
754 ms |
91936 KB |
Output is correct |
71 |
Correct |
885 ms |
102520 KB |
Output is correct |