#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
#define endl '\n'
#define ll long long
#define pi pair<ll, ll>
#define f first
#define s second
struct fr{
__int128 x, y;
fr(__int128 X = 0, __int128 Y = 1){
x = X, y = Y;
ll g = __gcd(x, y);
x /= g, y /= g;
}
friend fr operator+(fr a, fr b){
return fr(a.x * b.y + b.x * a.y, a.y * b.y);
}
friend fr operator-(fr a, fr b){
return fr(a.x * b.y - b.x * a.y, a.y * b.y);
}
friend fr operator*(fr a, fr b){
return fr(a.x * b.x, a.y * b.y);
}
friend fr operator/(fr a, fr b){
return fr(a.x * b.y, a.y * b.x);
}
friend bool operator<(fr a, fr b){
return a.x * b.y < b.x * a.y;
}
};
const int mxn = 2001;
int n, m;
fr a[mxn][mxn];
bool vis[mxn];
int vi[mxn];
fr vf[mxn];
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n >> m;
for(int i = 1; i <= n; i++)
for(int j = 1; j <= m; j++){
ll x;
cin >> x;
a[i][j] = fr(x) + a[i][j - 1];
}
for(int i = 1; i <= n; i++){
vf[i] = fr(m + 1);
for(int j = 1; j <= n; j++){
if(vis[j]) continue;
fr x = a[j][m] * fr(i, n);
int it = lower_bound(a[j], a[j] + m, x) - a[j] - 1;
fr y = fr(it) + (x - a[j][it]) / (a[j][it + 1] - a[j][it]);
if(y < vf[i]) vi[i] = j, vf[i] = y;
}
vis[vi[i]] = 1;
if(i < n) cout << (ll)vf[i].x << " " << (ll)vf[i].y << endl;
}
cout << vi[1];
for(int i = 2; i <= n; i++) cout << " " << vi[i];
cout << endl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
64 ms |
125688 KB |
Output is correct |
2 |
Correct |
63 ms |
125820 KB |
Output is correct |
3 |
Correct |
58 ms |
125816 KB |
Output is correct |
4 |
Correct |
61 ms |
125748 KB |
Output is correct |
5 |
Correct |
60 ms |
125704 KB |
Output is correct |
6 |
Correct |
66 ms |
125816 KB |
Output is correct |
7 |
Correct |
61 ms |
125944 KB |
Output is correct |
8 |
Correct |
66 ms |
125816 KB |
Output is correct |
9 |
Correct |
76 ms |
125688 KB |
Output is correct |
10 |
Correct |
63 ms |
125816 KB |
Output is correct |
11 |
Correct |
58 ms |
125816 KB |
Output is correct |
12 |
Correct |
68 ms |
125816 KB |
Output is correct |
13 |
Correct |
59 ms |
125816 KB |
Output is correct |
14 |
Correct |
58 ms |
125816 KB |
Output is correct |
15 |
Correct |
59 ms |
125760 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
56 ms |
125788 KB |
Output is correct |
2 |
Correct |
58 ms |
125816 KB |
Output is correct |
3 |
Correct |
62 ms |
125712 KB |
Output is correct |
4 |
Correct |
65 ms |
125816 KB |
Output is correct |
5 |
Correct |
63 ms |
125816 KB |
Output is correct |
6 |
Correct |
58 ms |
125816 KB |
Output is correct |
7 |
Correct |
59 ms |
125816 KB |
Output is correct |
8 |
Correct |
58 ms |
125816 KB |
Output is correct |
9 |
Correct |
58 ms |
125724 KB |
Output is correct |
10 |
Correct |
57 ms |
125816 KB |
Output is correct |
11 |
Correct |
59 ms |
125816 KB |
Output is correct |
12 |
Correct |
57 ms |
125816 KB |
Output is correct |
13 |
Correct |
58 ms |
125816 KB |
Output is correct |
14 |
Correct |
57 ms |
125816 KB |
Output is correct |
15 |
Correct |
58 ms |
125816 KB |
Output is correct |
16 |
Correct |
58 ms |
125816 KB |
Output is correct |
17 |
Correct |
58 ms |
125816 KB |
Output is correct |
18 |
Correct |
65 ms |
125816 KB |
Output is correct |
19 |
Correct |
59 ms |
125816 KB |
Output is correct |
20 |
Correct |
61 ms |
125816 KB |
Output is correct |
21 |
Correct |
59 ms |
125816 KB |
Output is correct |
22 |
Correct |
71 ms |
125816 KB |
Output is correct |
23 |
Correct |
62 ms |
125688 KB |
Output is correct |
24 |
Correct |
58 ms |
125816 KB |
Output is correct |
25 |
Correct |
57 ms |
125816 KB |
Output is correct |
26 |
Correct |
63 ms |
125816 KB |
Output is correct |
27 |
Correct |
57 ms |
125816 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
64 ms |
125688 KB |
Output is correct |
2 |
Correct |
63 ms |
125820 KB |
Output is correct |
3 |
Correct |
58 ms |
125816 KB |
Output is correct |
4 |
Correct |
61 ms |
125748 KB |
Output is correct |
5 |
Correct |
60 ms |
125704 KB |
Output is correct |
6 |
Correct |
66 ms |
125816 KB |
Output is correct |
7 |
Correct |
61 ms |
125944 KB |
Output is correct |
8 |
Correct |
66 ms |
125816 KB |
Output is correct |
9 |
Correct |
76 ms |
125688 KB |
Output is correct |
10 |
Correct |
63 ms |
125816 KB |
Output is correct |
11 |
Correct |
58 ms |
125816 KB |
Output is correct |
12 |
Correct |
68 ms |
125816 KB |
Output is correct |
13 |
Correct |
59 ms |
125816 KB |
Output is correct |
14 |
Correct |
58 ms |
125816 KB |
Output is correct |
15 |
Correct |
59 ms |
125760 KB |
Output is correct |
16 |
Correct |
56 ms |
125788 KB |
Output is correct |
17 |
Correct |
58 ms |
125816 KB |
Output is correct |
18 |
Correct |
62 ms |
125712 KB |
Output is correct |
19 |
Correct |
65 ms |
125816 KB |
Output is correct |
20 |
Correct |
63 ms |
125816 KB |
Output is correct |
21 |
Correct |
58 ms |
125816 KB |
Output is correct |
22 |
Correct |
59 ms |
125816 KB |
Output is correct |
23 |
Correct |
58 ms |
125816 KB |
Output is correct |
24 |
Correct |
58 ms |
125724 KB |
Output is correct |
25 |
Correct |
57 ms |
125816 KB |
Output is correct |
26 |
Correct |
59 ms |
125816 KB |
Output is correct |
27 |
Correct |
57 ms |
125816 KB |
Output is correct |
28 |
Correct |
58 ms |
125816 KB |
Output is correct |
29 |
Correct |
57 ms |
125816 KB |
Output is correct |
30 |
Correct |
58 ms |
125816 KB |
Output is correct |
31 |
Correct |
58 ms |
125816 KB |
Output is correct |
32 |
Correct |
58 ms |
125816 KB |
Output is correct |
33 |
Correct |
65 ms |
125816 KB |
Output is correct |
34 |
Correct |
59 ms |
125816 KB |
Output is correct |
35 |
Correct |
61 ms |
125816 KB |
Output is correct |
36 |
Correct |
59 ms |
125816 KB |
Output is correct |
37 |
Correct |
71 ms |
125816 KB |
Output is correct |
38 |
Correct |
62 ms |
125688 KB |
Output is correct |
39 |
Correct |
58 ms |
125816 KB |
Output is correct |
40 |
Correct |
57 ms |
125816 KB |
Output is correct |
41 |
Correct |
63 ms |
125816 KB |
Output is correct |
42 |
Correct |
57 ms |
125816 KB |
Output is correct |
43 |
Correct |
186 ms |
125816 KB |
Output is correct |
44 |
Correct |
870 ms |
126072 KB |
Output is correct |
45 |
Correct |
348 ms |
133248 KB |
Output is correct |
46 |
Correct |
92 ms |
126968 KB |
Output is correct |
47 |
Correct |
533 ms |
133924 KB |
Output is correct |
48 |
Correct |
1261 ms |
127736 KB |
Output is correct |
49 |
Correct |
314 ms |
126968 KB |
Output is correct |
50 |
Correct |
1534 ms |
131576 KB |
Output is correct |
51 |
Correct |
551 ms |
129784 KB |
Output is correct |
52 |
Correct |
1280 ms |
132952 KB |
Output is correct |
53 |
Correct |
1168 ms |
130936 KB |
Output is correct |
54 |
Correct |
60 ms |
125816 KB |
Output is correct |
55 |
Correct |
554 ms |
126200 KB |
Output is correct |
56 |
Correct |
748 ms |
130296 KB |
Output is correct |
57 |
Correct |
604 ms |
129408 KB |
Output is correct |
58 |
Correct |
1031 ms |
129660 KB |
Output is correct |
59 |
Correct |
592 ms |
129912 KB |
Output is correct |
60 |
Correct |
1479 ms |
147968 KB |
Output is correct |
61 |
Correct |
1548 ms |
147836 KB |
Output is correct |
62 |
Correct |
1717 ms |
147960 KB |
Output is correct |
63 |
Correct |
1631 ms |
148256 KB |
Output is correct |
64 |
Correct |
1527 ms |
147960 KB |
Output is correct |
65 |
Correct |
1598 ms |
134776 KB |
Output is correct |
66 |
Correct |
1532 ms |
134636 KB |
Output is correct |
67 |
Correct |
1440 ms |
134632 KB |
Output is correct |
68 |
Correct |
684 ms |
131836 KB |
Output is correct |
69 |
Correct |
637 ms |
133624 KB |
Output is correct |
70 |
Correct |
854 ms |
132352 KB |
Output is correct |
71 |
Correct |
1008 ms |
137124 KB |
Output is correct |