#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[2][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++) {
int t = i & 1;
for (int last = 0; last < n; last++) {
int cand = i & (-i), pos = 31 - __builtin_clz(cand), mask = trim(last, pos) ^ cand;
dp[t][last] = LLONG_MAX;
for (int preLast = mask; preLast < mask + cand; preLast++)
dp[t][last] = min(dp[t][last], dp[t ^ 1][preLast] + cost[last][preLast]);
}
}
ll ans = LLONG_MAX;
for (int i = 0; i < n; i++) ans = min(ans, dp[(n - 1) & 1][i]);
cout << ans;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2384 KB |
Output is correct |
2 |
Correct |
1 ms |
2384 KB |
Output is correct |
3 |
Correct |
1 ms |
2384 KB |
Output is correct |
4 |
Correct |
1 ms |
2384 KB |
Output is correct |
5 |
Correct |
1 ms |
2384 KB |
Output is correct |
6 |
Correct |
1 ms |
2384 KB |
Output is correct |
7 |
Correct |
1 ms |
2384 KB |
Output is correct |
8 |
Correct |
1 ms |
2384 KB |
Output is correct |
9 |
Correct |
1 ms |
2384 KB |
Output is correct |
10 |
Correct |
1 ms |
2384 KB |
Output is correct |
11 |
Correct |
1 ms |
2384 KB |
Output is correct |
12 |
Correct |
1 ms |
2384 KB |
Output is correct |
13 |
Correct |
1 ms |
2384 KB |
Output is correct |
14 |
Correct |
1 ms |
2384 KB |
Output is correct |
15 |
Correct |
1 ms |
2384 KB |
Output is correct |
16 |
Correct |
1 ms |
2384 KB |
Output is correct |
17 |
Correct |
1 ms |
2384 KB |
Output is correct |
18 |
Correct |
1 ms |
2384 KB |
Output is correct |
19 |
Correct |
1 ms |
2396 KB |
Output is correct |
20 |
Correct |
1 ms |
2384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2384 KB |
Output is correct |
2 |
Correct |
1 ms |
2384 KB |
Output is correct |
3 |
Correct |
1 ms |
2384 KB |
Output is correct |
4 |
Correct |
1 ms |
2384 KB |
Output is correct |
5 |
Correct |
1 ms |
2384 KB |
Output is correct |
6 |
Correct |
1 ms |
2384 KB |
Output is correct |
7 |
Correct |
1 ms |
2384 KB |
Output is correct |
8 |
Correct |
1 ms |
2384 KB |
Output is correct |
9 |
Correct |
1 ms |
2384 KB |
Output is correct |
10 |
Correct |
1 ms |
2384 KB |
Output is correct |
11 |
Correct |
1 ms |
2384 KB |
Output is correct |
12 |
Correct |
1 ms |
2384 KB |
Output is correct |
13 |
Correct |
1 ms |
2384 KB |
Output is correct |
14 |
Correct |
1 ms |
2384 KB |
Output is correct |
15 |
Correct |
1 ms |
2384 KB |
Output is correct |
16 |
Correct |
1 ms |
2384 KB |
Output is correct |
17 |
Correct |
1 ms |
2384 KB |
Output is correct |
18 |
Correct |
1 ms |
2384 KB |
Output is correct |
19 |
Correct |
1 ms |
2396 KB |
Output is correct |
20 |
Correct |
1 ms |
2384 KB |
Output is correct |
21 |
Correct |
2 ms |
2384 KB |
Output is correct |
22 |
Correct |
2 ms |
2384 KB |
Output is correct |
23 |
Correct |
2 ms |
2384 KB |
Output is correct |
24 |
Correct |
1 ms |
2384 KB |
Output is correct |
25 |
Correct |
1 ms |
2384 KB |
Output is correct |
26 |
Correct |
2 ms |
2384 KB |
Output is correct |
27 |
Correct |
2 ms |
2384 KB |
Output is correct |
28 |
Correct |
2 ms |
2384 KB |
Output is correct |
29 |
Correct |
2 ms |
2384 KB |
Output is correct |
30 |
Correct |
2 ms |
2552 KB |
Output is correct |
31 |
Correct |
2 ms |
2384 KB |
Output is correct |
32 |
Correct |
2 ms |
2384 KB |
Output is correct |
33 |
Correct |
3 ms |
2384 KB |
Output is correct |
34 |
Correct |
2 ms |
2384 KB |
Output is correct |
35 |
Correct |
2 ms |
2384 KB |
Output is correct |
36 |
Correct |
2 ms |
2384 KB |
Output is correct |
37 |
Correct |
2 ms |
2384 KB |
Output is correct |
38 |
Correct |
2 ms |
2384 KB |
Output is correct |
39 |
Correct |
2 ms |
2384 KB |
Output is correct |
40 |
Correct |
2 ms |
2384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2384 KB |
Output is correct |
2 |
Correct |
1 ms |
2384 KB |
Output is correct |
3 |
Correct |
1 ms |
2384 KB |
Output is correct |
4 |
Correct |
1 ms |
2384 KB |
Output is correct |
5 |
Correct |
1 ms |
2384 KB |
Output is correct |
6 |
Correct |
1 ms |
2384 KB |
Output is correct |
7 |
Correct |
1 ms |
2384 KB |
Output is correct |
8 |
Correct |
1 ms |
2384 KB |
Output is correct |
9 |
Correct |
1 ms |
2384 KB |
Output is correct |
10 |
Correct |
1 ms |
2384 KB |
Output is correct |
11 |
Correct |
1 ms |
2384 KB |
Output is correct |
12 |
Correct |
1 ms |
2384 KB |
Output is correct |
13 |
Correct |
1 ms |
2384 KB |
Output is correct |
14 |
Correct |
1 ms |
2384 KB |
Output is correct |
15 |
Correct |
1 ms |
2384 KB |
Output is correct |
16 |
Correct |
1 ms |
2384 KB |
Output is correct |
17 |
Correct |
1 ms |
2384 KB |
Output is correct |
18 |
Correct |
1 ms |
2384 KB |
Output is correct |
19 |
Correct |
1 ms |
2396 KB |
Output is correct |
20 |
Correct |
1 ms |
2384 KB |
Output is correct |
21 |
Correct |
2 ms |
2384 KB |
Output is correct |
22 |
Correct |
2 ms |
2384 KB |
Output is correct |
23 |
Correct |
2 ms |
2384 KB |
Output is correct |
24 |
Correct |
1 ms |
2384 KB |
Output is correct |
25 |
Correct |
1 ms |
2384 KB |
Output is correct |
26 |
Correct |
2 ms |
2384 KB |
Output is correct |
27 |
Correct |
2 ms |
2384 KB |
Output is correct |
28 |
Correct |
2 ms |
2384 KB |
Output is correct |
29 |
Correct |
2 ms |
2384 KB |
Output is correct |
30 |
Correct |
2 ms |
2552 KB |
Output is correct |
31 |
Correct |
2 ms |
2384 KB |
Output is correct |
32 |
Correct |
2 ms |
2384 KB |
Output is correct |
33 |
Correct |
3 ms |
2384 KB |
Output is correct |
34 |
Correct |
2 ms |
2384 KB |
Output is correct |
35 |
Correct |
2 ms |
2384 KB |
Output is correct |
36 |
Correct |
2 ms |
2384 KB |
Output is correct |
37 |
Correct |
2 ms |
2384 KB |
Output is correct |
38 |
Correct |
2 ms |
2384 KB |
Output is correct |
39 |
Correct |
2 ms |
2384 KB |
Output is correct |
40 |
Correct |
2 ms |
2384 KB |
Output is correct |
41 |
Correct |
20 ms |
8748 KB |
Output is correct |
42 |
Correct |
20 ms |
8528 KB |
Output is correct |
43 |
Correct |
21 ms |
8528 KB |
Output is correct |
44 |
Correct |
20 ms |
8528 KB |
Output is correct |
45 |
Correct |
20 ms |
8528 KB |
Output is correct |
46 |
Correct |
20 ms |
8528 KB |
Output is correct |
47 |
Correct |
20 ms |
8744 KB |
Output is correct |
48 |
Correct |
22 ms |
8528 KB |
Output is correct |
49 |
Correct |
21 ms |
8532 KB |
Output is correct |
50 |
Correct |
23 ms |
8752 KB |
Output is correct |
51 |
Correct |
20 ms |
8768 KB |
Output is correct |
52 |
Correct |
20 ms |
8528 KB |
Output is correct |
53 |
Correct |
20 ms |
8772 KB |
Output is correct |
54 |
Correct |
20 ms |
8544 KB |
Output is correct |
55 |
Correct |
20 ms |
8528 KB |
Output is correct |
56 |
Correct |
20 ms |
8528 KB |
Output is correct |
57 |
Correct |
20 ms |
8928 KB |
Output is correct |
58 |
Correct |
20 ms |
8528 KB |
Output is correct |
59 |
Correct |
20 ms |
8528 KB |
Output is correct |
60 |
Correct |
21 ms |
8696 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2384 KB |
Output is correct |
2 |
Correct |
1 ms |
2384 KB |
Output is correct |
3 |
Correct |
1 ms |
2384 KB |
Output is correct |
4 |
Correct |
1 ms |
2384 KB |
Output is correct |
5 |
Correct |
1 ms |
2384 KB |
Output is correct |
6 |
Correct |
1 ms |
2384 KB |
Output is correct |
7 |
Correct |
1 ms |
2384 KB |
Output is correct |
8 |
Correct |
1 ms |
2384 KB |
Output is correct |
9 |
Correct |
1 ms |
2384 KB |
Output is correct |
10 |
Correct |
1 ms |
2384 KB |
Output is correct |
11 |
Correct |
1 ms |
2384 KB |
Output is correct |
12 |
Correct |
1 ms |
2384 KB |
Output is correct |
13 |
Correct |
1 ms |
2384 KB |
Output is correct |
14 |
Correct |
1 ms |
2384 KB |
Output is correct |
15 |
Correct |
1 ms |
2384 KB |
Output is correct |
16 |
Correct |
1 ms |
2384 KB |
Output is correct |
17 |
Correct |
1 ms |
2384 KB |
Output is correct |
18 |
Correct |
1 ms |
2384 KB |
Output is correct |
19 |
Correct |
1 ms |
2396 KB |
Output is correct |
20 |
Correct |
1 ms |
2384 KB |
Output is correct |
21 |
Correct |
2 ms |
2384 KB |
Output is correct |
22 |
Correct |
2 ms |
2384 KB |
Output is correct |
23 |
Correct |
2 ms |
2384 KB |
Output is correct |
24 |
Correct |
1 ms |
2384 KB |
Output is correct |
25 |
Correct |
1 ms |
2384 KB |
Output is correct |
26 |
Correct |
2 ms |
2384 KB |
Output is correct |
27 |
Correct |
2 ms |
2384 KB |
Output is correct |
28 |
Correct |
2 ms |
2384 KB |
Output is correct |
29 |
Correct |
2 ms |
2384 KB |
Output is correct |
30 |
Correct |
2 ms |
2552 KB |
Output is correct |
31 |
Correct |
2 ms |
2384 KB |
Output is correct |
32 |
Correct |
2 ms |
2384 KB |
Output is correct |
33 |
Correct |
3 ms |
2384 KB |
Output is correct |
34 |
Correct |
2 ms |
2384 KB |
Output is correct |
35 |
Correct |
2 ms |
2384 KB |
Output is correct |
36 |
Correct |
2 ms |
2384 KB |
Output is correct |
37 |
Correct |
2 ms |
2384 KB |
Output is correct |
38 |
Correct |
2 ms |
2384 KB |
Output is correct |
39 |
Correct |
2 ms |
2384 KB |
Output is correct |
40 |
Correct |
2 ms |
2384 KB |
Output is correct |
41 |
Correct |
20 ms |
8748 KB |
Output is correct |
42 |
Correct |
20 ms |
8528 KB |
Output is correct |
43 |
Correct |
21 ms |
8528 KB |
Output is correct |
44 |
Correct |
20 ms |
8528 KB |
Output is correct |
45 |
Correct |
20 ms |
8528 KB |
Output is correct |
46 |
Correct |
20 ms |
8528 KB |
Output is correct |
47 |
Correct |
20 ms |
8744 KB |
Output is correct |
48 |
Correct |
22 ms |
8528 KB |
Output is correct |
49 |
Correct |
21 ms |
8532 KB |
Output is correct |
50 |
Correct |
23 ms |
8752 KB |
Output is correct |
51 |
Correct |
20 ms |
8768 KB |
Output is correct |
52 |
Correct |
20 ms |
8528 KB |
Output is correct |
53 |
Correct |
20 ms |
8772 KB |
Output is correct |
54 |
Correct |
20 ms |
8544 KB |
Output is correct |
55 |
Correct |
20 ms |
8528 KB |
Output is correct |
56 |
Correct |
20 ms |
8528 KB |
Output is correct |
57 |
Correct |
20 ms |
8928 KB |
Output is correct |
58 |
Correct |
20 ms |
8528 KB |
Output is correct |
59 |
Correct |
20 ms |
8528 KB |
Output is correct |
60 |
Correct |
21 ms |
8696 KB |
Output is correct |
61 |
Correct |
314 ms |
33120 KB |
Output is correct |
62 |
Correct |
311 ms |
33096 KB |
Output is correct |
63 |
Correct |
316 ms |
33100 KB |
Output is correct |
64 |
Correct |
305 ms |
33096 KB |
Output is correct |
65 |
Correct |
327 ms |
33096 KB |
Output is correct |
66 |
Correct |
314 ms |
33132 KB |
Output is correct |
67 |
Correct |
312 ms |
33100 KB |
Output is correct |
68 |
Correct |
331 ms |
33156 KB |
Output is correct |
69 |
Correct |
321 ms |
33164 KB |
Output is correct |
70 |
Correct |
305 ms |
33172 KB |
Output is correct |
71 |
Correct |
305 ms |
33136 KB |
Output is correct |
72 |
Correct |
306 ms |
33120 KB |
Output is correct |
73 |
Correct |
311 ms |
33124 KB |
Output is correct |
74 |
Correct |
309 ms |
33096 KB |
Output is correct |
75 |
Correct |
315 ms |
33120 KB |
Output is correct |
76 |
Correct |
316 ms |
33128 KB |
Output is correct |
77 |
Correct |
305 ms |
33096 KB |
Output is correct |
78 |
Correct |
320 ms |
33160 KB |
Output is correct |
79 |
Correct |
284 ms |
33100 KB |
Output is correct |
80 |
Correct |
284 ms |
33132 KB |
Output is correct |