#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
#define pb push_back
#define rsz resize
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
using pi = pair<int,int>;
#define f first
#define s second
#define mp make_pair
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 MX = 2005;
bool used[MX]; fr V[MX][MX]; fr nd[MX], dist[MX], ans[MX]; int ind[MX];
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
int N, L; cin >> N >> L;
for (int i = 1; i <= N; i++) {
V[i][0] = fr(0);
for (int j = 1; j <= L; j++) {
ll x; cin >> x;
V[i][j] = fr(x);
if (j != 0) V[i][j] = V[i][j] + V[i][j - 1];
}
}
nd[0] = fr(0);
for (int i = 1; i <= N; i++) {
ans[i] = fr(L + 1);
for (int j = 1; j <= N; j++) {
if (used[j]) {
continue;
}
// cout << "i, j: " << i << " " << j << '\n';
fr need = V[j][L] * fr(i, N);
// cout << "i, j, need: " << i << " " << j << " " << (ll) need.x << " " << (ll) need.y << '\n';
int it = lower_bound(V[j], V[j] + L, need) - V[j] - 1;
// cout << "i, j, it: " << i << " " << j << " " << it << '\n';
fr to_add = fr(it) + (need - V[j][it] - nd[i - 1]) / (V[j][it + 1] - V[j][it]);
// cout << "i, j, to_add: " << i << " " << j << " " << (ll) to_add.x << " " << (ll) to_add.y << '\n';
if (to_add < ans[i]) {
// cout << "best: " << (ll) to_add.x << " " << (ll)to_add.y << " " << j << " " << '\n';
ans[i] = to_add;
ind[i] = j;
nd[i] = need;
}
}
// cout << "i, ind: " << i << " " << ind[i] << "\n";
if(i < N) cout << (ll) ans[i].x << " " << (ll) ans[i].y << '\n';
used[ind[i]] = true;
}
for (int i = 1; i <= N; i++) {
cout << ind[i] << " ";
}
cout << '\n';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
82 ms |
126332 KB |
Output is correct |
2 |
Correct |
70 ms |
126456 KB |
Output is correct |
3 |
Correct |
80 ms |
126456 KB |
Output is correct |
4 |
Correct |
74 ms |
126456 KB |
Output is correct |
5 |
Correct |
80 ms |
126424 KB |
Output is correct |
6 |
Correct |
72 ms |
126332 KB |
Output is correct |
7 |
Correct |
70 ms |
126456 KB |
Output is correct |
8 |
Incorrect |
69 ms |
126396 KB |
Integer parameter [name=P_i] equals to 0, violates the range [1, 2] |
9 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
79 ms |
126348 KB |
Output is correct |
2 |
Incorrect |
71 ms |
126460 KB |
X_i is not increasing |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
82 ms |
126332 KB |
Output is correct |
2 |
Correct |
70 ms |
126456 KB |
Output is correct |
3 |
Correct |
80 ms |
126456 KB |
Output is correct |
4 |
Correct |
74 ms |
126456 KB |
Output is correct |
5 |
Correct |
80 ms |
126424 KB |
Output is correct |
6 |
Correct |
72 ms |
126332 KB |
Output is correct |
7 |
Correct |
70 ms |
126456 KB |
Output is correct |
8 |
Incorrect |
69 ms |
126396 KB |
Integer parameter [name=P_i] equals to 0, violates the range [1, 2] |
9 |
Halted |
0 ms |
0 KB |
- |