#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
vector<vector<int>> a(n, vector<int>(n));
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
cin >> a[i][j];
}
}
int lg = 0;
for (int p = 1; p < n; p *= 2, lg++) {}
const long long inf = (long long) 1e18;
vector<long long> dp(n);
for (int i = 0; i + 1 < n; i++) {
vector<long long> new_dp(n, inf);
for (int x = 0; x < n; x++) {
int bit;
for (int b = lg; b >= 0; b--) {
if ((i >> b & 1) != ((i + 1) >> b & 1)) {
bit = b;
break;
}
}
for (int xr = 0; xr < (1 << bit); xr++) {
int y = (x ^ xr);
new_dp[y] = min(new_dp[y], dp[x] + a[(i ^ x)][(i + 1) ^ y]);
}
}
swap(dp, new_dp);
}
cout << *min_element(dp.begin(), dp.end()) << '\n';
return 0;
}
Compilation message
Main.cpp: In function 'int main()':
Main.cpp:30:32: warning: 'bit' may be used uninitialized in this function [-Wmaybe-uninitialized]
30 | for (int xr = 0; xr < (1 << bit); xr++) {
| ~~~^~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
456 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
456 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
456 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
456 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
456 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
456 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
2 ms |
604 KB |
Output is correct |
22 |
Correct |
2 ms |
604 KB |
Output is correct |
23 |
Correct |
2 ms |
604 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
2 ms |
604 KB |
Output is correct |
27 |
Correct |
2 ms |
460 KB |
Output is correct |
28 |
Correct |
1 ms |
860 KB |
Output is correct |
29 |
Correct |
2 ms |
604 KB |
Output is correct |
30 |
Correct |
2 ms |
636 KB |
Output is correct |
31 |
Correct |
2 ms |
604 KB |
Output is correct |
32 |
Correct |
2 ms |
604 KB |
Output is correct |
33 |
Correct |
2 ms |
604 KB |
Output is correct |
34 |
Correct |
2 ms |
604 KB |
Output is correct |
35 |
Correct |
2 ms |
604 KB |
Output is correct |
36 |
Correct |
1 ms |
688 KB |
Output is correct |
37 |
Correct |
2 ms |
600 KB |
Output is correct |
38 |
Correct |
2 ms |
636 KB |
Output is correct |
39 |
Correct |
2 ms |
604 KB |
Output is correct |
40 |
Correct |
1 ms |
464 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
456 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
456 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
456 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
2 ms |
604 KB |
Output is correct |
22 |
Correct |
2 ms |
604 KB |
Output is correct |
23 |
Correct |
2 ms |
604 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
2 ms |
604 KB |
Output is correct |
27 |
Correct |
2 ms |
460 KB |
Output is correct |
28 |
Correct |
1 ms |
860 KB |
Output is correct |
29 |
Correct |
2 ms |
604 KB |
Output is correct |
30 |
Correct |
2 ms |
636 KB |
Output is correct |
31 |
Correct |
2 ms |
604 KB |
Output is correct |
32 |
Correct |
2 ms |
604 KB |
Output is correct |
33 |
Correct |
2 ms |
604 KB |
Output is correct |
34 |
Correct |
2 ms |
604 KB |
Output is correct |
35 |
Correct |
2 ms |
604 KB |
Output is correct |
36 |
Correct |
1 ms |
688 KB |
Output is correct |
37 |
Correct |
2 ms |
600 KB |
Output is correct |
38 |
Correct |
2 ms |
636 KB |
Output is correct |
39 |
Correct |
2 ms |
604 KB |
Output is correct |
40 |
Correct |
1 ms |
464 KB |
Output is correct |
41 |
Correct |
24 ms |
3928 KB |
Output is correct |
42 |
Correct |
22 ms |
3924 KB |
Output is correct |
43 |
Correct |
21 ms |
3924 KB |
Output is correct |
44 |
Correct |
21 ms |
3928 KB |
Output is correct |
45 |
Correct |
22 ms |
3920 KB |
Output is correct |
46 |
Correct |
22 ms |
3928 KB |
Output is correct |
47 |
Correct |
21 ms |
3932 KB |
Output is correct |
48 |
Correct |
23 ms |
3924 KB |
Output is correct |
49 |
Correct |
28 ms |
3792 KB |
Output is correct |
50 |
Correct |
21 ms |
3792 KB |
Output is correct |
51 |
Correct |
22 ms |
3932 KB |
Output is correct |
52 |
Correct |
22 ms |
3928 KB |
Output is correct |
53 |
Correct |
21 ms |
3932 KB |
Output is correct |
54 |
Correct |
27 ms |
3920 KB |
Output is correct |
55 |
Correct |
23 ms |
3932 KB |
Output is correct |
56 |
Correct |
21 ms |
3928 KB |
Output is correct |
57 |
Correct |
22 ms |
3920 KB |
Output is correct |
58 |
Correct |
23 ms |
3932 KB |
Output is correct |
59 |
Correct |
20 ms |
3932 KB |
Output is correct |
60 |
Correct |
22 ms |
3916 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
456 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
456 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
456 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
2 ms |
604 KB |
Output is correct |
22 |
Correct |
2 ms |
604 KB |
Output is correct |
23 |
Correct |
2 ms |
604 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
2 ms |
604 KB |
Output is correct |
27 |
Correct |
2 ms |
460 KB |
Output is correct |
28 |
Correct |
1 ms |
860 KB |
Output is correct |
29 |
Correct |
2 ms |
604 KB |
Output is correct |
30 |
Correct |
2 ms |
636 KB |
Output is correct |
31 |
Correct |
2 ms |
604 KB |
Output is correct |
32 |
Correct |
2 ms |
604 KB |
Output is correct |
33 |
Correct |
2 ms |
604 KB |
Output is correct |
34 |
Correct |
2 ms |
604 KB |
Output is correct |
35 |
Correct |
2 ms |
604 KB |
Output is correct |
36 |
Correct |
1 ms |
688 KB |
Output is correct |
37 |
Correct |
2 ms |
600 KB |
Output is correct |
38 |
Correct |
2 ms |
636 KB |
Output is correct |
39 |
Correct |
2 ms |
604 KB |
Output is correct |
40 |
Correct |
1 ms |
464 KB |
Output is correct |
41 |
Correct |
24 ms |
3928 KB |
Output is correct |
42 |
Correct |
22 ms |
3924 KB |
Output is correct |
43 |
Correct |
21 ms |
3924 KB |
Output is correct |
44 |
Correct |
21 ms |
3928 KB |
Output is correct |
45 |
Correct |
22 ms |
3920 KB |
Output is correct |
46 |
Correct |
22 ms |
3928 KB |
Output is correct |
47 |
Correct |
21 ms |
3932 KB |
Output is correct |
48 |
Correct |
23 ms |
3924 KB |
Output is correct |
49 |
Correct |
28 ms |
3792 KB |
Output is correct |
50 |
Correct |
21 ms |
3792 KB |
Output is correct |
51 |
Correct |
22 ms |
3932 KB |
Output is correct |
52 |
Correct |
22 ms |
3928 KB |
Output is correct |
53 |
Correct |
21 ms |
3932 KB |
Output is correct |
54 |
Correct |
27 ms |
3920 KB |
Output is correct |
55 |
Correct |
23 ms |
3932 KB |
Output is correct |
56 |
Correct |
21 ms |
3928 KB |
Output is correct |
57 |
Correct |
22 ms |
3920 KB |
Output is correct |
58 |
Correct |
23 ms |
3932 KB |
Output is correct |
59 |
Correct |
20 ms |
3932 KB |
Output is correct |
60 |
Correct |
22 ms |
3916 KB |
Output is correct |
61 |
Correct |
441 ms |
57168 KB |
Output is correct |
62 |
Correct |
403 ms |
57300 KB |
Output is correct |
63 |
Correct |
375 ms |
57168 KB |
Output is correct |
64 |
Correct |
371 ms |
57304 KB |
Output is correct |
65 |
Correct |
434 ms |
57340 KB |
Output is correct |
66 |
Correct |
398 ms |
57172 KB |
Output is correct |
67 |
Correct |
373 ms |
57200 KB |
Output is correct |
68 |
Correct |
374 ms |
57172 KB |
Output is correct |
69 |
Correct |
364 ms |
57168 KB |
Output is correct |
70 |
Correct |
363 ms |
57164 KB |
Output is correct |
71 |
Correct |
359 ms |
57940 KB |
Output is correct |
72 |
Correct |
368 ms |
58152 KB |
Output is correct |
73 |
Correct |
405 ms |
57964 KB |
Output is correct |
74 |
Correct |
461 ms |
58196 KB |
Output is correct |
75 |
Correct |
376 ms |
57764 KB |
Output is correct |
76 |
Correct |
407 ms |
57900 KB |
Output is correct |
77 |
Correct |
431 ms |
58008 KB |
Output is correct |
78 |
Correct |
409 ms |
57808 KB |
Output is correct |
79 |
Correct |
397 ms |
57772 KB |
Output is correct |
80 |
Correct |
401 ms |
57904 KB |
Output is correct |