#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 F first
#define S second
#define all(x) x.begin(), x.end()
#define sz(x) ((int)x.size())
#define eb emplace_back
#define int LL
using namespace std;
using LL = long long;
using pii = pair<int, int>;
struct Frac {
__int128_t x, y;
Frac(int _x = 0, int _y = 1) {
x = _x; y = _y;
simp();
}
void simp() {
int g = __gcd(x, y);
x /= g; y /= g;
}
};
Frac operator-(const Frac &a) {
return Frac(-a.x, a.y);
}
Frac operator+(const Frac &a, const Frac &b) {
return Frac(a.x * b.y + a.y * b.x, a.y * b.y);
}
Frac operator-(const Frac &a, const Frac &b) {
return a + (-b);
}
Frac operator*(const Frac &a, const Frac &b) {
return Frac(a.x * b.x, a.y * b.y);
}
Frac operator/(const Frac &a, const Frac &b) {
return Frac(a.x * b.y, a.y * b.x);
}
bool operator==(const Frac &a, const Frac &b) {
return a.x * b.y == a.y * b.x;
}
bool operator<(const Frac &a, const Frac &b) {
return a.x * b.y < a.y * b.x;
}
bool operator>(const Frac &a, const Frac &b) {
return b < a;
}
bool operator<=(const Frac &a, const Frac &b) {
return a < b || a == b;
}
bool operator>=(const Frac &a, const Frac &b) {
return a > b || a == b;
}
ostream& operator<<(ostream& os, const Frac &a) {
os << (LL)a.x << "/" << (LL)a.y;
return os;
}
const int MAXN = 2010;
struct Meow {
int v[MAXN];
Frac tar;
Frac inq[MAXN];
Frac rem[MAXN];
int pos_r, pos_l;
Frac now;
bool used;
void init(int n, int l) {
used = false;
tar = Frac();
For(i, 1, l) {
cin >> v[i];
tar.x += v[i];
rem[i] = Frac(1);
}
tar = tar / n;
pos_r = 1; pos_l = 1;
now = Frac(0);
push(1, Frac(0));
}
void push(int p0, Frac par) {
while(pos_l < p0) {
now = now - inq[pos_l] * v[pos_l];
pos_l++;
}
// cout << rem[pos_r] << " " << tar << " " << now << "\n" << flush;
Frac t = inq[pos_l] + rem[pos_r] + par - 1;
inq[pos_l] = inq[pos_l] - t;
now = now - t * v[pos_l];
while(now + rem[pos_r] * v[pos_r] < tar) {
now = now + rem[pos_r] * v[pos_r];
inq[pos_r] = inq[pos_r] + rem[pos_r];
rem[pos_r] = 0;
pos_r++;
}
t = (tar - now) / v[pos_r];
assert(t <= rem[pos_r]);
rem[pos_r] = rem[pos_r] - t;
inq[pos_r] = inq[pos_r] + t;
now = tar;
}
pair<int, Frac> get_front() {
return make_pair(pos_r, 1 - rem[pos_r]);
}
} meow[MAXN];
int32_t main() {
ios::sync_with_stdio(false);
cin.tie(0);
// nyanyanyanyanya
int n, l; cin >> n >> l;
// assert(n <= 6);
For(i, 1, n) meow[i].init(n, l);
vector<int> ans;
For(i, 1, n - 1) {
pair<int, Frac> front(l + 1, 0);
int min_id = -1;
For(j, 1, n) if(!meow[j].used) {
if(meow[j].get_front() < front) {
front = meow[j].get_front();
min_id = j;
}
// auto p = meow[j].get_front();
// cout << j << " : " << p.F << " - " << p.S << "\n" << flush;
}
ans.eb(min_id);
meow[min_id].used = true;
For(j, 1, n) if(!meow[j].used) {
meow[j].push(front.F, front.S);
}
front.S = front.F - 1 + front.S;
cout << (LL)front.S.x << " " << (LL)front.S.y << "\n";
}
for(auto &i:ans) cout << i << " ";
For(i, 1, n) if(!meow[i].used) cout << i << "\n";
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
100 ms |
261420 KB |
Output is correct |
2 |
Correct |
98 ms |
261532 KB |
Output is correct |
3 |
Correct |
103 ms |
261484 KB |
Output is correct |
4 |
Correct |
104 ms |
261508 KB |
Output is correct |
5 |
Correct |
119 ms |
261484 KB |
Output is correct |
6 |
Correct |
99 ms |
261416 KB |
Output is correct |
7 |
Correct |
103 ms |
261536 KB |
Output is correct |
8 |
Correct |
114 ms |
261532 KB |
Output is correct |
9 |
Correct |
100 ms |
261532 KB |
Output is correct |
10 |
Correct |
104 ms |
261528 KB |
Output is correct |
11 |
Correct |
111 ms |
261568 KB |
Output is correct |
12 |
Correct |
101 ms |
261556 KB |
Output is correct |
13 |
Correct |
105 ms |
261452 KB |
Output is correct |
14 |
Correct |
103 ms |
261476 KB |
Output is correct |
15 |
Correct |
100 ms |
261544 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
101 ms |
261432 KB |
Output is correct |
2 |
Correct |
100 ms |
261584 KB |
Output is correct |
3 |
Correct |
100 ms |
261576 KB |
Output is correct |
4 |
Correct |
104 ms |
261588 KB |
Output is correct |
5 |
Correct |
101 ms |
261540 KB |
Output is correct |
6 |
Correct |
101 ms |
261580 KB |
Output is correct |
7 |
Correct |
103 ms |
261472 KB |
Output is correct |
8 |
Correct |
103 ms |
261452 KB |
Output is correct |
9 |
Correct |
112 ms |
261564 KB |
Output is correct |
10 |
Correct |
107 ms |
261564 KB |
Output is correct |
11 |
Correct |
111 ms |
261472 KB |
Output is correct |
12 |
Correct |
109 ms |
261512 KB |
Output is correct |
13 |
Correct |
105 ms |
261580 KB |
Output is correct |
14 |
Correct |
114 ms |
261560 KB |
Output is correct |
15 |
Correct |
101 ms |
261608 KB |
Output is correct |
16 |
Correct |
104 ms |
261508 KB |
Output is correct |
17 |
Correct |
104 ms |
261580 KB |
Output is correct |
18 |
Correct |
101 ms |
261540 KB |
Output is correct |
19 |
Correct |
107 ms |
261580 KB |
Output is correct |
20 |
Correct |
103 ms |
261560 KB |
Output is correct |
21 |
Correct |
101 ms |
261620 KB |
Output is correct |
22 |
Correct |
104 ms |
261576 KB |
Output is correct |
23 |
Correct |
105 ms |
261520 KB |
Output is correct |
24 |
Correct |
108 ms |
261548 KB |
Output is correct |
25 |
Correct |
99 ms |
261572 KB |
Output is correct |
26 |
Correct |
100 ms |
261556 KB |
Output is correct |
27 |
Correct |
115 ms |
261492 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
100 ms |
261420 KB |
Output is correct |
2 |
Correct |
98 ms |
261532 KB |
Output is correct |
3 |
Correct |
103 ms |
261484 KB |
Output is correct |
4 |
Correct |
104 ms |
261508 KB |
Output is correct |
5 |
Correct |
119 ms |
261484 KB |
Output is correct |
6 |
Correct |
99 ms |
261416 KB |
Output is correct |
7 |
Correct |
103 ms |
261536 KB |
Output is correct |
8 |
Correct |
114 ms |
261532 KB |
Output is correct |
9 |
Correct |
100 ms |
261532 KB |
Output is correct |
10 |
Correct |
104 ms |
261528 KB |
Output is correct |
11 |
Correct |
111 ms |
261568 KB |
Output is correct |
12 |
Correct |
101 ms |
261556 KB |
Output is correct |
13 |
Correct |
105 ms |
261452 KB |
Output is correct |
14 |
Correct |
103 ms |
261476 KB |
Output is correct |
15 |
Correct |
100 ms |
261544 KB |
Output is correct |
16 |
Correct |
101 ms |
261432 KB |
Output is correct |
17 |
Correct |
100 ms |
261584 KB |
Output is correct |
18 |
Correct |
100 ms |
261576 KB |
Output is correct |
19 |
Correct |
104 ms |
261588 KB |
Output is correct |
20 |
Correct |
101 ms |
261540 KB |
Output is correct |
21 |
Correct |
101 ms |
261580 KB |
Output is correct |
22 |
Correct |
103 ms |
261472 KB |
Output is correct |
23 |
Correct |
103 ms |
261452 KB |
Output is correct |
24 |
Correct |
112 ms |
261564 KB |
Output is correct |
25 |
Correct |
107 ms |
261564 KB |
Output is correct |
26 |
Correct |
111 ms |
261472 KB |
Output is correct |
27 |
Correct |
109 ms |
261512 KB |
Output is correct |
28 |
Correct |
105 ms |
261580 KB |
Output is correct |
29 |
Correct |
114 ms |
261560 KB |
Output is correct |
30 |
Correct |
101 ms |
261608 KB |
Output is correct |
31 |
Correct |
104 ms |
261508 KB |
Output is correct |
32 |
Correct |
104 ms |
261580 KB |
Output is correct |
33 |
Correct |
101 ms |
261540 KB |
Output is correct |
34 |
Correct |
107 ms |
261580 KB |
Output is correct |
35 |
Correct |
103 ms |
261560 KB |
Output is correct |
36 |
Correct |
101 ms |
261620 KB |
Output is correct |
37 |
Correct |
104 ms |
261576 KB |
Output is correct |
38 |
Correct |
105 ms |
261520 KB |
Output is correct |
39 |
Correct |
108 ms |
261548 KB |
Output is correct |
40 |
Correct |
99 ms |
261572 KB |
Output is correct |
41 |
Correct |
100 ms |
261556 KB |
Output is correct |
42 |
Correct |
115 ms |
261492 KB |
Output is correct |
43 |
Runtime error |
115 ms |
262144 KB |
Execution killed with signal 9 |
44 |
Halted |
0 ms |
0 KB |
- |