Submission #535008

# Submission time Handle Problem Language Result Execution time Memory
535008 2022-03-09T09:24:02 Z malokov Naan (JOI19_naan) C++17
100 / 100
463 ms 116508 KB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define maxn 2005
#define pll pair<ll, ll>
#define ff first
#define ss second
#define io ios_base::sync_with_stdio(0);cin.tie(0);
const ll inf = 1<<30;
ll a[maxn][maxn];
pll b[maxn][maxn];
bool vis[maxn];
int main() {
	io
	int n, l;
	cin >> n >> l;
	for (int i = 0;i < n;i++) {
		ll tot = 0;
		for (int j = 0;j < l;j++) {
			cin >> a[i][j];
			tot += a[i][j];
			a[i][j] *= n;
		}
		ll cur = 0, ind = 0;
		for (int j = 1;j <= n;j++) {
			while (ind < l && cur + a[i][ind] <= tot*j) {
				cur += a[i][ind];
				ind++;
			}
			if (ind == l) b[i][j] = {l, 1};
			else b[i][j] = {(tot * j - cur) + ind*a[i][ind], a[i][ind]};
		}
	}
	auto cmp = [&] (pll x, pll y){return x.ff * (y.ss/n) < (x.ss/n) * y.ff;};
	vector<int> ans;
	vector<pll> frac;
	for (int i = 1;i <= n;i++) {
		pll best = {inf, 1};
		int bind = 0;
		for (int j = 0;j < n;j++) {
			if (!vis[j] && !cmp(best, b[j][i])) {
				best = b[j][i];
				bind = j;
			}
		}
		ans.push_back(bind+1);
		vis[bind] = 1;
		frac.push_back(best);
	}
	frac.pop_back();
	for (auto i:frac) cout << i.ff << " " << i.ss << "\n";
	for (int i:ans) cout << i << " ";
	cout << endl;
}
# Verdict Execution time Memory Grader output
1 Correct 0 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 324 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 328 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 336 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 364 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 2 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 2 ms 344 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 0 ms 332 KB Output is correct
24 Correct 1 ms 332 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 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 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 324 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 328 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 336 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 364 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 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 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 332 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 332 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
29 Correct 2 ms 332 KB Output is correct
30 Correct 1 ms 332 KB Output is correct
31 Correct 1 ms 332 KB Output is correct
32 Correct 2 ms 344 KB Output is correct
33 Correct 1 ms 332 KB Output is correct
34 Correct 1 ms 332 KB Output is correct
35 Correct 1 ms 332 KB Output is correct
36 Correct 1 ms 332 KB Output is correct
37 Correct 1 ms 332 KB Output is correct
38 Correct 0 ms 332 KB Output is correct
39 Correct 1 ms 332 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 332 KB Output is correct
43 Correct 31 ms 13368 KB Output is correct
44 Correct 174 ms 63904 KB Output is correct
45 Correct 130 ms 28760 KB Output is correct
46 Correct 17 ms 4036 KB Output is correct
47 Correct 130 ms 42448 KB Output is correct
48 Correct 104 ms 75204 KB Output is correct
49 Correct 47 ms 24040 KB Output is correct
50 Correct 196 ms 95588 KB Output is correct
51 Correct 114 ms 41668 KB Output is correct
52 Correct 214 ms 86992 KB Output is correct
53 Correct 167 ms 80852 KB Output is correct
54 Correct 1 ms 332 KB Output is correct
55 Correct 44 ms 43920 KB Output is correct
56 Correct 153 ms 56284 KB Output is correct
57 Correct 108 ms 49208 KB Output is correct
58 Correct 147 ms 78672 KB Output is correct
59 Correct 152 ms 46020 KB Output is correct
60 Correct 392 ms 116412 KB Output is correct
61 Correct 426 ms 116316 KB Output is correct
62 Correct 382 ms 116136 KB Output is correct
63 Correct 463 ms 116508 KB Output is correct
64 Correct 387 ms 116424 KB Output is correct
65 Correct 280 ms 103152 KB Output is correct
66 Correct 267 ms 103236 KB Output is correct
67 Correct 310 ms 103116 KB Output is correct
68 Correct 170 ms 60076 KB Output is correct
69 Correct 170 ms 56648 KB Output is correct
70 Correct 201 ms 72060 KB Output is correct
71 Correct 267 ms 82244 KB Output is correct