#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pl;
typedef pair<int,int> pii;
typedef tuple<int,int,int> tt;
#define all(a) a.begin(), a.end()
#define filter(a) a.erase(unique(all(a)), a.end())
ll cost[2048][2048], dp[2048][2048];
int trim (int mask, int pos) {
return ((mask >> pos) << pos);
}
int main()
{
ios::sync_with_stdio(0);
cin.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++) {
for (int last = 0; last < n; last++) {
int cand = i & (-i), pos = 31 - __builtin_clz(cand), mask = trim(last, pos) ^ cand;
dp[i][last] = LLONG_MAX;
for (int preLast = mask; preLast < mask + cand; preLast++)
dp[i][last] = min(dp[i][last], dp[i - 1][preLast] + cost[preLast][last]);
}
}
ll ans = LLONG_MAX;
for (int i = 0; i < n; i++) ans = min(ans, dp[n - 1][i]);
cout << ans;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
6480 KB |
Output is correct |
2 |
Correct |
1 ms |
6480 KB |
Output is correct |
3 |
Correct |
1 ms |
6480 KB |
Output is correct |
4 |
Correct |
2 ms |
6480 KB |
Output is correct |
5 |
Correct |
1 ms |
6480 KB |
Output is correct |
6 |
Correct |
1 ms |
6480 KB |
Output is correct |
7 |
Correct |
1 ms |
6612 KB |
Output is correct |
8 |
Correct |
2 ms |
6480 KB |
Output is correct |
9 |
Correct |
1 ms |
6480 KB |
Output is correct |
10 |
Correct |
1 ms |
6736 KB |
Output is correct |
11 |
Correct |
1 ms |
6480 KB |
Output is correct |
12 |
Correct |
1 ms |
6612 KB |
Output is correct |
13 |
Correct |
1 ms |
6480 KB |
Output is correct |
14 |
Correct |
1 ms |
6480 KB |
Output is correct |
15 |
Correct |
1 ms |
6480 KB |
Output is correct |
16 |
Correct |
1 ms |
6480 KB |
Output is correct |
17 |
Correct |
1 ms |
6648 KB |
Output is correct |
18 |
Correct |
2 ms |
6480 KB |
Output is correct |
19 |
Correct |
1 ms |
6480 KB |
Output is correct |
20 |
Correct |
2 ms |
6480 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
6480 KB |
Output is correct |
2 |
Correct |
1 ms |
6480 KB |
Output is correct |
3 |
Correct |
1 ms |
6480 KB |
Output is correct |
4 |
Correct |
2 ms |
6480 KB |
Output is correct |
5 |
Correct |
1 ms |
6480 KB |
Output is correct |
6 |
Correct |
1 ms |
6480 KB |
Output is correct |
7 |
Correct |
1 ms |
6612 KB |
Output is correct |
8 |
Correct |
2 ms |
6480 KB |
Output is correct |
9 |
Correct |
1 ms |
6480 KB |
Output is correct |
10 |
Correct |
1 ms |
6736 KB |
Output is correct |
11 |
Correct |
1 ms |
6480 KB |
Output is correct |
12 |
Correct |
1 ms |
6612 KB |
Output is correct |
13 |
Correct |
1 ms |
6480 KB |
Output is correct |
14 |
Correct |
1 ms |
6480 KB |
Output is correct |
15 |
Correct |
1 ms |
6480 KB |
Output is correct |
16 |
Correct |
1 ms |
6480 KB |
Output is correct |
17 |
Correct |
1 ms |
6648 KB |
Output is correct |
18 |
Correct |
2 ms |
6480 KB |
Output is correct |
19 |
Correct |
1 ms |
6480 KB |
Output is correct |
20 |
Correct |
2 ms |
6480 KB |
Output is correct |
21 |
Correct |
3 ms |
6728 KB |
Output is correct |
22 |
Correct |
3 ms |
6736 KB |
Output is correct |
23 |
Correct |
3 ms |
6752 KB |
Output is correct |
24 |
Correct |
1 ms |
6480 KB |
Output is correct |
25 |
Correct |
2 ms |
6480 KB |
Output is correct |
26 |
Correct |
3 ms |
6732 KB |
Output is correct |
27 |
Correct |
4 ms |
6844 KB |
Output is correct |
28 |
Correct |
3 ms |
6748 KB |
Output is correct |
29 |
Correct |
3 ms |
6736 KB |
Output is correct |
30 |
Correct |
3 ms |
6736 KB |
Output is correct |
31 |
Correct |
3 ms |
6736 KB |
Output is correct |
32 |
Correct |
3 ms |
6736 KB |
Output is correct |
33 |
Correct |
4 ms |
6736 KB |
Output is correct |
34 |
Correct |
3 ms |
6900 KB |
Output is correct |
35 |
Correct |
3 ms |
6736 KB |
Output is correct |
36 |
Correct |
3 ms |
6736 KB |
Output is correct |
37 |
Correct |
4 ms |
6736 KB |
Output is correct |
38 |
Correct |
3 ms |
6736 KB |
Output is correct |
39 |
Correct |
3 ms |
6736 KB |
Output is correct |
40 |
Correct |
3 ms |
6736 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
6480 KB |
Output is correct |
2 |
Correct |
1 ms |
6480 KB |
Output is correct |
3 |
Correct |
1 ms |
6480 KB |
Output is correct |
4 |
Correct |
2 ms |
6480 KB |
Output is correct |
5 |
Correct |
1 ms |
6480 KB |
Output is correct |
6 |
Correct |
1 ms |
6480 KB |
Output is correct |
7 |
Correct |
1 ms |
6612 KB |
Output is correct |
8 |
Correct |
2 ms |
6480 KB |
Output is correct |
9 |
Correct |
1 ms |
6480 KB |
Output is correct |
10 |
Correct |
1 ms |
6736 KB |
Output is correct |
11 |
Correct |
1 ms |
6480 KB |
Output is correct |
12 |
Correct |
1 ms |
6612 KB |
Output is correct |
13 |
Correct |
1 ms |
6480 KB |
Output is correct |
14 |
Correct |
1 ms |
6480 KB |
Output is correct |
15 |
Correct |
1 ms |
6480 KB |
Output is correct |
16 |
Correct |
1 ms |
6480 KB |
Output is correct |
17 |
Correct |
1 ms |
6648 KB |
Output is correct |
18 |
Correct |
2 ms |
6480 KB |
Output is correct |
19 |
Correct |
1 ms |
6480 KB |
Output is correct |
20 |
Correct |
2 ms |
6480 KB |
Output is correct |
21 |
Correct |
3 ms |
6728 KB |
Output is correct |
22 |
Correct |
3 ms |
6736 KB |
Output is correct |
23 |
Correct |
3 ms |
6752 KB |
Output is correct |
24 |
Correct |
1 ms |
6480 KB |
Output is correct |
25 |
Correct |
2 ms |
6480 KB |
Output is correct |
26 |
Correct |
3 ms |
6732 KB |
Output is correct |
27 |
Correct |
4 ms |
6844 KB |
Output is correct |
28 |
Correct |
3 ms |
6748 KB |
Output is correct |
29 |
Correct |
3 ms |
6736 KB |
Output is correct |
30 |
Correct |
3 ms |
6736 KB |
Output is correct |
31 |
Correct |
3 ms |
6736 KB |
Output is correct |
32 |
Correct |
3 ms |
6736 KB |
Output is correct |
33 |
Correct |
4 ms |
6736 KB |
Output is correct |
34 |
Correct |
3 ms |
6900 KB |
Output is correct |
35 |
Correct |
3 ms |
6736 KB |
Output is correct |
36 |
Correct |
3 ms |
6736 KB |
Output is correct |
37 |
Correct |
4 ms |
6736 KB |
Output is correct |
38 |
Correct |
3 ms |
6736 KB |
Output is correct |
39 |
Correct |
3 ms |
6736 KB |
Output is correct |
40 |
Correct |
3 ms |
6736 KB |
Output is correct |
41 |
Correct |
32 ms |
21320 KB |
Output is correct |
42 |
Correct |
31 ms |
21524 KB |
Output is correct |
43 |
Correct |
29 ms |
21320 KB |
Output is correct |
44 |
Correct |
30 ms |
21320 KB |
Output is correct |
45 |
Correct |
34 ms |
21320 KB |
Output is correct |
46 |
Correct |
31 ms |
21424 KB |
Output is correct |
47 |
Correct |
32 ms |
21328 KB |
Output is correct |
48 |
Correct |
30 ms |
21540 KB |
Output is correct |
49 |
Correct |
30 ms |
21328 KB |
Output is correct |
50 |
Correct |
30 ms |
21328 KB |
Output is correct |
51 |
Correct |
32 ms |
21336 KB |
Output is correct |
52 |
Correct |
36 ms |
21320 KB |
Output is correct |
53 |
Correct |
31 ms |
21576 KB |
Output is correct |
54 |
Correct |
28 ms |
21576 KB |
Output is correct |
55 |
Correct |
30 ms |
21584 KB |
Output is correct |
56 |
Correct |
28 ms |
21576 KB |
Output is correct |
57 |
Correct |
28 ms |
21592 KB |
Output is correct |
58 |
Correct |
28 ms |
21584 KB |
Output is correct |
59 |
Correct |
28 ms |
21584 KB |
Output is correct |
60 |
Correct |
28 ms |
21564 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
6480 KB |
Output is correct |
2 |
Correct |
1 ms |
6480 KB |
Output is correct |
3 |
Correct |
1 ms |
6480 KB |
Output is correct |
4 |
Correct |
2 ms |
6480 KB |
Output is correct |
5 |
Correct |
1 ms |
6480 KB |
Output is correct |
6 |
Correct |
1 ms |
6480 KB |
Output is correct |
7 |
Correct |
1 ms |
6612 KB |
Output is correct |
8 |
Correct |
2 ms |
6480 KB |
Output is correct |
9 |
Correct |
1 ms |
6480 KB |
Output is correct |
10 |
Correct |
1 ms |
6736 KB |
Output is correct |
11 |
Correct |
1 ms |
6480 KB |
Output is correct |
12 |
Correct |
1 ms |
6612 KB |
Output is correct |
13 |
Correct |
1 ms |
6480 KB |
Output is correct |
14 |
Correct |
1 ms |
6480 KB |
Output is correct |
15 |
Correct |
1 ms |
6480 KB |
Output is correct |
16 |
Correct |
1 ms |
6480 KB |
Output is correct |
17 |
Correct |
1 ms |
6648 KB |
Output is correct |
18 |
Correct |
2 ms |
6480 KB |
Output is correct |
19 |
Correct |
1 ms |
6480 KB |
Output is correct |
20 |
Correct |
2 ms |
6480 KB |
Output is correct |
21 |
Correct |
3 ms |
6728 KB |
Output is correct |
22 |
Correct |
3 ms |
6736 KB |
Output is correct |
23 |
Correct |
3 ms |
6752 KB |
Output is correct |
24 |
Correct |
1 ms |
6480 KB |
Output is correct |
25 |
Correct |
2 ms |
6480 KB |
Output is correct |
26 |
Correct |
3 ms |
6732 KB |
Output is correct |
27 |
Correct |
4 ms |
6844 KB |
Output is correct |
28 |
Correct |
3 ms |
6748 KB |
Output is correct |
29 |
Correct |
3 ms |
6736 KB |
Output is correct |
30 |
Correct |
3 ms |
6736 KB |
Output is correct |
31 |
Correct |
3 ms |
6736 KB |
Output is correct |
32 |
Correct |
3 ms |
6736 KB |
Output is correct |
33 |
Correct |
4 ms |
6736 KB |
Output is correct |
34 |
Correct |
3 ms |
6900 KB |
Output is correct |
35 |
Correct |
3 ms |
6736 KB |
Output is correct |
36 |
Correct |
3 ms |
6736 KB |
Output is correct |
37 |
Correct |
4 ms |
6736 KB |
Output is correct |
38 |
Correct |
3 ms |
6736 KB |
Output is correct |
39 |
Correct |
3 ms |
6736 KB |
Output is correct |
40 |
Correct |
3 ms |
6736 KB |
Output is correct |
41 |
Correct |
32 ms |
21320 KB |
Output is correct |
42 |
Correct |
31 ms |
21524 KB |
Output is correct |
43 |
Correct |
29 ms |
21320 KB |
Output is correct |
44 |
Correct |
30 ms |
21320 KB |
Output is correct |
45 |
Correct |
34 ms |
21320 KB |
Output is correct |
46 |
Correct |
31 ms |
21424 KB |
Output is correct |
47 |
Correct |
32 ms |
21328 KB |
Output is correct |
48 |
Correct |
30 ms |
21540 KB |
Output is correct |
49 |
Correct |
30 ms |
21328 KB |
Output is correct |
50 |
Correct |
30 ms |
21328 KB |
Output is correct |
51 |
Correct |
32 ms |
21336 KB |
Output is correct |
52 |
Correct |
36 ms |
21320 KB |
Output is correct |
53 |
Correct |
31 ms |
21576 KB |
Output is correct |
54 |
Correct |
28 ms |
21576 KB |
Output is correct |
55 |
Correct |
30 ms |
21584 KB |
Output is correct |
56 |
Correct |
28 ms |
21576 KB |
Output is correct |
57 |
Correct |
28 ms |
21592 KB |
Output is correct |
58 |
Correct |
28 ms |
21584 KB |
Output is correct |
59 |
Correct |
28 ms |
21584 KB |
Output is correct |
60 |
Correct |
28 ms |
21564 KB |
Output is correct |
61 |
Correct |
525 ms |
106312 KB |
Output is correct |
62 |
Correct |
542 ms |
106312 KB |
Output is correct |
63 |
Correct |
569 ms |
106312 KB |
Output is correct |
64 |
Correct |
448 ms |
106312 KB |
Output is correct |
65 |
Correct |
510 ms |
106312 KB |
Output is correct |
66 |
Correct |
559 ms |
106276 KB |
Output is correct |
67 |
Correct |
531 ms |
106472 KB |
Output is correct |
68 |
Correct |
515 ms |
106344 KB |
Output is correct |
69 |
Correct |
488 ms |
106444 KB |
Output is correct |
70 |
Correct |
493 ms |
106312 KB |
Output is correct |
71 |
Correct |
511 ms |
107100 KB |
Output is correct |
72 |
Correct |
468 ms |
107108 KB |
Output is correct |
73 |
Correct |
478 ms |
107080 KB |
Output is correct |
74 |
Correct |
478 ms |
107088 KB |
Output is correct |
75 |
Correct |
478 ms |
107080 KB |
Output is correct |
76 |
Correct |
444 ms |
107124 KB |
Output is correct |
77 |
Correct |
498 ms |
107080 KB |
Output is correct |
78 |
Correct |
516 ms |
107104 KB |
Output is correct |
79 |
Correct |
482 ms |
106972 KB |
Output is correct |
80 |
Correct |
508 ms |
107092 KB |
Output is correct |