Submission #378347

# Submission time Handle Problem Language Result Execution time Memory
378347 2021-03-16T14:11:44 Z cheissmart Naan (JOI19_naan) C++14
100 / 100
450 ms 93444 KB
#include <bits/stdc++.h>
#define IO_OP std::ios::sync_with_stdio(0); std::cin.tie(0);
#define F first
#define S second
#define V vector
#define PB push_back
#define MP make_pair
#define EB emplace_back
#define ALL(v) (v).begin(), (v).end()
#define debug(x) cerr << "Line(" << __LINE__ << ") -> " << #x << " is " << x << endl

using namespace std;

typedef long long ll;
typedef pair<int, int> pi;
typedef V<int> vi;

const int INF = 1e9 + 7, N = 2002;

int a[N][N], sum[N];
pair<ll, ll> r[N][N];
int n, l;

bool cmp(pair<ll, ll> a, pair<ll, ll> b) {
	return a.F * (b.S / n) < (a.S / n) * b.F;
}

signed main()
{
	IO_OP;
	
	cin >> n >> l;
	for(int i = 0; i < n; i++) {
		int sum = 0;
		for(int j = 0; j < l; j++) {
			cin >> a[i][j];
			sum += a[i][j];
			a[i][j] *= n;
		}
		int ptr = 0;
		ll cur = 0;
		for(int j = 1; j < n; j++) {
			ll need = (ll) sum * j;
			while(cur + a[i][ptr] <= need) {
				cur += a[i][ptr];
				ptr++;
			}
			r[i][j - 1] = {(ll) ptr * a[i][ptr] + need - cur, a[i][ptr]};
		}
	}
	vi p(n), vis(n);
	for(int i = 0; i < n - 1; i++) {
		int bestj = -1;
		for(int j = 0; j < n; j++) if(!vis[j]) {
			if(bestj == -1 || cmp(r[j][i], r[bestj][i])) {
				bestj = j;
			}
		}
		vis[bestj] = 1;
		p[i] = bestj;
		cout << r[bestj][i].F << " " << r[bestj][i].S << '\n';
	}
	for(int i = 0; i < n; i++) if(!vis[i])
		p[n - 1] = i;
	for(int i = 0; i < n; i++)
		cout << p[i] + 1 << ' ';

}

# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 492 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 2 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 492 KB Output is correct
4 Correct 1 ms 492 KB Output is correct
5 Correct 1 ms 492 KB Output is correct
6 Correct 1 ms 512 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 3 ms 492 KB Output is correct
10 Correct 2 ms 512 KB Output is correct
11 Correct 2 ms 492 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 492 KB Output is correct
15 Correct 1 ms 492 KB Output is correct
16 Correct 1 ms 492 KB Output is correct
17 Correct 1 ms 492 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 492 KB Output is correct
20 Correct 1 ms 416 KB Output is correct
21 Correct 1 ms 492 KB Output is correct
22 Correct 1 ms 492 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 1 ms 364 KB Output is correct
27 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 492 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 2 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 492 KB Output is correct
19 Correct 1 ms 492 KB Output is correct
20 Correct 1 ms 492 KB Output is correct
21 Correct 1 ms 512 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 3 ms 492 KB Output is correct
25 Correct 2 ms 512 KB Output is correct
26 Correct 2 ms 492 KB Output is correct
27 Correct 1 ms 364 KB Output is correct
28 Correct 1 ms 364 KB Output is correct
29 Correct 1 ms 492 KB Output is correct
30 Correct 1 ms 492 KB Output is correct
31 Correct 1 ms 492 KB Output is correct
32 Correct 1 ms 492 KB Output is correct
33 Correct 1 ms 364 KB Output is correct
34 Correct 1 ms 492 KB Output is correct
35 Correct 1 ms 416 KB Output is correct
36 Correct 1 ms 492 KB Output is correct
37 Correct 1 ms 492 KB Output is correct
38 Correct 1 ms 364 KB Output is correct
39 Correct 1 ms 364 KB Output is correct
40 Correct 1 ms 364 KB Output is correct
41 Correct 1 ms 364 KB Output is correct
42 Correct 1 ms 364 KB Output is correct
43 Correct 35 ms 12420 KB Output is correct
44 Correct 214 ms 55660 KB Output is correct
45 Correct 135 ms 23404 KB Output is correct
46 Correct 21 ms 3180 KB Output is correct
47 Correct 162 ms 35308 KB Output is correct
48 Correct 134 ms 71916 KB Output is correct
49 Correct 53 ms 22124 KB Output is correct
50 Correct 254 ms 83180 KB Output is correct
51 Correct 158 ms 33388 KB Output is correct
52 Correct 276 ms 73580 KB Output is correct
53 Correct 222 ms 69612 KB Output is correct
54 Correct 1 ms 364 KB Output is correct
55 Correct 53 ms 43372 KB Output is correct
56 Correct 178 ms 46188 KB Output is correct
57 Correct 169 ms 40684 KB Output is correct
58 Correct 189 ms 69612 KB Output is correct
59 Correct 163 ms 37356 KB Output is correct
60 Correct 449 ms 93444 KB Output is correct
61 Correct 443 ms 93292 KB Output is correct
62 Correct 435 ms 93036 KB Output is correct
63 Correct 437 ms 93152 KB Output is correct
64 Correct 450 ms 93420 KB Output is correct
65 Correct 347 ms 87532 KB Output is correct
66 Correct 347 ms 87532 KB Output is correct
67 Correct 345 ms 87404 KB Output is correct
68 Correct 172 ms 52588 KB Output is correct
69 Correct 197 ms 46828 KB Output is correct
70 Correct 188 ms 64236 KB Output is correct
71 Correct 306 ms 69740 KB Output is correct