#include <algorithm>
#include <iostream>
#include <numeric>
#include <cassert>
#include <vector>
typedef long long llong;
const int MAXN = 2000 + 10;
const int INF = 1e9;
int n, l;
struct Fraction
{
llong p;
llong q;
Fraction()
{
p = 0;
q = 1;
}
Fraction(llong _p, llong _q = 1)
{
p = _p;
q = _q;
llong g = std::__gcd(p, q);
p /= g; q /= g;
}
friend Fraction operator + (const Fraction &left, const Fraction &right)
{
return {left.p * right.q + right.p * left.q, left.q * right.q};
}
friend Fraction operator - (const Fraction &left, const Fraction &right)
{
return {left.p * right.q - right.p * left.q, left.q * right.q};
}
friend Fraction operator * (const Fraction &left, const Fraction &right)
{
return {left.p * right.p, left.q * right.q};
}
friend Fraction operator / (const Fraction &left, const Fraction &right)
{
return {left.p * right.q, left.q * right.p};
}
friend void operator += (Fraction &left, const Fraction &right)
{
left = left + right;
}
friend void operator -= (Fraction &left, const Fraction &right)
{
left = left - right;
}
friend void operator *= (Fraction &left, const Fraction &right)
{
left = left * right;
}
friend void operator /= (Fraction &left, const Fraction &right)
{
left = left / right;
}
friend bool operator < (const Fraction &left, const Fraction &right)
{
return (left.p * right.q < right.p * left.q);
}
friend bool operator <= (const Fraction &left, const Fraction &right)
{
return (left.p * right.q <= right.p * left.q);
}
void print()
{
std::cout << p << ' ' << q << '\n';
}
};
bool taken[MAXN];
Fraction s[MAXN];
llong v[MAXN][MAXN];
Fraction nextSum[MAXN];
Fraction currentSum[MAXN];
std::vector <Fraction> positions;
std::vector <int> order;
void solve()
{
Fraction takenTo = 0;
for (int pos = 1 ; pos <= l ; ++pos)
{
Fraction minimum = l + 1;
int idx = -1;
for (int i = 1 ; i <= n ; ++i)
{
if (taken[i])
{
continue;
}
nextSum[i] = currentSum[i] + (1 - takenTo) * v[i][pos];
if (s[i] <= nextSum[i])
{
Fraction must = pos - 1 + takenTo + (s[i] - currentSum[i]) / v[i][pos];
if (must < minimum)
{
minimum = must;
idx = i;
}
}
}
if (idx == -1)
{
takenTo = 0;
for (int i = 1 ; i <= n ; ++i)
{
currentSum[i] = nextSum[i];
}
} else
{
taken[idx] = true;
order.push_back(idx);
positions.push_back(minimum);
takenTo = minimum - pos + 1;
std::fill(currentSum + 1, currentSum + n + 1, 0);
pos--;
}
}
positions.pop_back();
}
void print()
{
for (int i = 0 ; i < n - 1 ; ++i)
{
assert(std::__gcd(positions[i].p, positions[i].q) == 1);
positions[i].print();
}
for (int i = 0 ; i < n ; ++i)
{
std::cout << order[i] << ' ';
}
std::cout << '\n';
}
void input()
{
std::cin >> n >> l;
for (int i = 1 ; i <= n ; ++i)
{
for (int j = 1 ; j <= l ; ++j)
{
std::cin >> v[i][j];
s[i] += v[i][j];
}
s[i] /= n;
}
}
void fastIOI()
{
std::ios_base :: sync_with_stdio(0);
std::cout.tie(nullptr);
std::cin.tie(nullptr);
}
int main()
{
fastIOI();
input();
solve();
print();
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
600 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
1 ms |
344 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
344 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
604 KB |
Output is correct |
3 |
Correct |
2 ms |
604 KB |
Output is correct |
4 |
Correct |
1 ms |
604 KB |
Output is correct |
5 |
Correct |
1 ms |
604 KB |
Output is correct |
6 |
Correct |
1 ms |
604 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
604 KB |
Output is correct |
9 |
Correct |
1 ms |
604 KB |
Output is correct |
10 |
Correct |
2 ms |
604 KB |
Output is correct |
11 |
Correct |
1 ms |
604 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
604 KB |
Output is correct |
14 |
Correct |
2 ms |
604 KB |
Output is correct |
15 |
Correct |
1 ms |
604 KB |
Output is correct |
16 |
Correct |
1 ms |
600 KB |
Output is correct |
17 |
Correct |
2 ms |
600 KB |
Output is correct |
18 |
Correct |
1 ms |
604 KB |
Output is correct |
19 |
Correct |
1 ms |
600 KB |
Output is correct |
20 |
Correct |
1 ms |
604 KB |
Output is correct |
21 |
Correct |
2 ms |
604 KB |
Output is correct |
22 |
Correct |
2 ms |
600 KB |
Output is correct |
23 |
Correct |
0 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
604 KB |
Output is correct |
25 |
Correct |
1 ms |
604 KB |
Output is correct |
26 |
Correct |
1 ms |
348 KB |
Output is correct |
27 |
Correct |
1 ms |
600 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
600 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
1 ms |
344 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
344 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
604 KB |
Output is correct |
18 |
Correct |
2 ms |
604 KB |
Output is correct |
19 |
Correct |
1 ms |
604 KB |
Output is correct |
20 |
Correct |
1 ms |
604 KB |
Output is correct |
21 |
Correct |
1 ms |
604 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
604 KB |
Output is correct |
24 |
Correct |
1 ms |
604 KB |
Output is correct |
25 |
Correct |
2 ms |
604 KB |
Output is correct |
26 |
Correct |
1 ms |
604 KB |
Output is correct |
27 |
Correct |
0 ms |
348 KB |
Output is correct |
28 |
Correct |
1 ms |
604 KB |
Output is correct |
29 |
Correct |
2 ms |
604 KB |
Output is correct |
30 |
Correct |
1 ms |
604 KB |
Output is correct |
31 |
Correct |
1 ms |
600 KB |
Output is correct |
32 |
Correct |
2 ms |
600 KB |
Output is correct |
33 |
Correct |
1 ms |
604 KB |
Output is correct |
34 |
Correct |
1 ms |
600 KB |
Output is correct |
35 |
Correct |
1 ms |
604 KB |
Output is correct |
36 |
Correct |
2 ms |
604 KB |
Output is correct |
37 |
Correct |
2 ms |
600 KB |
Output is correct |
38 |
Correct |
0 ms |
348 KB |
Output is correct |
39 |
Correct |
1 ms |
604 KB |
Output is correct |
40 |
Correct |
1 ms |
604 KB |
Output is correct |
41 |
Correct |
1 ms |
348 KB |
Output is correct |
42 |
Correct |
1 ms |
600 KB |
Output is correct |
43 |
Incorrect |
154 ms |
11112 KB |
Integer parameter [name=A_i] equals to 2109834534371, violates the range [1, 2000000000000] |
44 |
Halted |
0 ms |
0 KB |
- |