#include <bits/stdc++.h>
#define N 2048
#define INF 1000000000000000000LL
using namespace std;
typedef vector<vector<long long>> vvt;
typedef vector<long long> vt;
int n, cost[N][N];
long long abc[N][N], cda[N][N];
vvt DNC(int x, int y) {
if(x == y) {
vvt res = vvt(1,vt(1,0));
return res;
}
int z = (x+y)>>1;
vvt cs1 = DNC(x,z), cs2 = DNC(z+1,y), ans = vvt(y-x+1,vt(y-x+1,INF));
for(int a = 0; a <= z-x; a ++) {
for(int c = 0; c <= z-x; c ++) {
abc[a][c] = INF;
for(int b = 0; b <= z-x; b ++) {
abc[a][c] = min(abc[a][c], cs1[a][b]+cost[b+x][c+z+1]);
}
}
}
for(int c = 0; c <= z-x; c ++) {
for(int a = 0; a <= z-x; a ++) {
cda[c][a] = INF;
for(int d = 0; d <= z-x; d ++) {
cda[c][a] = min(cda[c][a], cs2[c][d]+cost[d+z+1][a+x]);
}
}
}
for(int a = 0; a <= z-x; a ++) {
for(int d = 0; d <= z-x; d ++) {
for(int c = 0; c <= z-x; c ++) {
ans[a][d+(z-x+1)] = min(ans[a][d+(z-x+1)], abc[a][c]+cs2[c][d]);
}
}
}
for(int c = 0; c <= z-x; c ++) {
for(int b = 0; b <= z-x; b ++) {
for(int a = 0; a <= z-x; a ++) {
ans[c+(z-x+1)][b] = min(ans[c+(z-x+1)][b], cda[c][a]+cs1[a][b]);
}
}
}
// cout << "OK!\n";
return ans;
}
int main() {
cin.tie(0)->sync_with_stdio(0);
cin >> n;
for(int i = 0; i < n; i ++) {
for(int j = 0; j < n; j ++) {
cin >> cost[i][j];
}
}
vvt ans = DNC(0,n-1);
long long fin = INF;
for(int i = 0; i < n; i ++) {
fin = min(fin, *min_element(ans[i].begin(),ans[i].end()));
}
cout << fin;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
604 KB |
Output is correct |
2 |
Correct |
0 ms |
604 KB |
Output is correct |
3 |
Correct |
0 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 |
0 ms |
604 KB |
Output is correct |
7 |
Correct |
0 ms |
604 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
0 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 |
604 KB |
Output is correct |
13 |
Correct |
0 ms |
604 KB |
Output is correct |
14 |
Correct |
0 ms |
604 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
604 KB |
Output is correct |
17 |
Correct |
0 ms |
604 KB |
Output is correct |
18 |
Correct |
1 ms |
604 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
604 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
604 KB |
Output is correct |
2 |
Correct |
0 ms |
604 KB |
Output is correct |
3 |
Correct |
0 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 |
0 ms |
604 KB |
Output is correct |
7 |
Correct |
0 ms |
604 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
0 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 |
604 KB |
Output is correct |
13 |
Correct |
0 ms |
604 KB |
Output is correct |
14 |
Correct |
0 ms |
604 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
604 KB |
Output is correct |
17 |
Correct |
0 ms |
604 KB |
Output is correct |
18 |
Correct |
1 ms |
604 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
604 KB |
Output is correct |
21 |
Correct |
4 ms |
1860 KB |
Output is correct |
22 |
Correct |
4 ms |
1628 KB |
Output is correct |
23 |
Correct |
5 ms |
1864 KB |
Output is correct |
24 |
Correct |
1 ms |
860 KB |
Output is correct |
25 |
Correct |
1 ms |
860 KB |
Output is correct |
26 |
Correct |
4 ms |
1756 KB |
Output is correct |
27 |
Correct |
3 ms |
1840 KB |
Output is correct |
28 |
Correct |
4 ms |
1628 KB |
Output is correct |
29 |
Correct |
4 ms |
1628 KB |
Output is correct |
30 |
Correct |
4 ms |
1628 KB |
Output is correct |
31 |
Correct |
4 ms |
1880 KB |
Output is correct |
32 |
Correct |
4 ms |
1628 KB |
Output is correct |
33 |
Correct |
5 ms |
1864 KB |
Output is correct |
34 |
Correct |
4 ms |
1764 KB |
Output is correct |
35 |
Correct |
4 ms |
1628 KB |
Output is correct |
36 |
Correct |
4 ms |
1880 KB |
Output is correct |
37 |
Correct |
4 ms |
1860 KB |
Output is correct |
38 |
Correct |
4 ms |
1628 KB |
Output is correct |
39 |
Correct |
4 ms |
1700 KB |
Output is correct |
40 |
Correct |
4 ms |
1628 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
604 KB |
Output is correct |
2 |
Correct |
0 ms |
604 KB |
Output is correct |
3 |
Correct |
0 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 |
0 ms |
604 KB |
Output is correct |
7 |
Correct |
0 ms |
604 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
0 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 |
604 KB |
Output is correct |
13 |
Correct |
0 ms |
604 KB |
Output is correct |
14 |
Correct |
0 ms |
604 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
604 KB |
Output is correct |
17 |
Correct |
0 ms |
604 KB |
Output is correct |
18 |
Correct |
1 ms |
604 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
604 KB |
Output is correct |
21 |
Correct |
4 ms |
1860 KB |
Output is correct |
22 |
Correct |
4 ms |
1628 KB |
Output is correct |
23 |
Correct |
5 ms |
1864 KB |
Output is correct |
24 |
Correct |
1 ms |
860 KB |
Output is correct |
25 |
Correct |
1 ms |
860 KB |
Output is correct |
26 |
Correct |
4 ms |
1756 KB |
Output is correct |
27 |
Correct |
3 ms |
1840 KB |
Output is correct |
28 |
Correct |
4 ms |
1628 KB |
Output is correct |
29 |
Correct |
4 ms |
1628 KB |
Output is correct |
30 |
Correct |
4 ms |
1628 KB |
Output is correct |
31 |
Correct |
4 ms |
1880 KB |
Output is correct |
32 |
Correct |
4 ms |
1628 KB |
Output is correct |
33 |
Correct |
5 ms |
1864 KB |
Output is correct |
34 |
Correct |
4 ms |
1764 KB |
Output is correct |
35 |
Correct |
4 ms |
1628 KB |
Output is correct |
36 |
Correct |
4 ms |
1880 KB |
Output is correct |
37 |
Correct |
4 ms |
1860 KB |
Output is correct |
38 |
Correct |
4 ms |
1628 KB |
Output is correct |
39 |
Correct |
4 ms |
1700 KB |
Output is correct |
40 |
Correct |
4 ms |
1628 KB |
Output is correct |
41 |
Correct |
160 ms |
10260 KB |
Output is correct |
42 |
Correct |
178 ms |
10320 KB |
Output is correct |
43 |
Correct |
197 ms |
10068 KB |
Output is correct |
44 |
Correct |
174 ms |
10064 KB |
Output is correct |
45 |
Correct |
154 ms |
10068 KB |
Output is correct |
46 |
Correct |
174 ms |
10220 KB |
Output is correct |
47 |
Correct |
165 ms |
10180 KB |
Output is correct |
48 |
Correct |
180 ms |
10064 KB |
Output is correct |
49 |
Correct |
160 ms |
10056 KB |
Output is correct |
50 |
Correct |
165 ms |
10212 KB |
Output is correct |
51 |
Correct |
176 ms |
10320 KB |
Output is correct |
52 |
Correct |
182 ms |
10324 KB |
Output is correct |
53 |
Correct |
181 ms |
10252 KB |
Output is correct |
54 |
Correct |
178 ms |
10264 KB |
Output is correct |
55 |
Correct |
170 ms |
10064 KB |
Output is correct |
56 |
Correct |
167 ms |
10312 KB |
Output is correct |
57 |
Correct |
170 ms |
10320 KB |
Output is correct |
58 |
Correct |
169 ms |
10068 KB |
Output is correct |
59 |
Correct |
174 ms |
10068 KB |
Output is correct |
60 |
Correct |
162 ms |
10064 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
604 KB |
Output is correct |
2 |
Correct |
0 ms |
604 KB |
Output is correct |
3 |
Correct |
0 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 |
0 ms |
604 KB |
Output is correct |
7 |
Correct |
0 ms |
604 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
0 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 |
604 KB |
Output is correct |
13 |
Correct |
0 ms |
604 KB |
Output is correct |
14 |
Correct |
0 ms |
604 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
604 KB |
Output is correct |
17 |
Correct |
0 ms |
604 KB |
Output is correct |
18 |
Correct |
1 ms |
604 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
604 KB |
Output is correct |
21 |
Correct |
4 ms |
1860 KB |
Output is correct |
22 |
Correct |
4 ms |
1628 KB |
Output is correct |
23 |
Correct |
5 ms |
1864 KB |
Output is correct |
24 |
Correct |
1 ms |
860 KB |
Output is correct |
25 |
Correct |
1 ms |
860 KB |
Output is correct |
26 |
Correct |
4 ms |
1756 KB |
Output is correct |
27 |
Correct |
3 ms |
1840 KB |
Output is correct |
28 |
Correct |
4 ms |
1628 KB |
Output is correct |
29 |
Correct |
4 ms |
1628 KB |
Output is correct |
30 |
Correct |
4 ms |
1628 KB |
Output is correct |
31 |
Correct |
4 ms |
1880 KB |
Output is correct |
32 |
Correct |
4 ms |
1628 KB |
Output is correct |
33 |
Correct |
5 ms |
1864 KB |
Output is correct |
34 |
Correct |
4 ms |
1764 KB |
Output is correct |
35 |
Correct |
4 ms |
1628 KB |
Output is correct |
36 |
Correct |
4 ms |
1880 KB |
Output is correct |
37 |
Correct |
4 ms |
1860 KB |
Output is correct |
38 |
Correct |
4 ms |
1628 KB |
Output is correct |
39 |
Correct |
4 ms |
1700 KB |
Output is correct |
40 |
Correct |
4 ms |
1628 KB |
Output is correct |
41 |
Correct |
160 ms |
10260 KB |
Output is correct |
42 |
Correct |
178 ms |
10320 KB |
Output is correct |
43 |
Correct |
197 ms |
10068 KB |
Output is correct |
44 |
Correct |
174 ms |
10064 KB |
Output is correct |
45 |
Correct |
154 ms |
10068 KB |
Output is correct |
46 |
Correct |
174 ms |
10220 KB |
Output is correct |
47 |
Correct |
165 ms |
10180 KB |
Output is correct |
48 |
Correct |
180 ms |
10064 KB |
Output is correct |
49 |
Correct |
160 ms |
10056 KB |
Output is correct |
50 |
Correct |
165 ms |
10212 KB |
Output is correct |
51 |
Correct |
176 ms |
10320 KB |
Output is correct |
52 |
Correct |
182 ms |
10324 KB |
Output is correct |
53 |
Correct |
181 ms |
10252 KB |
Output is correct |
54 |
Correct |
178 ms |
10264 KB |
Output is correct |
55 |
Correct |
170 ms |
10064 KB |
Output is correct |
56 |
Correct |
167 ms |
10312 KB |
Output is correct |
57 |
Correct |
170 ms |
10320 KB |
Output is correct |
58 |
Correct |
169 ms |
10068 KB |
Output is correct |
59 |
Correct |
174 ms |
10068 KB |
Output is correct |
60 |
Correct |
162 ms |
10064 KB |
Output is correct |
61 |
Execution timed out |
1509 ms |
77996 KB |
Time limit exceeded |
62 |
Halted |
0 ms |
0 KB |
- |