#include<bits/stdc++.h>
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2")
using namespace std;
const long long maxn=2500;
long long dp[maxn][maxn],n,cost[maxn][maxn];
long long inf=1e18;
void vorod(){
cin>>n;
for(long long i=0;i<n;i++){
for(long long j=0;j<n;j++){
cin>>cost[i][j];
}
}
}
void solve(){
for(long long lev=1;lev<n;lev++){
long long pae=(lev&(-lev));
for(long long i=0;i<n;i++){
long long l=(i^pae)&(~(pae-1));
long long r=l+pae;
dp[lev][i]=inf;
for(long long j=l;j<r;j++){
dp[lev][i]=min(dp[lev][i],dp[lev-1][j]+cost[i][j]);
}
}
}
}
void khor(){
long long res=inf;
for(long long i=0;i<n;i++){
res=min(res,dp[n-1][i]);
}
cout<<res<<"\n";
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
vorod();
solve();
khor();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4440 KB |
Output is correct |
2 |
Correct |
1 ms |
4440 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
0 ms |
4444 KB |
Output is correct |
8 |
Correct |
0 ms |
4444 KB |
Output is correct |
9 |
Correct |
0 ms |
4444 KB |
Output is correct |
10 |
Correct |
1 ms |
4444 KB |
Output is correct |
11 |
Correct |
1 ms |
4444 KB |
Output is correct |
12 |
Correct |
1 ms |
4444 KB |
Output is correct |
13 |
Correct |
1 ms |
4696 KB |
Output is correct |
14 |
Correct |
1 ms |
4444 KB |
Output is correct |
15 |
Correct |
1 ms |
4444 KB |
Output is correct |
16 |
Correct |
0 ms |
4444 KB |
Output is correct |
17 |
Correct |
1 ms |
4440 KB |
Output is correct |
18 |
Correct |
1 ms |
4440 KB |
Output is correct |
19 |
Correct |
1 ms |
4444 KB |
Output is correct |
20 |
Correct |
1 ms |
4444 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4440 KB |
Output is correct |
2 |
Correct |
1 ms |
4440 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
0 ms |
4444 KB |
Output is correct |
8 |
Correct |
0 ms |
4444 KB |
Output is correct |
9 |
Correct |
0 ms |
4444 KB |
Output is correct |
10 |
Correct |
1 ms |
4444 KB |
Output is correct |
11 |
Correct |
1 ms |
4444 KB |
Output is correct |
12 |
Correct |
1 ms |
4444 KB |
Output is correct |
13 |
Correct |
1 ms |
4696 KB |
Output is correct |
14 |
Correct |
1 ms |
4444 KB |
Output is correct |
15 |
Correct |
1 ms |
4444 KB |
Output is correct |
16 |
Correct |
0 ms |
4444 KB |
Output is correct |
17 |
Correct |
1 ms |
4440 KB |
Output is correct |
18 |
Correct |
1 ms |
4440 KB |
Output is correct |
19 |
Correct |
1 ms |
4444 KB |
Output is correct |
20 |
Correct |
1 ms |
4444 KB |
Output is correct |
21 |
Correct |
2 ms |
8536 KB |
Output is correct |
22 |
Correct |
2 ms |
8536 KB |
Output is correct |
23 |
Correct |
2 ms |
8540 KB |
Output is correct |
24 |
Correct |
1 ms |
6492 KB |
Output is correct |
25 |
Correct |
1 ms |
6492 KB |
Output is correct |
26 |
Correct |
2 ms |
8540 KB |
Output is correct |
27 |
Correct |
2 ms |
8540 KB |
Output is correct |
28 |
Correct |
2 ms |
8540 KB |
Output is correct |
29 |
Correct |
2 ms |
8536 KB |
Output is correct |
30 |
Correct |
2 ms |
8540 KB |
Output is correct |
31 |
Correct |
3 ms |
8540 KB |
Output is correct |
32 |
Correct |
2 ms |
8540 KB |
Output is correct |
33 |
Correct |
3 ms |
8540 KB |
Output is correct |
34 |
Correct |
2 ms |
8536 KB |
Output is correct |
35 |
Correct |
2 ms |
8540 KB |
Output is correct |
36 |
Correct |
2 ms |
8536 KB |
Output is correct |
37 |
Correct |
2 ms |
8540 KB |
Output is correct |
38 |
Correct |
2 ms |
8536 KB |
Output is correct |
39 |
Correct |
2 ms |
8540 KB |
Output is correct |
40 |
Correct |
3 ms |
8540 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4440 KB |
Output is correct |
2 |
Correct |
1 ms |
4440 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
0 ms |
4444 KB |
Output is correct |
8 |
Correct |
0 ms |
4444 KB |
Output is correct |
9 |
Correct |
0 ms |
4444 KB |
Output is correct |
10 |
Correct |
1 ms |
4444 KB |
Output is correct |
11 |
Correct |
1 ms |
4444 KB |
Output is correct |
12 |
Correct |
1 ms |
4444 KB |
Output is correct |
13 |
Correct |
1 ms |
4696 KB |
Output is correct |
14 |
Correct |
1 ms |
4444 KB |
Output is correct |
15 |
Correct |
1 ms |
4444 KB |
Output is correct |
16 |
Correct |
0 ms |
4444 KB |
Output is correct |
17 |
Correct |
1 ms |
4440 KB |
Output is correct |
18 |
Correct |
1 ms |
4440 KB |
Output is correct |
19 |
Correct |
1 ms |
4444 KB |
Output is correct |
20 |
Correct |
1 ms |
4444 KB |
Output is correct |
21 |
Correct |
2 ms |
8536 KB |
Output is correct |
22 |
Correct |
2 ms |
8536 KB |
Output is correct |
23 |
Correct |
2 ms |
8540 KB |
Output is correct |
24 |
Correct |
1 ms |
6492 KB |
Output is correct |
25 |
Correct |
1 ms |
6492 KB |
Output is correct |
26 |
Correct |
2 ms |
8540 KB |
Output is correct |
27 |
Correct |
2 ms |
8540 KB |
Output is correct |
28 |
Correct |
2 ms |
8540 KB |
Output is correct |
29 |
Correct |
2 ms |
8536 KB |
Output is correct |
30 |
Correct |
2 ms |
8540 KB |
Output is correct |
31 |
Correct |
3 ms |
8540 KB |
Output is correct |
32 |
Correct |
2 ms |
8540 KB |
Output is correct |
33 |
Correct |
3 ms |
8540 KB |
Output is correct |
34 |
Correct |
2 ms |
8536 KB |
Output is correct |
35 |
Correct |
2 ms |
8540 KB |
Output is correct |
36 |
Correct |
2 ms |
8536 KB |
Output is correct |
37 |
Correct |
2 ms |
8540 KB |
Output is correct |
38 |
Correct |
2 ms |
8536 KB |
Output is correct |
39 |
Correct |
2 ms |
8540 KB |
Output is correct |
40 |
Correct |
3 ms |
8540 KB |
Output is correct |
41 |
Correct |
21 ms |
22864 KB |
Output is correct |
42 |
Correct |
21 ms |
23076 KB |
Output is correct |
43 |
Correct |
20 ms |
23088 KB |
Output is correct |
44 |
Correct |
20 ms |
22864 KB |
Output is correct |
45 |
Correct |
20 ms |
22872 KB |
Output is correct |
46 |
Correct |
20 ms |
23120 KB |
Output is correct |
47 |
Correct |
20 ms |
22872 KB |
Output is correct |
48 |
Correct |
20 ms |
22872 KB |
Output is correct |
49 |
Correct |
20 ms |
22872 KB |
Output is correct |
50 |
Correct |
21 ms |
23092 KB |
Output is correct |
51 |
Correct |
20 ms |
22876 KB |
Output is correct |
52 |
Correct |
19 ms |
23080 KB |
Output is correct |
53 |
Correct |
20 ms |
22876 KB |
Output is correct |
54 |
Correct |
20 ms |
22872 KB |
Output is correct |
55 |
Correct |
20 ms |
23080 KB |
Output is correct |
56 |
Correct |
19 ms |
22876 KB |
Output is correct |
57 |
Correct |
20 ms |
22864 KB |
Output is correct |
58 |
Correct |
19 ms |
22876 KB |
Output is correct |
59 |
Correct |
19 ms |
23096 KB |
Output is correct |
60 |
Correct |
20 ms |
22864 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4440 KB |
Output is correct |
2 |
Correct |
1 ms |
4440 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
0 ms |
4444 KB |
Output is correct |
8 |
Correct |
0 ms |
4444 KB |
Output is correct |
9 |
Correct |
0 ms |
4444 KB |
Output is correct |
10 |
Correct |
1 ms |
4444 KB |
Output is correct |
11 |
Correct |
1 ms |
4444 KB |
Output is correct |
12 |
Correct |
1 ms |
4444 KB |
Output is correct |
13 |
Correct |
1 ms |
4696 KB |
Output is correct |
14 |
Correct |
1 ms |
4444 KB |
Output is correct |
15 |
Correct |
1 ms |
4444 KB |
Output is correct |
16 |
Correct |
0 ms |
4444 KB |
Output is correct |
17 |
Correct |
1 ms |
4440 KB |
Output is correct |
18 |
Correct |
1 ms |
4440 KB |
Output is correct |
19 |
Correct |
1 ms |
4444 KB |
Output is correct |
20 |
Correct |
1 ms |
4444 KB |
Output is correct |
21 |
Correct |
2 ms |
8536 KB |
Output is correct |
22 |
Correct |
2 ms |
8536 KB |
Output is correct |
23 |
Correct |
2 ms |
8540 KB |
Output is correct |
24 |
Correct |
1 ms |
6492 KB |
Output is correct |
25 |
Correct |
1 ms |
6492 KB |
Output is correct |
26 |
Correct |
2 ms |
8540 KB |
Output is correct |
27 |
Correct |
2 ms |
8540 KB |
Output is correct |
28 |
Correct |
2 ms |
8540 KB |
Output is correct |
29 |
Correct |
2 ms |
8536 KB |
Output is correct |
30 |
Correct |
2 ms |
8540 KB |
Output is correct |
31 |
Correct |
3 ms |
8540 KB |
Output is correct |
32 |
Correct |
2 ms |
8540 KB |
Output is correct |
33 |
Correct |
3 ms |
8540 KB |
Output is correct |
34 |
Correct |
2 ms |
8536 KB |
Output is correct |
35 |
Correct |
2 ms |
8540 KB |
Output is correct |
36 |
Correct |
2 ms |
8536 KB |
Output is correct |
37 |
Correct |
2 ms |
8540 KB |
Output is correct |
38 |
Correct |
2 ms |
8536 KB |
Output is correct |
39 |
Correct |
2 ms |
8540 KB |
Output is correct |
40 |
Correct |
3 ms |
8540 KB |
Output is correct |
41 |
Correct |
21 ms |
22864 KB |
Output is correct |
42 |
Correct |
21 ms |
23076 KB |
Output is correct |
43 |
Correct |
20 ms |
23088 KB |
Output is correct |
44 |
Correct |
20 ms |
22864 KB |
Output is correct |
45 |
Correct |
20 ms |
22872 KB |
Output is correct |
46 |
Correct |
20 ms |
23120 KB |
Output is correct |
47 |
Correct |
20 ms |
22872 KB |
Output is correct |
48 |
Correct |
20 ms |
22872 KB |
Output is correct |
49 |
Correct |
20 ms |
22872 KB |
Output is correct |
50 |
Correct |
21 ms |
23092 KB |
Output is correct |
51 |
Correct |
20 ms |
22876 KB |
Output is correct |
52 |
Correct |
19 ms |
23080 KB |
Output is correct |
53 |
Correct |
20 ms |
22876 KB |
Output is correct |
54 |
Correct |
20 ms |
22872 KB |
Output is correct |
55 |
Correct |
20 ms |
23080 KB |
Output is correct |
56 |
Correct |
19 ms |
22876 KB |
Output is correct |
57 |
Correct |
20 ms |
22864 KB |
Output is correct |
58 |
Correct |
19 ms |
22876 KB |
Output is correct |
59 |
Correct |
19 ms |
23096 KB |
Output is correct |
60 |
Correct |
20 ms |
22864 KB |
Output is correct |
61 |
Correct |
297 ms |
84564 KB |
Output is correct |
62 |
Correct |
307 ms |
84564 KB |
Output is correct |
63 |
Correct |
297 ms |
84608 KB |
Output is correct |
64 |
Correct |
278 ms |
84700 KB |
Output is correct |
65 |
Correct |
283 ms |
84560 KB |
Output is correct |
66 |
Correct |
291 ms |
84560 KB |
Output is correct |
67 |
Correct |
296 ms |
84560 KB |
Output is correct |
68 |
Correct |
284 ms |
84560 KB |
Output is correct |
69 |
Correct |
296 ms |
84564 KB |
Output is correct |
70 |
Correct |
295 ms |
84608 KB |
Output is correct |
71 |
Correct |
294 ms |
84560 KB |
Output is correct |
72 |
Correct |
295 ms |
84564 KB |
Output is correct |
73 |
Correct |
289 ms |
84620 KB |
Output is correct |
74 |
Correct |
289 ms |
84564 KB |
Output is correct |
75 |
Correct |
290 ms |
84604 KB |
Output is correct |
76 |
Correct |
289 ms |
84560 KB |
Output is correct |
77 |
Correct |
284 ms |
84564 KB |
Output is correct |
78 |
Correct |
280 ms |
84600 KB |
Output is correct |
79 |
Correct |
294 ms |
84560 KB |
Output is correct |
80 |
Correct |
293 ms |
84564 KB |
Output is correct |