답안 #532537

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
532537 2022-03-03T06:08:08 Z 8e7 Naan (JOI19_naan) C++17
100 / 100
391 ms 103236 KB
//Challenge: Accepted
#include <bits/stdc++.h>
using namespace std;
#ifdef zisk
void debug(){cout << endl;}
template<class T, class ... U> void debug(T a, U ... b){cout << a << " ", debug(b...);}
template<class T> void pary(T l, T r) {
	while (l != r) cout << *l << " ", l++;
	cout << endl;
}
#else
#define debug(...) 0
#define pary(...) 0
#endif
#define ll long long
#define maxn 2005
#define pii 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];
pii 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 = [&] (pii x, pii y){return x.ff * (y.ss/n) < (x.ss/n) * y.ff;};
	vector<int> ans;
	vector<pii> frac;
	for (int i = 1;i <= n;i++) {
		pii 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;
}
# 결과 실행 시간 메모리 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 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 0 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
# 결과 실행 시간 메모리 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 0 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 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
# 결과 실행 시간 메모리 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 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 0 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 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 0 ms 332 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
29 Correct 1 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 1 ms 332 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 1 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 26 ms 11852 KB Output is correct
44 Correct 168 ms 53996 KB Output is correct
45 Correct 105 ms 28868 KB Output is correct
46 Correct 15 ms 3988 KB Output is correct
47 Correct 125 ms 42456 KB Output is correct
48 Correct 104 ms 75216 KB Output is correct
49 Correct 43 ms 24016 KB Output is correct
50 Correct 194 ms 95564 KB Output is correct
51 Correct 110 ms 41580 KB Output is correct
52 Correct 203 ms 86972 KB Output is correct
53 Correct 160 ms 80860 KB Output is correct
54 Correct 1 ms 332 KB Output is correct
55 Correct 42 ms 43972 KB Output is correct
56 Correct 133 ms 56308 KB Output is correct
57 Correct 104 ms 49240 KB Output is correct
58 Correct 144 ms 78580 KB Output is correct
59 Correct 121 ms 46024 KB Output is correct
60 Correct 374 ms 98108 KB Output is correct
61 Correct 391 ms 98528 KB Output is correct
62 Correct 376 ms 97832 KB Output is correct
63 Correct 385 ms 98792 KB Output is correct
64 Correct 378 ms 98116 KB Output is correct
65 Correct 260 ms 103108 KB Output is correct
66 Correct 275 ms 103236 KB Output is correct
67 Correct 266 ms 103156 KB Output is correct
68 Correct 138 ms 60172 KB Output is correct
69 Correct 155 ms 56476 KB Output is correct
70 Correct 151 ms 72096 KB Output is correct
71 Correct 242 ms 82364 KB Output is correct