#include "bits/stdc++.h"
using namespace std;
#define fi first
#define se second
#define ll long long
#define dbg(v) cerr<<#v<<" = "<<v<<'\n'
#define vi vector<int>
#define vl vector <ll>
#define pii pair<int,int>
#define vii vector < pii >
#define mp make_pair
#define db long double
#define pb push_back
#define all(s) s.begin(),s.end()
template < class P , class Q > ostream& operator<<(ostream& stream, pair < P , Q > v){ stream << "(" << v.fi << ',' << v.se << ")"; return stream;}
template < class T > ostream& operator<<(ostream& stream, const vector<T> v){ stream << "[ "; for (int i=0; i<(int)v.size(); i++) stream << v[i] << " "; stream << "]"; return stream;}
template < class T > T smin(T &a,T b) {if (a > b) a = b;return a;}
template < class T > T smax(T &a,T b) {if (a < b) a = b;return a;}
int s[2048][2048];
ll cnt[2048];
ll sum[2048];
ll gcd(ll a,ll b) {
return !b ? a : gcd(b, a % b);
}
void Rel(ll &a,ll &b) {
ll g = gcd(a,b);
a /= g;
b /= g;
}
int main(void) {
int n,m;
cin>>n>>m;
for (int i = 1;i <= n;++i)
for (int j = 1;j <= m;++j)
cin>>s[i][j];
for (int i = 1;i <= n;++i)
for (int j = 1;j <= m;++j)
sum[i] += s[i][j];
vi p(n);
for (int i = 0;i < n;++i)
p[i] = i + 1;
vi Order;
vector < pair < ll , ll > > Frac;
for (int i = 1;i <= m;++i) {
ll A = n,B = 1;
while (!p.empty() && A > 0) {
sort(all(p),[&](int x,int y) {
const ll curx = (sum[x] - cnt[x]);
const ll cury = (sum[y] - cnt[y]);
return curx * s[y][i] > cury * s[x][i];
});
int Index = p.back();
ll C = (sum[Index] - cnt[Index]);
ll D = s[Index][i];
if (C * B > A * D) {
break;
}
p.pop_back();
Order.pb(Index);
ll New_A = (A * D - B * C) / B;
ll New_B = D;
A = New_A;
B = New_B;
Frac.pb(mp(i * B * n - A,B * n));
for (int j = 1;j <= n;++j)
cnt[j] = 0;
}
for (int j = 1;j <= n;++j)
cnt[j] += A * s[j][i] / B;
}
Frac.pop_back();
for (auto & it : Frac)
Rel(it.fi,it.se);
for (auto it : Frac)
cout << it.fi << ' ' << it.se << '\n';
for (int i = 0;i < n;++i)
cout << Order[i] << " \n"[i == n - 1];
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
3 ms |
384 KB |
Output is correct |
4 |
Correct |
3 ms |
384 KB |
Output is correct |
5 |
Correct |
3 ms |
256 KB |
Output is correct |
6 |
Correct |
2 ms |
384 KB |
Output is correct |
7 |
Correct |
3 ms |
384 KB |
Output is correct |
8 |
Correct |
3 ms |
384 KB |
Output is correct |
9 |
Correct |
2 ms |
384 KB |
Output is correct |
10 |
Correct |
3 ms |
384 KB |
Output is correct |
11 |
Correct |
3 ms |
384 KB |
Output is correct |
12 |
Correct |
3 ms |
384 KB |
Output is correct |
13 |
Correct |
3 ms |
384 KB |
Output is correct |
14 |
Correct |
3 ms |
384 KB |
Output is correct |
15 |
Correct |
4 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
384 KB |
Output is correct |
2 |
Correct |
3 ms |
384 KB |
Output is correct |
3 |
Correct |
3 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
4 ms |
384 KB |
Output is correct |
6 |
Correct |
3 ms |
384 KB |
Output is correct |
7 |
Correct |
3 ms |
384 KB |
Output is correct |
8 |
Correct |
2 ms |
384 KB |
Output is correct |
9 |
Correct |
3 ms |
380 KB |
Output is correct |
10 |
Correct |
4 ms |
380 KB |
Output is correct |
11 |
Correct |
3 ms |
384 KB |
Output is correct |
12 |
Correct |
3 ms |
384 KB |
Output is correct |
13 |
Correct |
3 ms |
384 KB |
Output is correct |
14 |
Correct |
4 ms |
384 KB |
Output is correct |
15 |
Correct |
4 ms |
384 KB |
Output is correct |
16 |
Correct |
4 ms |
384 KB |
Output is correct |
17 |
Correct |
4 ms |
384 KB |
Output is correct |
18 |
Correct |
3 ms |
384 KB |
Output is correct |
19 |
Correct |
4 ms |
384 KB |
Output is correct |
20 |
Correct |
4 ms |
384 KB |
Output is correct |
21 |
Correct |
5 ms |
384 KB |
Output is correct |
22 |
Correct |
2 ms |
384 KB |
Output is correct |
23 |
Correct |
2 ms |
384 KB |
Output is correct |
24 |
Correct |
5 ms |
384 KB |
Output is correct |
25 |
Correct |
3 ms |
384 KB |
Output is correct |
26 |
Correct |
2 ms |
384 KB |
Output is correct |
27 |
Correct |
4 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
3 ms |
384 KB |
Output is correct |
4 |
Correct |
3 ms |
384 KB |
Output is correct |
5 |
Correct |
3 ms |
256 KB |
Output is correct |
6 |
Correct |
2 ms |
384 KB |
Output is correct |
7 |
Correct |
3 ms |
384 KB |
Output is correct |
8 |
Correct |
3 ms |
384 KB |
Output is correct |
9 |
Correct |
2 ms |
384 KB |
Output is correct |
10 |
Correct |
3 ms |
384 KB |
Output is correct |
11 |
Correct |
3 ms |
384 KB |
Output is correct |
12 |
Correct |
3 ms |
384 KB |
Output is correct |
13 |
Correct |
3 ms |
384 KB |
Output is correct |
14 |
Correct |
3 ms |
384 KB |
Output is correct |
15 |
Correct |
4 ms |
384 KB |
Output is correct |
16 |
Correct |
3 ms |
384 KB |
Output is correct |
17 |
Correct |
3 ms |
384 KB |
Output is correct |
18 |
Correct |
3 ms |
384 KB |
Output is correct |
19 |
Correct |
1 ms |
384 KB |
Output is correct |
20 |
Correct |
4 ms |
384 KB |
Output is correct |
21 |
Correct |
3 ms |
384 KB |
Output is correct |
22 |
Correct |
3 ms |
384 KB |
Output is correct |
23 |
Correct |
2 ms |
384 KB |
Output is correct |
24 |
Correct |
3 ms |
380 KB |
Output is correct |
25 |
Correct |
4 ms |
380 KB |
Output is correct |
26 |
Correct |
3 ms |
384 KB |
Output is correct |
27 |
Correct |
3 ms |
384 KB |
Output is correct |
28 |
Correct |
3 ms |
384 KB |
Output is correct |
29 |
Correct |
4 ms |
384 KB |
Output is correct |
30 |
Correct |
4 ms |
384 KB |
Output is correct |
31 |
Correct |
4 ms |
384 KB |
Output is correct |
32 |
Correct |
4 ms |
384 KB |
Output is correct |
33 |
Correct |
3 ms |
384 KB |
Output is correct |
34 |
Correct |
4 ms |
384 KB |
Output is correct |
35 |
Correct |
4 ms |
384 KB |
Output is correct |
36 |
Correct |
5 ms |
384 KB |
Output is correct |
37 |
Correct |
2 ms |
384 KB |
Output is correct |
38 |
Correct |
2 ms |
384 KB |
Output is correct |
39 |
Correct |
5 ms |
384 KB |
Output is correct |
40 |
Correct |
3 ms |
384 KB |
Output is correct |
41 |
Correct |
2 ms |
384 KB |
Output is correct |
42 |
Correct |
4 ms |
384 KB |
Output is correct |
43 |
Correct |
93 ms |
6316 KB |
Output is correct |
44 |
Correct |
621 ms |
20796 KB |
Output is correct |
45 |
Correct |
430 ms |
13364 KB |
Output is correct |
46 |
Correct |
66 ms |
2424 KB |
Output is correct |
47 |
Correct |
487 ms |
16504 KB |
Output is correct |
48 |
Correct |
238 ms |
17404 KB |
Output is correct |
49 |
Correct |
115 ms |
8568 KB |
Output is correct |
50 |
Correct |
559 ms |
21764 KB |
Output is correct |
51 |
Correct |
341 ms |
12616 KB |
Output is correct |
52 |
Correct |
644 ms |
21356 KB |
Output is correct |
53 |
Correct |
468 ms |
19008 KB |
Output is correct |
54 |
Correct |
4 ms |
384 KB |
Output is correct |
55 |
Correct |
80 ms |
6392 KB |
Output is correct |
56 |
Correct |
442 ms |
15096 KB |
Output is correct |
57 |
Correct |
431 ms |
13432 KB |
Output is correct |
58 |
Correct |
566 ms |
18028 KB |
Output is correct |
59 |
Correct |
547 ms |
13616 KB |
Output is correct |
60 |
Correct |
1379 ms |
16760 KB |
Output is correct |
61 |
Correct |
1368 ms |
16628 KB |
Output is correct |
62 |
Correct |
1475 ms |
16632 KB |
Output is correct |
63 |
Correct |
1409 ms |
16544 KB |
Output is correct |
64 |
Correct |
1355 ms |
16760 KB |
Output is correct |
65 |
Correct |
872 ms |
25204 KB |
Output is correct |
66 |
Correct |
898 ms |
25208 KB |
Output is correct |
67 |
Correct |
979 ms |
25140 KB |
Output is correct |
68 |
Correct |
428 ms |
17500 KB |
Output is correct |
69 |
Correct |
550 ms |
18172 KB |
Output is correct |
70 |
Correct |
464 ms |
19476 KB |
Output is correct |
71 |
Correct |
791 ms |
22376 KB |
Output is correct |