#include "bits/stdc++.h"
using namespace std;
#ifdef Nero
#include "Deb.h"
#else
#define debug(...)
#endif
const int N = 555;
const long long INF = 1e16;
int a[N][N];
long long dp[N][N][N];
void build(int nd, int l, int r) {
if (l + 1 == r) {
dp[nd][l][r] = a[l][r];
dp[nd][r][l] = a[l][r];
return;
}
int mid = (l + r) >> 1;
build(nd * 2, l, mid);
build(nd * 2 + 1, mid + 1, r);
for (int i = l; i <= r; ++i) {
for (int j = l; j <= r; ++j) {
dp[nd][i][j] = INF;
}
}
for (int i = l; i <= mid; ++i) {
for (int j = l; j <= mid; ++j) {
if (i == j) continue;
for (int k = mid + 1; k <= r; ++k) {
for (int m = mid + 1; m <= r; ++m) {
if (k == m) continue;
dp[nd][i][m] = min(dp[nd][i][m], dp[nd * 2][i][j] + dp[nd * 2 + 1][k][m] + a[j][k]);
dp[nd][m][i] = min(dp[nd][i][m], dp[nd * 2][j][i] + dp[nd * 2 + 1][m][k] + a[j][k]);
}
}
}
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= n; ++j) {
cin >> a[i][j];
}
}
build(1, 1, n);
long long ans = INF;
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= n; ++j) {
if (i != j) {
ans = min(ans, dp[1][i][j]);
}
}
}
cout << ans << '\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
604 KB |
Output is correct |
2 |
Correct |
0 ms |
604 KB |
Output is correct |
3 |
Correct |
1 ms |
604 KB |
Output is correct |
4 |
Correct |
0 ms |
604 KB |
Output is correct |
5 |
Correct |
0 ms |
604 KB |
Output is correct |
6 |
Correct |
1 ms |
604 KB |
Output is correct |
7 |
Correct |
0 ms |
604 KB |
Output is correct |
8 |
Correct |
1 ms |
604 KB |
Output is correct |
9 |
Correct |
1 ms |
604 KB |
Output is correct |
10 |
Correct |
1 ms |
604 KB |
Output is correct |
11 |
Correct |
1 ms |
604 KB |
Output is correct |
12 |
Correct |
1 ms |
720 KB |
Output is correct |
13 |
Correct |
1 ms |
604 KB |
Output is correct |
14 |
Correct |
1 ms |
604 KB |
Output is correct |
15 |
Correct |
1 ms |
604 KB |
Output is correct |
16 |
Correct |
1 ms |
604 KB |
Output is correct |
17 |
Correct |
1 ms |
604 KB |
Output is correct |
18 |
Correct |
1 ms |
604 KB |
Output is correct |
19 |
Correct |
1 ms |
604 KB |
Output is correct |
20 |
Correct |
0 ms |
604 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
604 KB |
Output is correct |
2 |
Correct |
0 ms |
604 KB |
Output is correct |
3 |
Correct |
1 ms |
604 KB |
Output is correct |
4 |
Correct |
0 ms |
604 KB |
Output is correct |
5 |
Correct |
0 ms |
604 KB |
Output is correct |
6 |
Correct |
1 ms |
604 KB |
Output is correct |
7 |
Correct |
0 ms |
604 KB |
Output is correct |
8 |
Correct |
1 ms |
604 KB |
Output is correct |
9 |
Correct |
1 ms |
604 KB |
Output is correct |
10 |
Correct |
1 ms |
604 KB |
Output is correct |
11 |
Correct |
1 ms |
604 KB |
Output is correct |
12 |
Correct |
1 ms |
720 KB |
Output is correct |
13 |
Correct |
1 ms |
604 KB |
Output is correct |
14 |
Correct |
1 ms |
604 KB |
Output is correct |
15 |
Correct |
1 ms |
604 KB |
Output is correct |
16 |
Correct |
1 ms |
604 KB |
Output is correct |
17 |
Correct |
1 ms |
604 KB |
Output is correct |
18 |
Correct |
1 ms |
604 KB |
Output is correct |
19 |
Correct |
1 ms |
604 KB |
Output is correct |
20 |
Correct |
0 ms |
604 KB |
Output is correct |
21 |
Correct |
43 ms |
4956 KB |
Output is correct |
22 |
Correct |
39 ms |
4956 KB |
Output is correct |
23 |
Correct |
43 ms |
4960 KB |
Output is correct |
24 |
Correct |
4 ms |
2396 KB |
Output is correct |
25 |
Correct |
4 ms |
2480 KB |
Output is correct |
26 |
Correct |
55 ms |
4956 KB |
Output is correct |
27 |
Correct |
39 ms |
4956 KB |
Output is correct |
28 |
Correct |
40 ms |
4956 KB |
Output is correct |
29 |
Correct |
40 ms |
4956 KB |
Output is correct |
30 |
Correct |
45 ms |
4956 KB |
Output is correct |
31 |
Correct |
42 ms |
4956 KB |
Output is correct |
32 |
Correct |
40 ms |
5052 KB |
Output is correct |
33 |
Correct |
41 ms |
4956 KB |
Output is correct |
34 |
Correct |
42 ms |
4956 KB |
Output is correct |
35 |
Correct |
41 ms |
4956 KB |
Output is correct |
36 |
Correct |
39 ms |
4956 KB |
Output is correct |
37 |
Correct |
39 ms |
5120 KB |
Output is correct |
38 |
Correct |
37 ms |
5124 KB |
Output is correct |
39 |
Correct |
40 ms |
4956 KB |
Output is correct |
40 |
Correct |
38 ms |
4956 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
604 KB |
Output is correct |
2 |
Correct |
0 ms |
604 KB |
Output is correct |
3 |
Correct |
1 ms |
604 KB |
Output is correct |
4 |
Correct |
0 ms |
604 KB |
Output is correct |
5 |
Correct |
0 ms |
604 KB |
Output is correct |
6 |
Correct |
1 ms |
604 KB |
Output is correct |
7 |
Correct |
0 ms |
604 KB |
Output is correct |
8 |
Correct |
1 ms |
604 KB |
Output is correct |
9 |
Correct |
1 ms |
604 KB |
Output is correct |
10 |
Correct |
1 ms |
604 KB |
Output is correct |
11 |
Correct |
1 ms |
604 KB |
Output is correct |
12 |
Correct |
1 ms |
720 KB |
Output is correct |
13 |
Correct |
1 ms |
604 KB |
Output is correct |
14 |
Correct |
1 ms |
604 KB |
Output is correct |
15 |
Correct |
1 ms |
604 KB |
Output is correct |
16 |
Correct |
1 ms |
604 KB |
Output is correct |
17 |
Correct |
1 ms |
604 KB |
Output is correct |
18 |
Correct |
1 ms |
604 KB |
Output is correct |
19 |
Correct |
1 ms |
604 KB |
Output is correct |
20 |
Correct |
0 ms |
604 KB |
Output is correct |
21 |
Correct |
43 ms |
4956 KB |
Output is correct |
22 |
Correct |
39 ms |
4956 KB |
Output is correct |
23 |
Correct |
43 ms |
4960 KB |
Output is correct |
24 |
Correct |
4 ms |
2396 KB |
Output is correct |
25 |
Correct |
4 ms |
2480 KB |
Output is correct |
26 |
Correct |
55 ms |
4956 KB |
Output is correct |
27 |
Correct |
39 ms |
4956 KB |
Output is correct |
28 |
Correct |
40 ms |
4956 KB |
Output is correct |
29 |
Correct |
40 ms |
4956 KB |
Output is correct |
30 |
Correct |
45 ms |
4956 KB |
Output is correct |
31 |
Correct |
42 ms |
4956 KB |
Output is correct |
32 |
Correct |
40 ms |
5052 KB |
Output is correct |
33 |
Correct |
41 ms |
4956 KB |
Output is correct |
34 |
Correct |
42 ms |
4956 KB |
Output is correct |
35 |
Correct |
41 ms |
4956 KB |
Output is correct |
36 |
Correct |
39 ms |
4956 KB |
Output is correct |
37 |
Correct |
39 ms |
5120 KB |
Output is correct |
38 |
Correct |
37 ms |
5124 KB |
Output is correct |
39 |
Correct |
40 ms |
4956 KB |
Output is correct |
40 |
Correct |
38 ms |
4956 KB |
Output is correct |
41 |
Execution timed out |
1530 ms |
25472 KB |
Time limit exceeded |
42 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
604 KB |
Output is correct |
2 |
Correct |
0 ms |
604 KB |
Output is correct |
3 |
Correct |
1 ms |
604 KB |
Output is correct |
4 |
Correct |
0 ms |
604 KB |
Output is correct |
5 |
Correct |
0 ms |
604 KB |
Output is correct |
6 |
Correct |
1 ms |
604 KB |
Output is correct |
7 |
Correct |
0 ms |
604 KB |
Output is correct |
8 |
Correct |
1 ms |
604 KB |
Output is correct |
9 |
Correct |
1 ms |
604 KB |
Output is correct |
10 |
Correct |
1 ms |
604 KB |
Output is correct |
11 |
Correct |
1 ms |
604 KB |
Output is correct |
12 |
Correct |
1 ms |
720 KB |
Output is correct |
13 |
Correct |
1 ms |
604 KB |
Output is correct |
14 |
Correct |
1 ms |
604 KB |
Output is correct |
15 |
Correct |
1 ms |
604 KB |
Output is correct |
16 |
Correct |
1 ms |
604 KB |
Output is correct |
17 |
Correct |
1 ms |
604 KB |
Output is correct |
18 |
Correct |
1 ms |
604 KB |
Output is correct |
19 |
Correct |
1 ms |
604 KB |
Output is correct |
20 |
Correct |
0 ms |
604 KB |
Output is correct |
21 |
Correct |
43 ms |
4956 KB |
Output is correct |
22 |
Correct |
39 ms |
4956 KB |
Output is correct |
23 |
Correct |
43 ms |
4960 KB |
Output is correct |
24 |
Correct |
4 ms |
2396 KB |
Output is correct |
25 |
Correct |
4 ms |
2480 KB |
Output is correct |
26 |
Correct |
55 ms |
4956 KB |
Output is correct |
27 |
Correct |
39 ms |
4956 KB |
Output is correct |
28 |
Correct |
40 ms |
4956 KB |
Output is correct |
29 |
Correct |
40 ms |
4956 KB |
Output is correct |
30 |
Correct |
45 ms |
4956 KB |
Output is correct |
31 |
Correct |
42 ms |
4956 KB |
Output is correct |
32 |
Correct |
40 ms |
5052 KB |
Output is correct |
33 |
Correct |
41 ms |
4956 KB |
Output is correct |
34 |
Correct |
42 ms |
4956 KB |
Output is correct |
35 |
Correct |
41 ms |
4956 KB |
Output is correct |
36 |
Correct |
39 ms |
4956 KB |
Output is correct |
37 |
Correct |
39 ms |
5120 KB |
Output is correct |
38 |
Correct |
37 ms |
5124 KB |
Output is correct |
39 |
Correct |
40 ms |
4956 KB |
Output is correct |
40 |
Correct |
38 ms |
4956 KB |
Output is correct |
41 |
Execution timed out |
1530 ms |
25472 KB |
Time limit exceeded |
42 |
Halted |
0 ms |
0 KB |
- |