# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
470983 |
2021-09-06T14:38:43 Z |
Namnamseo |
Naan (JOI19_naan) |
C++17 |
|
185 ms |
8940 KB |
#include <algorithm>
#include <iostream>
#include <numeric>
using namespace std;
using ll=long long;
const int maxn = int(2e3) + 10;
int n, l;
ll v[maxn][maxn];
ll vs[maxn][maxn];
ll gcd(ll a, ll b) { while (b) a %= b, swap(a, b); return a; }
struct frac {
ll m, j;
frac(ll j_=0, ll m_=1) : m(m_), j(j_) {
if (m < 0) m=-m, j=-j;
ll g = gcd(m, abs(j));
m /= g; j /= g;
}
explicit operator int() { return j/m; }
explicit operator ll() { return j/m; }
bool operator<(frac r) const { return j*r.m < m*r.j; }
bool operator>(frac r) const { return j*r.m > m*r.j; }
bool operator<=(frac r) const { return j*r.m <= m*r.j; }
bool operator>=(frac r) const { return j*r.m >= m*r.j; }
frac operator+(frac r) { return frac(j*r.m + m*r.j, m*r.m); }
frac operator-(frac r) { return frac(j*r.m - m*r.j, m*r.m); }
frac operator*(frac r) { return frac(j*r.j, m*r.m); }
frac operator/(frac r) { return frac(j*r.m, m*r.j); }
frac ceil_to(ll nm) { return frac((j*nm+m-1)/m, nm); }
};
int ansp[maxn];
bool done[maxn];
frac byn(int i, frac s) {
frac tgt(vs[i][l], n);
int sj = int(s)+1;
frac lwidth = frac(sj) - s;
frac lweight = frac(v[i][sj]) * lwidth;
if (lweight >= tgt) {
return (s.ceil_to(n * v[i][sj]) + tgt / frac(v[i][sj]));
}
tgt = tgt - lweight; s = frac(sj);
ll isang = vs[i][sj] + ll(tgt);
int nj = upper_bound(vs[i]+1, vs[i]+l+1, isang) - vs[i] - 1;
tgt = tgt - (vs[i][nj] - vs[i][sj]); s = nj;
return s + (tgt / frac(v[i][nj+1])).ceil_to(n*v[i][nj+1]);
}
int main() { cin.tie(0)->sync_with_stdio(0);
cin >> n >> l;
for (int i=1; i<=n; ++i) for (int j=1; j<=l; ++j) cin >> v[i][j];
for (int i=1; i<=n; ++i) partial_sum(v[i]+1, v[i]+l+1, vs[i]+1);
frac cx{};
for (int pi=1; pi<=n; ++pi) {
frac mx; int mxi = -1;
for (int i=1; i<=n; ++i) if (!done[i]) {
frac tx = byn(i, cx);
if (mxi == -1 || tx < mx) mx = tx, mxi = i;
}
cx = mx;
if (pi < n) cout << mx.j << ' ' << mx.m << '\n';
ansp[pi] = mxi;
done[mxi] = true;
}
for (int i=1; i<=n; ++i) cout << ansp[i] << " \n"[i == n];
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
460 KB |
Output is correct |
4 |
Correct |
1 ms |
460 KB |
Output is correct |
5 |
Correct |
2 ms |
460 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
460 KB |
Output is correct |
10 |
Correct |
2 ms |
460 KB |
Output is correct |
11 |
Correct |
1 ms |
460 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
460 KB |
Output is correct |
15 |
Correct |
1 ms |
460 KB |
Output is correct |
16 |
Correct |
2 ms |
460 KB |
Output is correct |
17 |
Correct |
2 ms |
460 KB |
Output is correct |
18 |
Correct |
1 ms |
460 KB |
Output is correct |
19 |
Correct |
2 ms |
460 KB |
Output is correct |
20 |
Correct |
1 ms |
460 KB |
Output is correct |
21 |
Correct |
1 ms |
460 KB |
Output is correct |
22 |
Correct |
1 ms |
460 KB |
Output is correct |
23 |
Correct |
1 ms |
332 KB |
Output is correct |
24 |
Correct |
1 ms |
460 KB |
Output is correct |
25 |
Correct |
1 ms |
332 KB |
Output is correct |
26 |
Correct |
1 ms |
332 KB |
Output is correct |
27 |
Correct |
1 ms |
460 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
460 KB |
Output is correct |
19 |
Correct |
1 ms |
460 KB |
Output is correct |
20 |
Correct |
2 ms |
460 KB |
Output is correct |
21 |
Correct |
1 ms |
332 KB |
Output is correct |
22 |
Correct |
1 ms |
332 KB |
Output is correct |
23 |
Correct |
1 ms |
332 KB |
Output is correct |
24 |
Correct |
1 ms |
460 KB |
Output is correct |
25 |
Correct |
2 ms |
460 KB |
Output is correct |
26 |
Correct |
1 ms |
460 KB |
Output is correct |
27 |
Correct |
1 ms |
332 KB |
Output is correct |
28 |
Correct |
1 ms |
332 KB |
Output is correct |
29 |
Correct |
1 ms |
460 KB |
Output is correct |
30 |
Correct |
1 ms |
460 KB |
Output is correct |
31 |
Correct |
2 ms |
460 KB |
Output is correct |
32 |
Correct |
2 ms |
460 KB |
Output is correct |
33 |
Correct |
1 ms |
460 KB |
Output is correct |
34 |
Correct |
2 ms |
460 KB |
Output is correct |
35 |
Correct |
1 ms |
460 KB |
Output is correct |
36 |
Correct |
1 ms |
460 KB |
Output is correct |
37 |
Correct |
1 ms |
460 KB |
Output is correct |
38 |
Correct |
1 ms |
332 KB |
Output is correct |
39 |
Correct |
1 ms |
460 KB |
Output is correct |
40 |
Correct |
1 ms |
332 KB |
Output is correct |
41 |
Correct |
1 ms |
332 KB |
Output is correct |
42 |
Correct |
1 ms |
460 KB |
Output is correct |
43 |
Incorrect |
185 ms |
8940 KB |
X_i is not increasing |
44 |
Halted |
0 ms |
0 KB |
- |