Submission #721210

# Submission time Handle Problem Language Result Execution time Memory
721210 2023-04-10T13:57:59 Z jk410 Naan (JOI19_naan) C++17
100 / 100
401 ms 110472 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
struct frac {
	ll x, u, d;//x+u/d 꼴을 나타냄
};
bool operator<(const frac& a, const frac& b) {
	if (a.x != b.x)
		return a.x < b.x;
	return a.u * b.d < b.u* a.d;
}
int N, L;
ll V[2001];
frac X[2001][2000];
bool Used[2001];
int P[2001];
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin >> N >> L;
	for (int i = 1; i <= N; i++) {
		ll sum = 0;
		for (int j = 1; j <= L; j++) {
			cin >> V[j];
			sum += V[j];
		}
		ll cur = 0;
		for (int j = 1, k = 1; j < N; j++) {
			while ((cur + V[k]) * N <= sum * j)
				cur += V[k++];
			X[i][j] = { k - 1,sum * j - N * cur,N * V[k] };
		}
	}
	vector<pair<ll, ll>> ans;
	for (int i = 1; i < N; i++) {
		int idx;
		frac mn = { L,0,1 };
		for (int j = 1; j <= N; j++) {
			if (Used[j])
				continue;
			if (X[j][i] < mn) {
				mn = X[j][i];
				idx = j;
			}
		}
		ans.push_back({ mn.x * mn.d + mn.u,mn.d });
		P[i] = idx;
		Used[idx] = true;
	}
	for (int i = 1; i <= N; i++) {
		if (!Used[i])
			P[N] = i;
	}
	for (auto i : ans)
		cout << i.first << " " << i.second << "\n";
	for (int i = 1; i <= N; i++)
		cout << P[i] << " ";
	return 0;
}

Compilation message

naan.cpp: In function 'int main()':
naan.cpp:49:13: warning: 'idx' may be used uninitialized in this function [-Wmaybe-uninitialized]
   49 |   Used[idx] = true;
      |   ~~~~~~~~~~^~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 268 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 2 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 372 KB Output is correct
16 Correct 1 ms 468 KB Output is correct
17 Correct 2 ms 360 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 2 ms 340 KB Output is correct
21 Correct 2 ms 372 KB Output is correct
22 Correct 2 ms 376 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 2 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 268 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 2 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 344 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 372 KB Output is correct
31 Correct 1 ms 468 KB Output is correct
32 Correct 2 ms 360 KB Output is correct
33 Correct 1 ms 344 KB Output is correct
34 Correct 1 ms 340 KB Output is correct
35 Correct 2 ms 340 KB Output is correct
36 Correct 2 ms 372 KB Output is correct
37 Correct 2 ms 376 KB Output is correct
38 Correct 1 ms 340 KB Output is correct
39 Correct 2 ms 340 KB Output is correct
40 Correct 1 ms 340 KB Output is correct
41 Correct 1 ms 340 KB Output is correct
42 Correct 1 ms 340 KB Output is correct
43 Correct 26 ms 11588 KB Output is correct
44 Correct 167 ms 59532 KB Output is correct
45 Correct 106 ms 21696 KB Output is correct
46 Correct 16 ms 2180 KB Output is correct
47 Correct 124 ms 35024 KB Output is correct
48 Correct 98 ms 90292 KB Output is correct
49 Correct 36 ms 22476 KB Output is correct
50 Correct 193 ms 98432 KB Output is correct
51 Correct 102 ms 33700 KB Output is correct
52 Correct 199 ms 82820 KB Output is correct
53 Correct 158 ms 78456 KB Output is correct
54 Correct 1 ms 340 KB Output is correct
55 Correct 40 ms 52564 KB Output is correct
56 Correct 123 ms 49088 KB Output is correct
57 Correct 96 ms 42640 KB Output is correct
58 Correct 139 ms 78836 KB Output is correct
59 Correct 169 ms 38092 KB Output is correct
60 Correct 337 ms 110472 KB Output is correct
61 Correct 357 ms 109116 KB Output is correct
62 Correct 354 ms 109048 KB Output is correct
63 Correct 357 ms 106180 KB Output is correct
64 Correct 401 ms 108772 KB Output is correct
65 Correct 277 ms 102956 KB Output is correct
66 Correct 286 ms 102980 KB Output is correct
67 Correct 307 ms 102972 KB Output is correct
68 Correct 144 ms 56652 KB Output is correct
69 Correct 195 ms 49096 KB Output is correct
70 Correct 221 ms 71204 KB Output is correct
71 Correct 229 ms 76932 KB Output is correct