#pragma GCC optimize("O3")
//#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.1,sse4.2,popcnt,abm,mmx,avx,avx2,fma")
#include <bits/stdc++.h>
using namespace std;
//#include <atcoder/all>
//using namespace atcoder;
//#include <bits/extc++.h>
//using namespace __gnu_pbds;
#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif
using ll=long long;
using tll=array<ll,3>;
const ll inf=1e18;
const int N=2222;
int n,c[N][N];
ll dp[N][N],opt[N][N];
ll ans=inf;
void solve(int l,int r){
if(l==r){
dp[l][r]=0;
return;
}
if(l+1==r){
dp[l][l]=dp[r][r]=0;
dp[l][r]=dp[r][l]=c[l][r];
return;
}
int m=(l+r)>>1;
solve(l,m);
solve(m+1,r);
int ml=(l+m)/2,mr=(m+1+r)/2;
for(int i=l;i<=m;i++) for(int j1=m+1;j1<=mr;j1++) for(int j2=mr+1;j2<=r;j2++){
opt[i][j1]=min(opt[i][j1],dp[j1][j2]+c[i][j2]);
opt[i][j2]=min(opt[i][j2],dp[j1][j2]+c[i][j1]);
}
for(int i1=l;i1<=ml;i1++) for(int i2=ml+1;i2<=m;i2++) for(int j=m+1;j<=r;j++){
dp[i1][j]=min(dp[i1][j],dp[i1][i2]+opt[i2][j]);
dp[i2][j]=min(dp[i2][j],dp[i1][i2]+opt[i1][j]);
}
for(int i=l;i<=m;i++) for(int j=m+1;j<=r;j++) dp[j][i]=dp[i][j];
}
int main(){
ios::sync_with_stdio(false); cin.tie(0);
cin>>n;
for(int i=0;i<n;i++) for(int j=0;j<n;j++) cin>>c[i][j];
for(int i=0;i<n;i++) for(int j=0;j<n;j++) dp[i][j]=opt[i][j]=inf;
solve(0,n-1);
for(int i=0;i<n/2;i++) for(int j=n/2;j<n;j++) ans=min({ans,dp[i][j],dp[j][i]});
cout<<ans;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
468 KB |
Output is correct |
2 |
Correct |
1 ms |
468 KB |
Output is correct |
3 |
Correct |
0 ms |
468 KB |
Output is correct |
4 |
Correct |
1 ms |
468 KB |
Output is correct |
5 |
Correct |
1 ms |
468 KB |
Output is correct |
6 |
Correct |
1 ms |
468 KB |
Output is correct |
7 |
Correct |
1 ms |
468 KB |
Output is correct |
8 |
Correct |
1 ms |
468 KB |
Output is correct |
9 |
Correct |
0 ms |
468 KB |
Output is correct |
10 |
Correct |
0 ms |
468 KB |
Output is correct |
11 |
Correct |
1 ms |
468 KB |
Output is correct |
12 |
Correct |
0 ms |
468 KB |
Output is correct |
13 |
Correct |
0 ms |
468 KB |
Output is correct |
14 |
Correct |
0 ms |
468 KB |
Output is correct |
15 |
Correct |
0 ms |
468 KB |
Output is correct |
16 |
Correct |
0 ms |
468 KB |
Output is correct |
17 |
Correct |
1 ms |
468 KB |
Output is correct |
18 |
Correct |
0 ms |
468 KB |
Output is correct |
19 |
Correct |
0 ms |
468 KB |
Output is correct |
20 |
Correct |
0 ms |
468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
468 KB |
Output is correct |
2 |
Correct |
1 ms |
468 KB |
Output is correct |
3 |
Correct |
0 ms |
468 KB |
Output is correct |
4 |
Correct |
1 ms |
468 KB |
Output is correct |
5 |
Correct |
1 ms |
468 KB |
Output is correct |
6 |
Correct |
1 ms |
468 KB |
Output is correct |
7 |
Correct |
1 ms |
468 KB |
Output is correct |
8 |
Correct |
1 ms |
468 KB |
Output is correct |
9 |
Correct |
0 ms |
468 KB |
Output is correct |
10 |
Correct |
0 ms |
468 KB |
Output is correct |
11 |
Correct |
1 ms |
468 KB |
Output is correct |
12 |
Correct |
0 ms |
468 KB |
Output is correct |
13 |
Correct |
0 ms |
468 KB |
Output is correct |
14 |
Correct |
0 ms |
468 KB |
Output is correct |
15 |
Correct |
0 ms |
468 KB |
Output is correct |
16 |
Correct |
0 ms |
468 KB |
Output is correct |
17 |
Correct |
1 ms |
468 KB |
Output is correct |
18 |
Correct |
0 ms |
468 KB |
Output is correct |
19 |
Correct |
0 ms |
468 KB |
Output is correct |
20 |
Correct |
0 ms |
468 KB |
Output is correct |
21 |
Correct |
3 ms |
2132 KB |
Output is correct |
22 |
Correct |
2 ms |
2132 KB |
Output is correct |
23 |
Correct |
2 ms |
2132 KB |
Output is correct |
24 |
Correct |
1 ms |
1108 KB |
Output is correct |
25 |
Correct |
1 ms |
1108 KB |
Output is correct |
26 |
Correct |
2 ms |
2132 KB |
Output is correct |
27 |
Correct |
2 ms |
2132 KB |
Output is correct |
28 |
Correct |
2 ms |
2132 KB |
Output is correct |
29 |
Correct |
3 ms |
2132 KB |
Output is correct |
30 |
Correct |
3 ms |
2132 KB |
Output is correct |
31 |
Correct |
3 ms |
2132 KB |
Output is correct |
32 |
Correct |
2 ms |
2132 KB |
Output is correct |
33 |
Correct |
2 ms |
2132 KB |
Output is correct |
34 |
Correct |
2 ms |
2132 KB |
Output is correct |
35 |
Correct |
2 ms |
2132 KB |
Output is correct |
36 |
Correct |
2 ms |
2132 KB |
Output is correct |
37 |
Correct |
3 ms |
2196 KB |
Output is correct |
38 |
Correct |
2 ms |
2132 KB |
Output is correct |
39 |
Correct |
2 ms |
2132 KB |
Output is correct |
40 |
Correct |
2 ms |
2132 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
468 KB |
Output is correct |
2 |
Correct |
1 ms |
468 KB |
Output is correct |
3 |
Correct |
0 ms |
468 KB |
Output is correct |
4 |
Correct |
1 ms |
468 KB |
Output is correct |
5 |
Correct |
1 ms |
468 KB |
Output is correct |
6 |
Correct |
1 ms |
468 KB |
Output is correct |
7 |
Correct |
1 ms |
468 KB |
Output is correct |
8 |
Correct |
1 ms |
468 KB |
Output is correct |
9 |
Correct |
0 ms |
468 KB |
Output is correct |
10 |
Correct |
0 ms |
468 KB |
Output is correct |
11 |
Correct |
1 ms |
468 KB |
Output is correct |
12 |
Correct |
0 ms |
468 KB |
Output is correct |
13 |
Correct |
0 ms |
468 KB |
Output is correct |
14 |
Correct |
0 ms |
468 KB |
Output is correct |
15 |
Correct |
0 ms |
468 KB |
Output is correct |
16 |
Correct |
0 ms |
468 KB |
Output is correct |
17 |
Correct |
1 ms |
468 KB |
Output is correct |
18 |
Correct |
0 ms |
468 KB |
Output is correct |
19 |
Correct |
0 ms |
468 KB |
Output is correct |
20 |
Correct |
0 ms |
468 KB |
Output is correct |
21 |
Correct |
3 ms |
2132 KB |
Output is correct |
22 |
Correct |
2 ms |
2132 KB |
Output is correct |
23 |
Correct |
2 ms |
2132 KB |
Output is correct |
24 |
Correct |
1 ms |
1108 KB |
Output is correct |
25 |
Correct |
1 ms |
1108 KB |
Output is correct |
26 |
Correct |
2 ms |
2132 KB |
Output is correct |
27 |
Correct |
2 ms |
2132 KB |
Output is correct |
28 |
Correct |
2 ms |
2132 KB |
Output is correct |
29 |
Correct |
3 ms |
2132 KB |
Output is correct |
30 |
Correct |
3 ms |
2132 KB |
Output is correct |
31 |
Correct |
3 ms |
2132 KB |
Output is correct |
32 |
Correct |
2 ms |
2132 KB |
Output is correct |
33 |
Correct |
2 ms |
2132 KB |
Output is correct |
34 |
Correct |
2 ms |
2132 KB |
Output is correct |
35 |
Correct |
2 ms |
2132 KB |
Output is correct |
36 |
Correct |
2 ms |
2132 KB |
Output is correct |
37 |
Correct |
3 ms |
2196 KB |
Output is correct |
38 |
Correct |
2 ms |
2132 KB |
Output is correct |
39 |
Correct |
2 ms |
2132 KB |
Output is correct |
40 |
Correct |
2 ms |
2132 KB |
Output is correct |
41 |
Correct |
36 ms |
11604 KB |
Output is correct |
42 |
Correct |
41 ms |
11584 KB |
Output is correct |
43 |
Correct |
36 ms |
11604 KB |
Output is correct |
44 |
Correct |
43 ms |
11604 KB |
Output is correct |
45 |
Correct |
36 ms |
11604 KB |
Output is correct |
46 |
Correct |
37 ms |
11612 KB |
Output is correct |
47 |
Correct |
35 ms |
11584 KB |
Output is correct |
48 |
Correct |
37 ms |
11556 KB |
Output is correct |
49 |
Correct |
36 ms |
11516 KB |
Output is correct |
50 |
Correct |
42 ms |
11504 KB |
Output is correct |
51 |
Correct |
41 ms |
11548 KB |
Output is correct |
52 |
Correct |
41 ms |
11520 KB |
Output is correct |
53 |
Correct |
35 ms |
11576 KB |
Output is correct |
54 |
Correct |
36 ms |
11520 KB |
Output is correct |
55 |
Correct |
37 ms |
11548 KB |
Output is correct |
56 |
Correct |
35 ms |
11604 KB |
Output is correct |
57 |
Correct |
36 ms |
11608 KB |
Output is correct |
58 |
Correct |
35 ms |
11620 KB |
Output is correct |
59 |
Correct |
35 ms |
11608 KB |
Output is correct |
60 |
Correct |
36 ms |
11604 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
468 KB |
Output is correct |
2 |
Correct |
1 ms |
468 KB |
Output is correct |
3 |
Correct |
0 ms |
468 KB |
Output is correct |
4 |
Correct |
1 ms |
468 KB |
Output is correct |
5 |
Correct |
1 ms |
468 KB |
Output is correct |
6 |
Correct |
1 ms |
468 KB |
Output is correct |
7 |
Correct |
1 ms |
468 KB |
Output is correct |
8 |
Correct |
1 ms |
468 KB |
Output is correct |
9 |
Correct |
0 ms |
468 KB |
Output is correct |
10 |
Correct |
0 ms |
468 KB |
Output is correct |
11 |
Correct |
1 ms |
468 KB |
Output is correct |
12 |
Correct |
0 ms |
468 KB |
Output is correct |
13 |
Correct |
0 ms |
468 KB |
Output is correct |
14 |
Correct |
0 ms |
468 KB |
Output is correct |
15 |
Correct |
0 ms |
468 KB |
Output is correct |
16 |
Correct |
0 ms |
468 KB |
Output is correct |
17 |
Correct |
1 ms |
468 KB |
Output is correct |
18 |
Correct |
0 ms |
468 KB |
Output is correct |
19 |
Correct |
0 ms |
468 KB |
Output is correct |
20 |
Correct |
0 ms |
468 KB |
Output is correct |
21 |
Correct |
3 ms |
2132 KB |
Output is correct |
22 |
Correct |
2 ms |
2132 KB |
Output is correct |
23 |
Correct |
2 ms |
2132 KB |
Output is correct |
24 |
Correct |
1 ms |
1108 KB |
Output is correct |
25 |
Correct |
1 ms |
1108 KB |
Output is correct |
26 |
Correct |
2 ms |
2132 KB |
Output is correct |
27 |
Correct |
2 ms |
2132 KB |
Output is correct |
28 |
Correct |
2 ms |
2132 KB |
Output is correct |
29 |
Correct |
3 ms |
2132 KB |
Output is correct |
30 |
Correct |
3 ms |
2132 KB |
Output is correct |
31 |
Correct |
3 ms |
2132 KB |
Output is correct |
32 |
Correct |
2 ms |
2132 KB |
Output is correct |
33 |
Correct |
2 ms |
2132 KB |
Output is correct |
34 |
Correct |
2 ms |
2132 KB |
Output is correct |
35 |
Correct |
2 ms |
2132 KB |
Output is correct |
36 |
Correct |
2 ms |
2132 KB |
Output is correct |
37 |
Correct |
3 ms |
2196 KB |
Output is correct |
38 |
Correct |
2 ms |
2132 KB |
Output is correct |
39 |
Correct |
2 ms |
2132 KB |
Output is correct |
40 |
Correct |
2 ms |
2132 KB |
Output is correct |
41 |
Correct |
36 ms |
11604 KB |
Output is correct |
42 |
Correct |
41 ms |
11584 KB |
Output is correct |
43 |
Correct |
36 ms |
11604 KB |
Output is correct |
44 |
Correct |
43 ms |
11604 KB |
Output is correct |
45 |
Correct |
36 ms |
11604 KB |
Output is correct |
46 |
Correct |
37 ms |
11612 KB |
Output is correct |
47 |
Correct |
35 ms |
11584 KB |
Output is correct |
48 |
Correct |
37 ms |
11556 KB |
Output is correct |
49 |
Correct |
36 ms |
11516 KB |
Output is correct |
50 |
Correct |
42 ms |
11504 KB |
Output is correct |
51 |
Correct |
41 ms |
11548 KB |
Output is correct |
52 |
Correct |
41 ms |
11520 KB |
Output is correct |
53 |
Correct |
35 ms |
11576 KB |
Output is correct |
54 |
Correct |
36 ms |
11520 KB |
Output is correct |
55 |
Correct |
37 ms |
11548 KB |
Output is correct |
56 |
Correct |
35 ms |
11604 KB |
Output is correct |
57 |
Correct |
36 ms |
11608 KB |
Output is correct |
58 |
Correct |
35 ms |
11620 KB |
Output is correct |
59 |
Correct |
35 ms |
11608 KB |
Output is correct |
60 |
Correct |
36 ms |
11604 KB |
Output is correct |
61 |
Correct |
1162 ms |
89264 KB |
Output is correct |
62 |
Correct |
1170 ms |
89380 KB |
Output is correct |
63 |
Correct |
1237 ms |
89384 KB |
Output is correct |
64 |
Correct |
1197 ms |
89388 KB |
Output is correct |
65 |
Correct |
1192 ms |
89384 KB |
Output is correct |
66 |
Correct |
1194 ms |
89384 KB |
Output is correct |
67 |
Correct |
1276 ms |
89408 KB |
Output is correct |
68 |
Correct |
1254 ms |
89384 KB |
Output is correct |
69 |
Correct |
1308 ms |
89388 KB |
Output is correct |
70 |
Correct |
1242 ms |
89384 KB |
Output is correct |
71 |
Correct |
1200 ms |
89384 KB |
Output is correct |
72 |
Correct |
1281 ms |
89380 KB |
Output is correct |
73 |
Correct |
1320 ms |
89384 KB |
Output is correct |
74 |
Correct |
1264 ms |
89384 KB |
Output is correct |
75 |
Correct |
1215 ms |
89388 KB |
Output is correct |
76 |
Correct |
1188 ms |
89384 KB |
Output is correct |
77 |
Correct |
1228 ms |
89388 KB |
Output is correct |
78 |
Correct |
1178 ms |
89384 KB |
Output is correct |
79 |
Correct |
1235 ms |
89384 KB |
Output is correct |
80 |
Correct |
1220 ms |
89384 KB |
Output is correct |