/* nya */
#pragma GCC optimize("O4,unroll-loops,no-stack-protector")
#pragma GCC target("avx,avx2,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,fma")
#include <bits/stdc++.h>
#define For(i, a, b) for (int i = a; i <= b; i++)
#define Forr(i, a, b) for (int i = a; i >= b; i--)
#define Fors(i, a, b, s) for (int i = a; i <= b; i += s)
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define sz(x) ((int)x.size())
#define eb emplace_back
#define int LLL
#define INF (int)(1e18)
#define MOD (int)(1000000007)
// #define MOD (int)(998244353)
using namespace std;
using LL = long long;
using LLL = __int128_t;
using pii = pair<int, int>;
#ifdef NYAOWO
#include "library/debug.hpp"
inline void USACO(const string &s) {
cerr << "USACO: " << s << "\n";
}
#else
#define debug(...)
inline void timer() {}
inline void USACO(const string &s) {
freopen((s + ".in").c_str(), "r", stdin);
freopen((s + ".out").c_str(), "w", stdout);
}
#endif
bool smol(const pii &a, const pii &b) {
return a.F * b.S < a.S * b.F;
}
pii owo(int a, int b) {
int g = __gcd(a, b);
return pii(a / g, b / g);
}
const int MAXN = 2010;
LL v0[MAXN];
LL v[MAXN];
pii dv[MAXN][MAXN];
int vis[MAXN];
int32_t main() {
ios::sync_with_stdio(false);
cin.tie(0);
// OAO
LL n, l; cin >> n >> l;
For(i, 1, n) {
int su = 0;
For(j, 1, l) {
cin >> v[j];
su += v[j];
v[j] *= n;
v0[j] = v[j];
}
v[l + 1] = v0[l + 1] = 1;
int ptr = 1;
For(j, 1, n) {
LL now = su;
while(now > 0) {
int x = min(now, v[ptr]);
v[ptr] -= x;
now -= x;
if(v[ptr] == 0) ptr++;
}
dv[i][j] = owo(v0[ptr] - v[ptr] + v0[ptr] * (ptr - 1), v0[ptr]);
}
}
vector<LL> res;
For(rnd, 1, n) {
pii mn(1e18, 1);
int idx = -1;
For(i, 1, n) if(!vis[i]) {
if(smol(dv[i][rnd], mn)) {
mn = dv[i][rnd];
idx = i;
}
}
mn = owo(mn.F, mn.S);
if(rnd < n) cout << (LL)mn.F << " " << (LL)mn.S << "\n";
res.eb(idx);
vis[idx] = 1;
}
For(i, 0, n - 1) cout << res[i] << " \n"[i == n - 1];
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
0 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
376 KB |
Output is correct |
23 |
Correct |
0 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
0 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
0 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
340 KB |
Output is correct |
29 |
Correct |
1 ms |
340 KB |
Output is correct |
30 |
Correct |
1 ms |
340 KB |
Output is correct |
31 |
Correct |
1 ms |
340 KB |
Output is correct |
32 |
Correct |
1 ms |
340 KB |
Output is correct |
33 |
Correct |
1 ms |
340 KB |
Output is correct |
34 |
Correct |
1 ms |
340 KB |
Output is correct |
35 |
Correct |
1 ms |
340 KB |
Output is correct |
36 |
Correct |
1 ms |
340 KB |
Output is correct |
37 |
Correct |
1 ms |
376 KB |
Output is correct |
38 |
Correct |
0 ms |
340 KB |
Output is correct |
39 |
Correct |
1 ms |
340 KB |
Output is correct |
40 |
Correct |
1 ms |
340 KB |
Output is correct |
41 |
Correct |
1 ms |
340 KB |
Output is correct |
42 |
Correct |
1 ms |
340 KB |
Output is correct |
43 |
Correct |
58 ms |
12620 KB |
Output is correct |
44 |
Correct |
359 ms |
64324 KB |
Output is correct |
45 |
Correct |
147 ms |
25472 KB |
Output is correct |
46 |
Correct |
19 ms |
2300 KB |
Output is correct |
47 |
Correct |
231 ms |
42616 KB |
Output is correct |
48 |
Correct |
504 ms |
119516 KB |
Output is correct |
49 |
Correct |
115 ms |
28268 KB |
Output is correct |
50 |
Correct |
608 ms |
129940 KB |
Output is correct |
51 |
Correct |
232 ms |
42208 KB |
Output is correct |
52 |
Correct |
544 ms |
106072 KB |
Output is correct |
53 |
Correct |
487 ms |
100680 KB |
Output is correct |
54 |
Correct |
1 ms |
340 KB |
Output is correct |
55 |
Correct |
246 ms |
67992 KB |
Output is correct |
56 |
Correct |
308 ms |
62308 KB |
Output is correct |
57 |
Correct |
272 ms |
53944 KB |
Output is correct |
58 |
Correct |
432 ms |
101724 KB |
Output is correct |
59 |
Correct |
251 ms |
47896 KB |
Output is correct |
60 |
Correct |
676 ms |
145936 KB |
Output is correct |
61 |
Correct |
699 ms |
146888 KB |
Output is correct |
62 |
Correct |
767 ms |
142724 KB |
Output is correct |
63 |
Correct |
734 ms |
142300 KB |
Output is correct |
64 |
Correct |
747 ms |
142416 KB |
Output is correct |
65 |
Correct |
690 ms |
134876 KB |
Output is correct |
66 |
Correct |
691 ms |
134956 KB |
Output is correct |
67 |
Correct |
649 ms |
134900 KB |
Output is correct |
68 |
Correct |
271 ms |
71628 KB |
Output is correct |
69 |
Correct |
296 ms |
61160 KB |
Output is correct |
70 |
Correct |
347 ms |
90604 KB |
Output is correct |
71 |
Correct |
440 ms |
96772 KB |
Output is correct |