#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include<bits/extc++.h>
//__gnu_pbds
const int N = 2050;
int cost[N][N];
ll dp[2][N];
int main(){
ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
int n;cin>>n;
for(int i=0;i<n;i++){
for(int j=0;j<n;j++) cin>>cost[i][j];
}
for(int i=1;i<n;i++){
int b = (i&-i);
for(int x=0;x<=n;x++) dp[i&1][x]=1e18;
for(int x=0;x<n;x++){
int l = x^b;
l&=(~(b-1));
for(int j=l;j<l+b;j++) dp[i&1][x] = min(dp[i&1][x],dp[!(i&1)][j]+cost[x][j]);
}
}
ll minn = 1e18;
for(int i=0;i<n;i++) minn = min(minn,dp[(n-1)&1][i]);
cout<<minn<<"\n";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
468 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 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 |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
468 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 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 |
2652 KB |
Output is correct |
22 |
Correct |
2 ms |
2652 KB |
Output is correct |
23 |
Correct |
2 ms |
2688 KB |
Output is correct |
24 |
Correct |
1 ms |
2396 KB |
Output is correct |
25 |
Correct |
1 ms |
2392 KB |
Output is correct |
26 |
Correct |
2 ms |
2652 KB |
Output is correct |
27 |
Correct |
2 ms |
2652 KB |
Output is correct |
28 |
Correct |
2 ms |
2656 KB |
Output is correct |
29 |
Correct |
2 ms |
2648 KB |
Output is correct |
30 |
Correct |
2 ms |
2652 KB |
Output is correct |
31 |
Correct |
2 ms |
2524 KB |
Output is correct |
32 |
Correct |
2 ms |
2652 KB |
Output is correct |
33 |
Correct |
3 ms |
2648 KB |
Output is correct |
34 |
Correct |
3 ms |
2652 KB |
Output is correct |
35 |
Correct |
2 ms |
2648 KB |
Output is correct |
36 |
Correct |
2 ms |
2648 KB |
Output is correct |
37 |
Correct |
2 ms |
2648 KB |
Output is correct |
38 |
Correct |
2 ms |
2652 KB |
Output is correct |
39 |
Correct |
3 ms |
2672 KB |
Output is correct |
40 |
Correct |
3 ms |
2652 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
468 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 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 |
2652 KB |
Output is correct |
22 |
Correct |
2 ms |
2652 KB |
Output is correct |
23 |
Correct |
2 ms |
2688 KB |
Output is correct |
24 |
Correct |
1 ms |
2396 KB |
Output is correct |
25 |
Correct |
1 ms |
2392 KB |
Output is correct |
26 |
Correct |
2 ms |
2652 KB |
Output is correct |
27 |
Correct |
2 ms |
2652 KB |
Output is correct |
28 |
Correct |
2 ms |
2656 KB |
Output is correct |
29 |
Correct |
2 ms |
2648 KB |
Output is correct |
30 |
Correct |
2 ms |
2652 KB |
Output is correct |
31 |
Correct |
2 ms |
2524 KB |
Output is correct |
32 |
Correct |
2 ms |
2652 KB |
Output is correct |
33 |
Correct |
3 ms |
2648 KB |
Output is correct |
34 |
Correct |
3 ms |
2652 KB |
Output is correct |
35 |
Correct |
2 ms |
2648 KB |
Output is correct |
36 |
Correct |
2 ms |
2648 KB |
Output is correct |
37 |
Correct |
2 ms |
2648 KB |
Output is correct |
38 |
Correct |
2 ms |
2652 KB |
Output is correct |
39 |
Correct |
3 ms |
2672 KB |
Output is correct |
40 |
Correct |
3 ms |
2652 KB |
Output is correct |
41 |
Correct |
22 ms |
7004 KB |
Output is correct |
42 |
Correct |
22 ms |
7004 KB |
Output is correct |
43 |
Correct |
24 ms |
7008 KB |
Output is correct |
44 |
Correct |
22 ms |
7004 KB |
Output is correct |
45 |
Correct |
25 ms |
7004 KB |
Output is correct |
46 |
Correct |
22 ms |
6992 KB |
Output is correct |
47 |
Correct |
27 ms |
6920 KB |
Output is correct |
48 |
Correct |
22 ms |
7004 KB |
Output is correct |
49 |
Correct |
23 ms |
6924 KB |
Output is correct |
50 |
Correct |
23 ms |
6996 KB |
Output is correct |
51 |
Correct |
22 ms |
6996 KB |
Output is correct |
52 |
Correct |
23 ms |
7176 KB |
Output is correct |
53 |
Correct |
21 ms |
7004 KB |
Output is correct |
54 |
Correct |
22 ms |
7056 KB |
Output is correct |
55 |
Correct |
22 ms |
7000 KB |
Output is correct |
56 |
Correct |
23 ms |
6992 KB |
Output is correct |
57 |
Correct |
25 ms |
7260 KB |
Output is correct |
58 |
Correct |
22 ms |
7004 KB |
Output is correct |
59 |
Correct |
29 ms |
7000 KB |
Output is correct |
60 |
Correct |
22 ms |
7004 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
468 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 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 |
2652 KB |
Output is correct |
22 |
Correct |
2 ms |
2652 KB |
Output is correct |
23 |
Correct |
2 ms |
2688 KB |
Output is correct |
24 |
Correct |
1 ms |
2396 KB |
Output is correct |
25 |
Correct |
1 ms |
2392 KB |
Output is correct |
26 |
Correct |
2 ms |
2652 KB |
Output is correct |
27 |
Correct |
2 ms |
2652 KB |
Output is correct |
28 |
Correct |
2 ms |
2656 KB |
Output is correct |
29 |
Correct |
2 ms |
2648 KB |
Output is correct |
30 |
Correct |
2 ms |
2652 KB |
Output is correct |
31 |
Correct |
2 ms |
2524 KB |
Output is correct |
32 |
Correct |
2 ms |
2652 KB |
Output is correct |
33 |
Correct |
3 ms |
2648 KB |
Output is correct |
34 |
Correct |
3 ms |
2652 KB |
Output is correct |
35 |
Correct |
2 ms |
2648 KB |
Output is correct |
36 |
Correct |
2 ms |
2648 KB |
Output is correct |
37 |
Correct |
2 ms |
2648 KB |
Output is correct |
38 |
Correct |
2 ms |
2652 KB |
Output is correct |
39 |
Correct |
3 ms |
2672 KB |
Output is correct |
40 |
Correct |
3 ms |
2652 KB |
Output is correct |
41 |
Correct |
22 ms |
7004 KB |
Output is correct |
42 |
Correct |
22 ms |
7004 KB |
Output is correct |
43 |
Correct |
24 ms |
7008 KB |
Output is correct |
44 |
Correct |
22 ms |
7004 KB |
Output is correct |
45 |
Correct |
25 ms |
7004 KB |
Output is correct |
46 |
Correct |
22 ms |
6992 KB |
Output is correct |
47 |
Correct |
27 ms |
6920 KB |
Output is correct |
48 |
Correct |
22 ms |
7004 KB |
Output is correct |
49 |
Correct |
23 ms |
6924 KB |
Output is correct |
50 |
Correct |
23 ms |
6996 KB |
Output is correct |
51 |
Correct |
22 ms |
6996 KB |
Output is correct |
52 |
Correct |
23 ms |
7176 KB |
Output is correct |
53 |
Correct |
21 ms |
7004 KB |
Output is correct |
54 |
Correct |
22 ms |
7056 KB |
Output is correct |
55 |
Correct |
22 ms |
7000 KB |
Output is correct |
56 |
Correct |
23 ms |
6992 KB |
Output is correct |
57 |
Correct |
25 ms |
7260 KB |
Output is correct |
58 |
Correct |
22 ms |
7004 KB |
Output is correct |
59 |
Correct |
29 ms |
7000 KB |
Output is correct |
60 |
Correct |
22 ms |
7004 KB |
Output is correct |
61 |
Correct |
366 ms |
57460 KB |
Output is correct |
62 |
Correct |
374 ms |
57048 KB |
Output is correct |
63 |
Correct |
388 ms |
57164 KB |
Output is correct |
64 |
Correct |
356 ms |
57156 KB |
Output is correct |
65 |
Correct |
368 ms |
57044 KB |
Output is correct |
66 |
Correct |
360 ms |
57168 KB |
Output is correct |
67 |
Correct |
366 ms |
57172 KB |
Output is correct |
68 |
Correct |
392 ms |
57140 KB |
Output is correct |
69 |
Correct |
368 ms |
57064 KB |
Output is correct |
70 |
Correct |
362 ms |
57292 KB |
Output is correct |
71 |
Correct |
354 ms |
57680 KB |
Output is correct |
72 |
Correct |
365 ms |
57792 KB |
Output is correct |
73 |
Correct |
359 ms |
57844 KB |
Output is correct |
74 |
Correct |
361 ms |
57684 KB |
Output is correct |
75 |
Correct |
377 ms |
57936 KB |
Output is correct |
76 |
Correct |
359 ms |
57792 KB |
Output is correct |
77 |
Correct |
392 ms |
57728 KB |
Output is correct |
78 |
Correct |
366 ms |
57428 KB |
Output is correct |
79 |
Correct |
366 ms |
57668 KB |
Output is correct |
80 |
Correct |
360 ms |
57820 KB |
Output is correct |