#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{
ll x, y;
fr(ll X = 0, ll 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++){
cin >> a[i][j].x;
a[i][j] = a[i][j] + 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 << vf[i].x << " " << 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 |
34 ms |
63096 KB |
Output is correct |
2 |
Correct |
35 ms |
63096 KB |
Output is correct |
3 |
Correct |
32 ms |
63096 KB |
Output is correct |
4 |
Correct |
33 ms |
63096 KB |
Output is correct |
5 |
Correct |
34 ms |
63096 KB |
Output is correct |
6 |
Correct |
32 ms |
63104 KB |
Output is correct |
7 |
Correct |
30 ms |
63096 KB |
Output is correct |
8 |
Correct |
30 ms |
63104 KB |
Output is correct |
9 |
Correct |
47 ms |
63096 KB |
Output is correct |
10 |
Correct |
30 ms |
63104 KB |
Output is correct |
11 |
Correct |
34 ms |
63104 KB |
Output is correct |
12 |
Correct |
37 ms |
63096 KB |
Output is correct |
13 |
Correct |
31 ms |
63096 KB |
Output is correct |
14 |
Correct |
30 ms |
63104 KB |
Output is correct |
15 |
Correct |
31 ms |
63096 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
37 ms |
63096 KB |
Output is correct |
2 |
Correct |
45 ms |
63096 KB |
Output is correct |
3 |
Correct |
34 ms |
63096 KB |
Output is correct |
4 |
Correct |
30 ms |
63104 KB |
Output is correct |
5 |
Correct |
31 ms |
63096 KB |
Output is correct |
6 |
Correct |
31 ms |
63104 KB |
Output is correct |
7 |
Correct |
34 ms |
63100 KB |
Output is correct |
8 |
Correct |
30 ms |
63104 KB |
Output is correct |
9 |
Correct |
29 ms |
63104 KB |
Output is correct |
10 |
Correct |
30 ms |
63096 KB |
Output is correct |
11 |
Correct |
33 ms |
63096 KB |
Output is correct |
12 |
Correct |
30 ms |
63104 KB |
Output is correct |
13 |
Correct |
33 ms |
63104 KB |
Output is correct |
14 |
Correct |
31 ms |
63104 KB |
Output is correct |
15 |
Correct |
30 ms |
63096 KB |
Output is correct |
16 |
Correct |
36 ms |
63104 KB |
Output is correct |
17 |
Correct |
41 ms |
63096 KB |
Output is correct |
18 |
Correct |
32 ms |
63096 KB |
Output is correct |
19 |
Correct |
50 ms |
63100 KB |
Output is correct |
20 |
Correct |
44 ms |
63096 KB |
Output is correct |
21 |
Correct |
30 ms |
63104 KB |
Output is correct |
22 |
Correct |
38 ms |
63104 KB |
Output is correct |
23 |
Correct |
30 ms |
63104 KB |
Output is correct |
24 |
Correct |
31 ms |
63104 KB |
Output is correct |
25 |
Correct |
31 ms |
63104 KB |
Output is correct |
26 |
Correct |
31 ms |
63096 KB |
Output is correct |
27 |
Correct |
30 ms |
63104 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
34 ms |
63096 KB |
Output is correct |
2 |
Correct |
35 ms |
63096 KB |
Output is correct |
3 |
Correct |
32 ms |
63096 KB |
Output is correct |
4 |
Correct |
33 ms |
63096 KB |
Output is correct |
5 |
Correct |
34 ms |
63096 KB |
Output is correct |
6 |
Correct |
32 ms |
63104 KB |
Output is correct |
7 |
Correct |
30 ms |
63096 KB |
Output is correct |
8 |
Correct |
30 ms |
63104 KB |
Output is correct |
9 |
Correct |
47 ms |
63096 KB |
Output is correct |
10 |
Correct |
30 ms |
63104 KB |
Output is correct |
11 |
Correct |
34 ms |
63104 KB |
Output is correct |
12 |
Correct |
37 ms |
63096 KB |
Output is correct |
13 |
Correct |
31 ms |
63096 KB |
Output is correct |
14 |
Correct |
30 ms |
63104 KB |
Output is correct |
15 |
Correct |
31 ms |
63096 KB |
Output is correct |
16 |
Correct |
37 ms |
63096 KB |
Output is correct |
17 |
Correct |
45 ms |
63096 KB |
Output is correct |
18 |
Correct |
34 ms |
63096 KB |
Output is correct |
19 |
Correct |
30 ms |
63104 KB |
Output is correct |
20 |
Correct |
31 ms |
63096 KB |
Output is correct |
21 |
Correct |
31 ms |
63104 KB |
Output is correct |
22 |
Correct |
34 ms |
63100 KB |
Output is correct |
23 |
Correct |
30 ms |
63104 KB |
Output is correct |
24 |
Correct |
29 ms |
63104 KB |
Output is correct |
25 |
Correct |
30 ms |
63096 KB |
Output is correct |
26 |
Correct |
33 ms |
63096 KB |
Output is correct |
27 |
Correct |
30 ms |
63104 KB |
Output is correct |
28 |
Correct |
33 ms |
63104 KB |
Output is correct |
29 |
Correct |
31 ms |
63104 KB |
Output is correct |
30 |
Correct |
30 ms |
63096 KB |
Output is correct |
31 |
Correct |
36 ms |
63104 KB |
Output is correct |
32 |
Correct |
41 ms |
63096 KB |
Output is correct |
33 |
Correct |
32 ms |
63096 KB |
Output is correct |
34 |
Correct |
50 ms |
63100 KB |
Output is correct |
35 |
Correct |
44 ms |
63096 KB |
Output is correct |
36 |
Correct |
30 ms |
63104 KB |
Output is correct |
37 |
Correct |
38 ms |
63104 KB |
Output is correct |
38 |
Correct |
30 ms |
63104 KB |
Output is correct |
39 |
Correct |
31 ms |
63104 KB |
Output is correct |
40 |
Correct |
31 ms |
63104 KB |
Output is correct |
41 |
Correct |
31 ms |
63096 KB |
Output is correct |
42 |
Correct |
30 ms |
63104 KB |
Output is correct |
43 |
Correct |
136 ms |
63096 KB |
Output is correct |
44 |
Incorrect |
673 ms |
63100 KB |
X_i is not increasing |
45 |
Halted |
0 ms |
0 KB |
- |