Submission #470993

# Submission time Handle Problem Language Result Execution time Memory
470993 2021-09-06T14:54:15 Z Namnamseo Naan (JOI19_naan) C++17
29 / 100
4000 ms 82356 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]};
					if (cx.m >= int(1e9)) for(;;);
					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 29 ms 63476 KB Output is correct
2 Correct 29 ms 63580 KB Output is correct
3 Correct 31 ms 63572 KB Output is correct
4 Correct 29 ms 63572 KB Output is correct
5 Correct 30 ms 63476 KB Output is correct
6 Correct 33 ms 63556 KB Output is correct
7 Correct 30 ms 63564 KB Output is correct
8 Correct 30 ms 63492 KB Output is correct
9 Correct 29 ms 63556 KB Output is correct
10 Correct 29 ms 63488 KB Output is correct
11 Correct 34 ms 63556 KB Output is correct
12 Correct 31 ms 63504 KB Output is correct
13 Correct 30 ms 63604 KB Output is correct
14 Correct 30 ms 63476 KB Output is correct
15 Correct 32 ms 63584 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 30 ms 63480 KB Output is correct
2 Correct 29 ms 63588 KB Output is correct
3 Correct 32 ms 63588 KB Output is correct
4 Correct 32 ms 63524 KB Output is correct
5 Correct 30 ms 63632 KB Output is correct
6 Correct 30 ms 63568 KB Output is correct
7 Correct 36 ms 63528 KB Output is correct
8 Correct 29 ms 63572 KB Output is correct
9 Correct 30 ms 63552 KB Output is correct
10 Correct 35 ms 63556 KB Output is correct
11 Correct 31 ms 63624 KB Output is correct
12 Correct 31 ms 63556 KB Output is correct
13 Correct 31 ms 63568 KB Output is correct
14 Correct 30 ms 63652 KB Output is correct
15 Correct 35 ms 63584 KB Output is correct
16 Correct 32 ms 63648 KB Output is correct
17 Correct 31 ms 63668 KB Output is correct
18 Correct 31 ms 63640 KB Output is correct
19 Correct 32 ms 63668 KB Output is correct
20 Correct 32 ms 63536 KB Output is correct
21 Correct 33 ms 63624 KB Output is correct
22 Correct 35 ms 63668 KB Output is correct
23 Correct 30 ms 63564 KB Output is correct
24 Correct 32 ms 63540 KB Output is correct
25 Correct 32 ms 63620 KB Output is correct
26 Correct 31 ms 63492 KB Output is correct
27 Correct 31 ms 63584 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 29 ms 63476 KB Output is correct
2 Correct 29 ms 63580 KB Output is correct
3 Correct 31 ms 63572 KB Output is correct
4 Correct 29 ms 63572 KB Output is correct
5 Correct 30 ms 63476 KB Output is correct
6 Correct 33 ms 63556 KB Output is correct
7 Correct 30 ms 63564 KB Output is correct
8 Correct 30 ms 63492 KB Output is correct
9 Correct 29 ms 63556 KB Output is correct
10 Correct 29 ms 63488 KB Output is correct
11 Correct 34 ms 63556 KB Output is correct
12 Correct 31 ms 63504 KB Output is correct
13 Correct 30 ms 63604 KB Output is correct
14 Correct 30 ms 63476 KB Output is correct
15 Correct 32 ms 63584 KB Output is correct
16 Correct 30 ms 63480 KB Output is correct
17 Correct 29 ms 63588 KB Output is correct
18 Correct 32 ms 63588 KB Output is correct
19 Correct 32 ms 63524 KB Output is correct
20 Correct 30 ms 63632 KB Output is correct
21 Correct 30 ms 63568 KB Output is correct
22 Correct 36 ms 63528 KB Output is correct
23 Correct 29 ms 63572 KB Output is correct
24 Correct 30 ms 63552 KB Output is correct
25 Correct 35 ms 63556 KB Output is correct
26 Correct 31 ms 63624 KB Output is correct
27 Correct 31 ms 63556 KB Output is correct
28 Correct 31 ms 63568 KB Output is correct
29 Correct 30 ms 63652 KB Output is correct
30 Correct 35 ms 63584 KB Output is correct
31 Correct 32 ms 63648 KB Output is correct
32 Correct 31 ms 63668 KB Output is correct
33 Correct 31 ms 63640 KB Output is correct
34 Correct 32 ms 63668 KB Output is correct
35 Correct 32 ms 63536 KB Output is correct
36 Correct 33 ms 63624 KB Output is correct
37 Correct 35 ms 63668 KB Output is correct
38 Correct 30 ms 63564 KB Output is correct
39 Correct 32 ms 63540 KB Output is correct
40 Correct 32 ms 63620 KB Output is correct
41 Correct 31 ms 63492 KB Output is correct
42 Correct 31 ms 63584 KB Output is correct
43 Correct 207 ms 67780 KB Output is correct
44 Execution timed out 4018 ms 82356 KB Time limit exceeded
45 Halted 0 ms 0 KB -