#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr ll INF = 4e18;
ll dp[2048][2048], S[2048][2048], a[2048][2048];
int dep[2048][2048];
void dnc(int l, int r, int c){
if (r-l+1 == 2){
dp[l][r] = a[l][r];
dp[r][l] = a[r][l];
dep[l][r] = c;
dep[r][l] = c;
return;
}
int m = (l+r)>>1;
dnc(l, m, c+1); dnc(m+1, r, c+1);
for (int i=l;i<=m;i++){
for (int j=m+1;j<=r;j++){
dp[i][j] = dp[j][i] = INF;
dep[i][j] = dep[j][i] = c;
}
}
for (int k=m+1;k<=r;k++){
for (int i=l;i<=m;i++){
S[i][k] = INF;
for (int j=l;j<=m;j++) if (dep[i][j]==c+1){
S[i][k] = min(S[i][k], dp[i][j] + a[j][k]);
}
for (int j=m+1;j<=r;j++) if (dep[j][k]==c+1){
dp[i][j] = min(dp[i][j], S[i][k] + dp[k][j]);
dp[j][i] = dp[i][j];
}
}
}
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
for (int i=0;i<n;i++){
for (int j=0;j<n;j++) cin >> a[i][j];
}
dnc(0, n-1, 1);
ll ans = INF;
for (int i=0;i<n;i++) for (int j=0;j<n;j++) if (dep[i][j]==1) ans = min(ans, dp[i][j]);
cout << ans << '\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
596 KB |
Output is correct |
2 |
Correct |
1 ms |
468 KB |
Output is correct |
3 |
Correct |
1 ms |
596 KB |
Output is correct |
4 |
Correct |
1 ms |
596 KB |
Output is correct |
5 |
Correct |
0 ms |
596 KB |
Output is correct |
6 |
Correct |
1 ms |
596 KB |
Output is correct |
7 |
Correct |
1 ms |
468 KB |
Output is correct |
8 |
Correct |
0 ms |
596 KB |
Output is correct |
9 |
Correct |
1 ms |
468 KB |
Output is correct |
10 |
Correct |
1 ms |
596 KB |
Output is correct |
11 |
Correct |
1 ms |
596 KB |
Output is correct |
12 |
Correct |
1 ms |
596 KB |
Output is correct |
13 |
Correct |
1 ms |
596 KB |
Output is correct |
14 |
Correct |
1 ms |
596 KB |
Output is correct |
15 |
Correct |
0 ms |
468 KB |
Output is correct |
16 |
Correct |
0 ms |
596 KB |
Output is correct |
17 |
Correct |
0 ms |
468 KB |
Output is correct |
18 |
Correct |
1 ms |
468 KB |
Output is correct |
19 |
Correct |
1 ms |
724 KB |
Output is correct |
20 |
Correct |
1 ms |
596 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
596 KB |
Output is correct |
2 |
Correct |
1 ms |
468 KB |
Output is correct |
3 |
Correct |
1 ms |
596 KB |
Output is correct |
4 |
Correct |
1 ms |
596 KB |
Output is correct |
5 |
Correct |
0 ms |
596 KB |
Output is correct |
6 |
Correct |
1 ms |
596 KB |
Output is correct |
7 |
Correct |
1 ms |
468 KB |
Output is correct |
8 |
Correct |
0 ms |
596 KB |
Output is correct |
9 |
Correct |
1 ms |
468 KB |
Output is correct |
10 |
Correct |
1 ms |
596 KB |
Output is correct |
11 |
Correct |
1 ms |
596 KB |
Output is correct |
12 |
Correct |
1 ms |
596 KB |
Output is correct |
13 |
Correct |
1 ms |
596 KB |
Output is correct |
14 |
Correct |
1 ms |
596 KB |
Output is correct |
15 |
Correct |
0 ms |
468 KB |
Output is correct |
16 |
Correct |
0 ms |
596 KB |
Output is correct |
17 |
Correct |
0 ms |
468 KB |
Output is correct |
18 |
Correct |
1 ms |
468 KB |
Output is correct |
19 |
Correct |
1 ms |
724 KB |
Output is correct |
20 |
Correct |
1 ms |
596 KB |
Output is correct |
21 |
Correct |
5 ms |
2340 KB |
Output is correct |
22 |
Correct |
5 ms |
2388 KB |
Output is correct |
23 |
Correct |
5 ms |
2392 KB |
Output is correct |
24 |
Correct |
1 ms |
1364 KB |
Output is correct |
25 |
Correct |
1 ms |
1364 KB |
Output is correct |
26 |
Correct |
6 ms |
2396 KB |
Output is correct |
27 |
Correct |
5 ms |
2324 KB |
Output is correct |
28 |
Correct |
6 ms |
2348 KB |
Output is correct |
29 |
Correct |
5 ms |
2340 KB |
Output is correct |
30 |
Correct |
5 ms |
2388 KB |
Output is correct |
31 |
Correct |
5 ms |
2412 KB |
Output is correct |
32 |
Correct |
5 ms |
2388 KB |
Output is correct |
33 |
Correct |
4 ms |
2404 KB |
Output is correct |
34 |
Correct |
5 ms |
2388 KB |
Output is correct |
35 |
Correct |
5 ms |
2364 KB |
Output is correct |
36 |
Correct |
4 ms |
2400 KB |
Output is correct |
37 |
Correct |
5 ms |
2396 KB |
Output is correct |
38 |
Correct |
4 ms |
2392 KB |
Output is correct |
39 |
Correct |
4 ms |
2392 KB |
Output is correct |
40 |
Correct |
5 ms |
2340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
596 KB |
Output is correct |
2 |
Correct |
1 ms |
468 KB |
Output is correct |
3 |
Correct |
1 ms |
596 KB |
Output is correct |
4 |
Correct |
1 ms |
596 KB |
Output is correct |
5 |
Correct |
0 ms |
596 KB |
Output is correct |
6 |
Correct |
1 ms |
596 KB |
Output is correct |
7 |
Correct |
1 ms |
468 KB |
Output is correct |
8 |
Correct |
0 ms |
596 KB |
Output is correct |
9 |
Correct |
1 ms |
468 KB |
Output is correct |
10 |
Correct |
1 ms |
596 KB |
Output is correct |
11 |
Correct |
1 ms |
596 KB |
Output is correct |
12 |
Correct |
1 ms |
596 KB |
Output is correct |
13 |
Correct |
1 ms |
596 KB |
Output is correct |
14 |
Correct |
1 ms |
596 KB |
Output is correct |
15 |
Correct |
0 ms |
468 KB |
Output is correct |
16 |
Correct |
0 ms |
596 KB |
Output is correct |
17 |
Correct |
0 ms |
468 KB |
Output is correct |
18 |
Correct |
1 ms |
468 KB |
Output is correct |
19 |
Correct |
1 ms |
724 KB |
Output is correct |
20 |
Correct |
1 ms |
596 KB |
Output is correct |
21 |
Correct |
5 ms |
2340 KB |
Output is correct |
22 |
Correct |
5 ms |
2388 KB |
Output is correct |
23 |
Correct |
5 ms |
2392 KB |
Output is correct |
24 |
Correct |
1 ms |
1364 KB |
Output is correct |
25 |
Correct |
1 ms |
1364 KB |
Output is correct |
26 |
Correct |
6 ms |
2396 KB |
Output is correct |
27 |
Correct |
5 ms |
2324 KB |
Output is correct |
28 |
Correct |
6 ms |
2348 KB |
Output is correct |
29 |
Correct |
5 ms |
2340 KB |
Output is correct |
30 |
Correct |
5 ms |
2388 KB |
Output is correct |
31 |
Correct |
5 ms |
2412 KB |
Output is correct |
32 |
Correct |
5 ms |
2388 KB |
Output is correct |
33 |
Correct |
4 ms |
2404 KB |
Output is correct |
34 |
Correct |
5 ms |
2388 KB |
Output is correct |
35 |
Correct |
5 ms |
2364 KB |
Output is correct |
36 |
Correct |
4 ms |
2400 KB |
Output is correct |
37 |
Correct |
5 ms |
2396 KB |
Output is correct |
38 |
Correct |
4 ms |
2392 KB |
Output is correct |
39 |
Correct |
4 ms |
2392 KB |
Output is correct |
40 |
Correct |
5 ms |
2340 KB |
Output is correct |
41 |
Correct |
203 ms |
13960 KB |
Output is correct |
42 |
Correct |
204 ms |
13900 KB |
Output is correct |
43 |
Correct |
212 ms |
13912 KB |
Output is correct |
44 |
Correct |
203 ms |
13852 KB |
Output is correct |
45 |
Correct |
202 ms |
13948 KB |
Output is correct |
46 |
Correct |
206 ms |
13960 KB |
Output is correct |
47 |
Correct |
202 ms |
13964 KB |
Output is correct |
48 |
Correct |
214 ms |
13956 KB |
Output is correct |
49 |
Correct |
212 ms |
13952 KB |
Output is correct |
50 |
Correct |
205 ms |
13928 KB |
Output is correct |
51 |
Correct |
204 ms |
13948 KB |
Output is correct |
52 |
Correct |
201 ms |
13960 KB |
Output is correct |
53 |
Correct |
201 ms |
13956 KB |
Output is correct |
54 |
Correct |
204 ms |
13944 KB |
Output is correct |
55 |
Correct |
204 ms |
14040 KB |
Output is correct |
56 |
Correct |
205 ms |
15564 KB |
Output is correct |
57 |
Correct |
205 ms |
16272 KB |
Output is correct |
58 |
Correct |
209 ms |
15896 KB |
Output is correct |
59 |
Correct |
205 ms |
16464 KB |
Output is correct |
60 |
Correct |
203 ms |
15352 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
596 KB |
Output is correct |
2 |
Correct |
1 ms |
468 KB |
Output is correct |
3 |
Correct |
1 ms |
596 KB |
Output is correct |
4 |
Correct |
1 ms |
596 KB |
Output is correct |
5 |
Correct |
0 ms |
596 KB |
Output is correct |
6 |
Correct |
1 ms |
596 KB |
Output is correct |
7 |
Correct |
1 ms |
468 KB |
Output is correct |
8 |
Correct |
0 ms |
596 KB |
Output is correct |
9 |
Correct |
1 ms |
468 KB |
Output is correct |
10 |
Correct |
1 ms |
596 KB |
Output is correct |
11 |
Correct |
1 ms |
596 KB |
Output is correct |
12 |
Correct |
1 ms |
596 KB |
Output is correct |
13 |
Correct |
1 ms |
596 KB |
Output is correct |
14 |
Correct |
1 ms |
596 KB |
Output is correct |
15 |
Correct |
0 ms |
468 KB |
Output is correct |
16 |
Correct |
0 ms |
596 KB |
Output is correct |
17 |
Correct |
0 ms |
468 KB |
Output is correct |
18 |
Correct |
1 ms |
468 KB |
Output is correct |
19 |
Correct |
1 ms |
724 KB |
Output is correct |
20 |
Correct |
1 ms |
596 KB |
Output is correct |
21 |
Correct |
5 ms |
2340 KB |
Output is correct |
22 |
Correct |
5 ms |
2388 KB |
Output is correct |
23 |
Correct |
5 ms |
2392 KB |
Output is correct |
24 |
Correct |
1 ms |
1364 KB |
Output is correct |
25 |
Correct |
1 ms |
1364 KB |
Output is correct |
26 |
Correct |
6 ms |
2396 KB |
Output is correct |
27 |
Correct |
5 ms |
2324 KB |
Output is correct |
28 |
Correct |
6 ms |
2348 KB |
Output is correct |
29 |
Correct |
5 ms |
2340 KB |
Output is correct |
30 |
Correct |
5 ms |
2388 KB |
Output is correct |
31 |
Correct |
5 ms |
2412 KB |
Output is correct |
32 |
Correct |
5 ms |
2388 KB |
Output is correct |
33 |
Correct |
4 ms |
2404 KB |
Output is correct |
34 |
Correct |
5 ms |
2388 KB |
Output is correct |
35 |
Correct |
5 ms |
2364 KB |
Output is correct |
36 |
Correct |
4 ms |
2400 KB |
Output is correct |
37 |
Correct |
5 ms |
2396 KB |
Output is correct |
38 |
Correct |
4 ms |
2392 KB |
Output is correct |
39 |
Correct |
4 ms |
2392 KB |
Output is correct |
40 |
Correct |
5 ms |
2340 KB |
Output is correct |
41 |
Correct |
203 ms |
13960 KB |
Output is correct |
42 |
Correct |
204 ms |
13900 KB |
Output is correct |
43 |
Correct |
212 ms |
13912 KB |
Output is correct |
44 |
Correct |
203 ms |
13852 KB |
Output is correct |
45 |
Correct |
202 ms |
13948 KB |
Output is correct |
46 |
Correct |
206 ms |
13960 KB |
Output is correct |
47 |
Correct |
202 ms |
13964 KB |
Output is correct |
48 |
Correct |
214 ms |
13956 KB |
Output is correct |
49 |
Correct |
212 ms |
13952 KB |
Output is correct |
50 |
Correct |
205 ms |
13928 KB |
Output is correct |
51 |
Correct |
204 ms |
13948 KB |
Output is correct |
52 |
Correct |
201 ms |
13960 KB |
Output is correct |
53 |
Correct |
201 ms |
13956 KB |
Output is correct |
54 |
Correct |
204 ms |
13944 KB |
Output is correct |
55 |
Correct |
204 ms |
14040 KB |
Output is correct |
56 |
Correct |
205 ms |
15564 KB |
Output is correct |
57 |
Correct |
205 ms |
16272 KB |
Output is correct |
58 |
Correct |
209 ms |
15896 KB |
Output is correct |
59 |
Correct |
205 ms |
16464 KB |
Output is correct |
60 |
Correct |
203 ms |
15352 KB |
Output is correct |
61 |
Execution timed out |
1534 ms |
68476 KB |
Time limit exceeded |
62 |
Halted |
0 ms |
0 KB |
- |