#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx,popcnt,sse4,abm")
#include <bits/stdc++.h>
using namespace std;
#ifdef WAIMAI
#define debug(HEHE...) cout << "[" << #HEHE << "] : ", dout(HEHE)
void dout() {cout << '\n';}
template<typename T, typename...U>
void dout(T t, U...u) {cout << t << (sizeof...(u) ? ", " : ""), dout(u...);}
#else
#define debug(...) 7122
#endif
#define ll long long
#define Waimai ios::sync_with_stdio(false), cin.tie(0)
#define FOR(x,a,b) for (int x = a, I = b; x <= I; x++)
#define pb emplace_back
#define F first
#define S second
const ll INF = 1e18;
const int SIZE = 2100;
int n;
int a[SIZE][SIZE];
ll dp[2][SIZE];
void solve() {
cin >> n;
FOR (i, 0, n - 1) FOR (j, 0, n - 1) cin >> a[i][j];
FOR (i, 1, n - 1) {
int f = (i + 1) & 1, b = i & -i;
fill(dp[f], dp[f] + n, INF);
FOR (j, 0, n - 1) {
int s = (j ^ b) & (~(b - 1));
FOR (k, s, s + b - 1) dp[f][k] = min(dp[f][k], dp[!f][j] + a[j][k]);
}
}
cout << *min_element(dp[n & 1], dp[n & 1] + n) << '\n';
}
int main() {
Waimai;
solve();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
600 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
464 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
1 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 |
1 ms |
460 KB |
Output is correct |
18 |
Correct |
0 ms |
344 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 |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
600 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
464 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
1 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 |
1 ms |
460 KB |
Output is correct |
18 |
Correct |
0 ms |
344 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
3 ms |
2648 KB |
Output is correct |
22 |
Correct |
3 ms |
2652 KB |
Output is correct |
23 |
Correct |
2 ms |
2652 KB |
Output is correct |
24 |
Correct |
1 ms |
2396 KB |
Output is correct |
25 |
Correct |
2 ms |
2392 KB |
Output is correct |
26 |
Correct |
2 ms |
2652 KB |
Output is correct |
27 |
Correct |
3 ms |
2652 KB |
Output is correct |
28 |
Correct |
2 ms |
2652 KB |
Output is correct |
29 |
Correct |
2 ms |
2688 KB |
Output is correct |
30 |
Correct |
2 ms |
2648 KB |
Output is correct |
31 |
Correct |
2 ms |
2652 KB |
Output is correct |
32 |
Correct |
3 ms |
2520 KB |
Output is correct |
33 |
Correct |
2 ms |
2652 KB |
Output is correct |
34 |
Correct |
2 ms |
2652 KB |
Output is correct |
35 |
Correct |
2 ms |
2760 KB |
Output is correct |
36 |
Correct |
2 ms |
2648 KB |
Output is correct |
37 |
Correct |
2 ms |
2652 KB |
Output is correct |
38 |
Correct |
2 ms |
2652 KB |
Output is correct |
39 |
Correct |
2 ms |
2652 KB |
Output is correct |
40 |
Correct |
2 ms |
2652 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
600 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
464 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
1 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 |
1 ms |
460 KB |
Output is correct |
18 |
Correct |
0 ms |
344 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
3 ms |
2648 KB |
Output is correct |
22 |
Correct |
3 ms |
2652 KB |
Output is correct |
23 |
Correct |
2 ms |
2652 KB |
Output is correct |
24 |
Correct |
1 ms |
2396 KB |
Output is correct |
25 |
Correct |
2 ms |
2392 KB |
Output is correct |
26 |
Correct |
2 ms |
2652 KB |
Output is correct |
27 |
Correct |
3 ms |
2652 KB |
Output is correct |
28 |
Correct |
2 ms |
2652 KB |
Output is correct |
29 |
Correct |
2 ms |
2688 KB |
Output is correct |
30 |
Correct |
2 ms |
2648 KB |
Output is correct |
31 |
Correct |
2 ms |
2652 KB |
Output is correct |
32 |
Correct |
3 ms |
2520 KB |
Output is correct |
33 |
Correct |
2 ms |
2652 KB |
Output is correct |
34 |
Correct |
2 ms |
2652 KB |
Output is correct |
35 |
Correct |
2 ms |
2760 KB |
Output is correct |
36 |
Correct |
2 ms |
2648 KB |
Output is correct |
37 |
Correct |
2 ms |
2652 KB |
Output is correct |
38 |
Correct |
2 ms |
2652 KB |
Output is correct |
39 |
Correct |
2 ms |
2652 KB |
Output is correct |
40 |
Correct |
2 ms |
2652 KB |
Output is correct |
41 |
Correct |
23 ms |
6992 KB |
Output is correct |
42 |
Correct |
27 ms |
6996 KB |
Output is correct |
43 |
Correct |
24 ms |
7000 KB |
Output is correct |
44 |
Correct |
24 ms |
7084 KB |
Output is correct |
45 |
Correct |
25 ms |
6996 KB |
Output is correct |
46 |
Correct |
22 ms |
7004 KB |
Output is correct |
47 |
Correct |
22 ms |
6996 KB |
Output is correct |
48 |
Correct |
28 ms |
7000 KB |
Output is correct |
49 |
Correct |
25 ms |
7004 KB |
Output is correct |
50 |
Correct |
23 ms |
7004 KB |
Output is correct |
51 |
Correct |
22 ms |
7004 KB |
Output is correct |
52 |
Correct |
22 ms |
7092 KB |
Output is correct |
53 |
Correct |
22 ms |
7004 KB |
Output is correct |
54 |
Correct |
23 ms |
7004 KB |
Output is correct |
55 |
Correct |
22 ms |
7004 KB |
Output is correct |
56 |
Correct |
23 ms |
7080 KB |
Output is correct |
57 |
Correct |
22 ms |
7212 KB |
Output is correct |
58 |
Correct |
23 ms |
7256 KB |
Output is correct |
59 |
Correct |
22 ms |
7088 KB |
Output is correct |
60 |
Correct |
22 ms |
7000 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
600 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
464 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
1 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 |
1 ms |
460 KB |
Output is correct |
18 |
Correct |
0 ms |
344 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
3 ms |
2648 KB |
Output is correct |
22 |
Correct |
3 ms |
2652 KB |
Output is correct |
23 |
Correct |
2 ms |
2652 KB |
Output is correct |
24 |
Correct |
1 ms |
2396 KB |
Output is correct |
25 |
Correct |
2 ms |
2392 KB |
Output is correct |
26 |
Correct |
2 ms |
2652 KB |
Output is correct |
27 |
Correct |
3 ms |
2652 KB |
Output is correct |
28 |
Correct |
2 ms |
2652 KB |
Output is correct |
29 |
Correct |
2 ms |
2688 KB |
Output is correct |
30 |
Correct |
2 ms |
2648 KB |
Output is correct |
31 |
Correct |
2 ms |
2652 KB |
Output is correct |
32 |
Correct |
3 ms |
2520 KB |
Output is correct |
33 |
Correct |
2 ms |
2652 KB |
Output is correct |
34 |
Correct |
2 ms |
2652 KB |
Output is correct |
35 |
Correct |
2 ms |
2760 KB |
Output is correct |
36 |
Correct |
2 ms |
2648 KB |
Output is correct |
37 |
Correct |
2 ms |
2652 KB |
Output is correct |
38 |
Correct |
2 ms |
2652 KB |
Output is correct |
39 |
Correct |
2 ms |
2652 KB |
Output is correct |
40 |
Correct |
2 ms |
2652 KB |
Output is correct |
41 |
Correct |
23 ms |
6992 KB |
Output is correct |
42 |
Correct |
27 ms |
6996 KB |
Output is correct |
43 |
Correct |
24 ms |
7000 KB |
Output is correct |
44 |
Correct |
24 ms |
7084 KB |
Output is correct |
45 |
Correct |
25 ms |
6996 KB |
Output is correct |
46 |
Correct |
22 ms |
7004 KB |
Output is correct |
47 |
Correct |
22 ms |
6996 KB |
Output is correct |
48 |
Correct |
28 ms |
7000 KB |
Output is correct |
49 |
Correct |
25 ms |
7004 KB |
Output is correct |
50 |
Correct |
23 ms |
7004 KB |
Output is correct |
51 |
Correct |
22 ms |
7004 KB |
Output is correct |
52 |
Correct |
22 ms |
7092 KB |
Output is correct |
53 |
Correct |
22 ms |
7004 KB |
Output is correct |
54 |
Correct |
23 ms |
7004 KB |
Output is correct |
55 |
Correct |
22 ms |
7004 KB |
Output is correct |
56 |
Correct |
23 ms |
7080 KB |
Output is correct |
57 |
Correct |
22 ms |
7212 KB |
Output is correct |
58 |
Correct |
23 ms |
7256 KB |
Output is correct |
59 |
Correct |
22 ms |
7088 KB |
Output is correct |
60 |
Correct |
22 ms |
7000 KB |
Output is correct |
61 |
Correct |
363 ms |
57324 KB |
Output is correct |
62 |
Correct |
371 ms |
57692 KB |
Output is correct |
63 |
Correct |
361 ms |
57680 KB |
Output is correct |
64 |
Correct |
381 ms |
57732 KB |
Output is correct |
65 |
Correct |
388 ms |
57740 KB |
Output is correct |
66 |
Correct |
376 ms |
57700 KB |
Output is correct |
67 |
Correct |
376 ms |
57452 KB |
Output is correct |
68 |
Correct |
367 ms |
57676 KB |
Output is correct |
69 |
Correct |
376 ms |
57956 KB |
Output is correct |
70 |
Correct |
353 ms |
57556 KB |
Output is correct |
71 |
Correct |
353 ms |
58456 KB |
Output is correct |
72 |
Correct |
345 ms |
58468 KB |
Output is correct |
73 |
Correct |
371 ms |
58460 KB |
Output is correct |
74 |
Correct |
359 ms |
57844 KB |
Output is correct |
75 |
Correct |
358 ms |
58204 KB |
Output is correct |
76 |
Correct |
364 ms |
58444 KB |
Output is correct |
77 |
Correct |
349 ms |
58196 KB |
Output is correct |
78 |
Correct |
356 ms |
58252 KB |
Output is correct |
79 |
Correct |
360 ms |
58280 KB |
Output is correct |
80 |
Correct |
403 ms |
58400 KB |
Output is correct |