Submission #470992

# Submission time Handle Problem Language Result Execution time Memory
470992 2021-09-06T14:52:41 Z Namnamseo Naan (JOI19_naan) C++17
29 / 100
1167 ms 92484 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];

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 cuts[maxn][maxn];

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) vs[i] = accumulate(v[i]+1, v[i]+l+1, 0ll);

	for (int i=1; i<=n; ++i) {
		frac cx{};
		frac tgt{vs[i], n};
		int cj = 0;
		for (int j=1; j<=l; ++j) {
			frac yb{v[i][j]};
			while (yb.j) {
				if (tgt <= yb) {
					yb = yb - tgt;
					cx = cx + tgt / frac{v[i][j]};
					cuts[i][++cj] = cx;
					tgt = {vs[i], n};
				} else {
					tgt = tgt - yb;
					cx = j;
					yb = 0;
				}
			}
		}
	}

	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 = cuts[i][pi];
			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 30 ms 63532 KB Output is correct
2 Correct 29 ms 63484 KB Output is correct
3 Correct 30 ms 63564 KB Output is correct
4 Correct 29 ms 63548 KB Output is correct
5 Correct 29 ms 63564 KB Output is correct
6 Correct 29 ms 63504 KB Output is correct
7 Correct 31 ms 63556 KB Output is correct
8 Correct 28 ms 63520 KB Output is correct
9 Correct 28 ms 63576 KB Output is correct
10 Correct 33 ms 63692 KB Output is correct
11 Correct 30 ms 63568 KB Output is correct
12 Correct 30 ms 63608 KB Output is correct
13 Correct 30 ms 63564 KB Output is correct
14 Correct 30 ms 63504 KB Output is correct
15 Correct 29 ms 63544 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 30 ms 63564 KB Output is correct
2 Correct 31 ms 63580 KB Output is correct
3 Correct 30 ms 63564 KB Output is correct
4 Correct 30 ms 63560 KB Output is correct
5 Correct 32 ms 63600 KB Output is correct
6 Correct 30 ms 63544 KB Output is correct
7 Correct 30 ms 63540 KB Output is correct
8 Correct 30 ms 63492 KB Output is correct
9 Correct 32 ms 63556 KB Output is correct
10 Correct 30 ms 63572 KB Output is correct
11 Correct 30 ms 63640 KB Output is correct
12 Correct 30 ms 63556 KB Output is correct
13 Correct 30 ms 63488 KB Output is correct
14 Correct 33 ms 63564 KB Output is correct
15 Correct 31 ms 63572 KB Output is correct
16 Correct 30 ms 63536 KB Output is correct
17 Correct 31 ms 63564 KB Output is correct
18 Correct 31 ms 63556 KB Output is correct
19 Correct 32 ms 63644 KB Output is correct
20 Correct 30 ms 63564 KB Output is correct
21 Correct 31 ms 63624 KB Output is correct
22 Correct 30 ms 63628 KB Output is correct
23 Correct 29 ms 63556 KB Output is correct
24 Correct 30 ms 63628 KB Output is correct
25 Correct 33 ms 63564 KB Output is correct
26 Correct 29 ms 63564 KB Output is correct
27 Correct 31 ms 63600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 30 ms 63532 KB Output is correct
2 Correct 29 ms 63484 KB Output is correct
3 Correct 30 ms 63564 KB Output is correct
4 Correct 29 ms 63548 KB Output is correct
5 Correct 29 ms 63564 KB Output is correct
6 Correct 29 ms 63504 KB Output is correct
7 Correct 31 ms 63556 KB Output is correct
8 Correct 28 ms 63520 KB Output is correct
9 Correct 28 ms 63576 KB Output is correct
10 Correct 33 ms 63692 KB Output is correct
11 Correct 30 ms 63568 KB Output is correct
12 Correct 30 ms 63608 KB Output is correct
13 Correct 30 ms 63564 KB Output is correct
14 Correct 30 ms 63504 KB Output is correct
15 Correct 29 ms 63544 KB Output is correct
16 Correct 30 ms 63564 KB Output is correct
17 Correct 31 ms 63580 KB Output is correct
18 Correct 30 ms 63564 KB Output is correct
19 Correct 30 ms 63560 KB Output is correct
20 Correct 32 ms 63600 KB Output is correct
21 Correct 30 ms 63544 KB Output is correct
22 Correct 30 ms 63540 KB Output is correct
23 Correct 30 ms 63492 KB Output is correct
24 Correct 32 ms 63556 KB Output is correct
25 Correct 30 ms 63572 KB Output is correct
26 Correct 30 ms 63640 KB Output is correct
27 Correct 30 ms 63556 KB Output is correct
28 Correct 30 ms 63488 KB Output is correct
29 Correct 33 ms 63564 KB Output is correct
30 Correct 31 ms 63572 KB Output is correct
31 Correct 30 ms 63536 KB Output is correct
32 Correct 31 ms 63564 KB Output is correct
33 Correct 31 ms 63556 KB Output is correct
34 Correct 32 ms 63644 KB Output is correct
35 Correct 30 ms 63564 KB Output is correct
36 Correct 31 ms 63624 KB Output is correct
37 Correct 30 ms 63628 KB Output is correct
38 Correct 29 ms 63556 KB Output is correct
39 Correct 30 ms 63628 KB Output is correct
40 Correct 33 ms 63564 KB Output is correct
41 Correct 29 ms 63564 KB Output is correct
42 Correct 31 ms 63600 KB Output is correct
43 Correct 207 ms 67836 KB Output is correct
44 Incorrect 1167 ms 92484 KB X_i is not increasing
45 Halted 0 ms 0 KB -