#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <bits/stdc++.h>
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef long double ldb;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ldb,ldb> pdd;
#define ff(i,a,b) for(int i = a; i <= b; i++)
#define fb(i,b,a) for(int i = b; i >= a; i--)
#define trav(a,x) for(auto& a : x)
#define sz(a) (int)(a).size()
#define fi first
#define se second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
// os.order_of_key(k) the number of elements in the os less than k
// *os.find_by_order(k) print the k-th smallest number in os(0-based)
const int mod = 1000000007;
const ll inf = 1e15 + 5;
const int mxN = 2050;
int n;
int mat[mxN][mxN];
ll dp[mxN][mxN];
pii seg[4 * mxN];
int poz[4 * mxN];
void calc(int v, int tl, int tr){
seg[v] = {tl, tr};
if(tl == tr){
poz[tl] = v;
return;
}
int mid = (tl + tr) / 2;
calc(v * 2, tl, mid); calc(v * 2 + 1, mid + 1, tr);
}
int main(){
cin.tie(0)->sync_with_stdio(0);
cin >> n;
ff(i,0,n - 1)ff(j,0,n - 1)cin >> mat[i][j];
calc(1,0,n - 1);
ff(i,0,n)ff(a,0,n)dp[i][a] = inf;
ff(a,0,n - 1)dp[0][a] = 0;
ff(i,1,n - 1){
int X = 0;
ff(j,0,11){
if((i >> j) & 1){
X = j;
break;
}
}
ff(a,0,n - 1){
int pos = poz[a];
pos >>= X;
int L = seg[pos ^ 1].fi;
int R = seg[pos ^ 1].se;
ff(b,L,R){
dp[i][a] = min(dp[i][a], dp[i - 1][b] + mat[a][b]);
}
}
}
ll rez = inf;
ff(a,0,n - 1)rez = min(rez, dp[n - 1][a]);
cout << rez << '\n';
return 0;
}
/*
// probati bojenje sahovski
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
6488 KB |
Output is correct |
2 |
Correct |
1 ms |
6492 KB |
Output is correct |
3 |
Correct |
1 ms |
6492 KB |
Output is correct |
4 |
Correct |
1 ms |
6492 KB |
Output is correct |
5 |
Correct |
1 ms |
6492 KB |
Output is correct |
6 |
Correct |
1 ms |
6492 KB |
Output is correct |
7 |
Correct |
1 ms |
6492 KB |
Output is correct |
8 |
Correct |
1 ms |
6540 KB |
Output is correct |
9 |
Correct |
1 ms |
6488 KB |
Output is correct |
10 |
Correct |
1 ms |
6492 KB |
Output is correct |
11 |
Correct |
1 ms |
6664 KB |
Output is correct |
12 |
Correct |
1 ms |
6616 KB |
Output is correct |
13 |
Correct |
1 ms |
6492 KB |
Output is correct |
14 |
Correct |
1 ms |
6608 KB |
Output is correct |
15 |
Correct |
1 ms |
6492 KB |
Output is correct |
16 |
Correct |
1 ms |
6492 KB |
Output is correct |
17 |
Correct |
1 ms |
6492 KB |
Output is correct |
18 |
Correct |
1 ms |
6492 KB |
Output is correct |
19 |
Correct |
1 ms |
6492 KB |
Output is correct |
20 |
Correct |
1 ms |
6492 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
6488 KB |
Output is correct |
2 |
Correct |
1 ms |
6492 KB |
Output is correct |
3 |
Correct |
1 ms |
6492 KB |
Output is correct |
4 |
Correct |
1 ms |
6492 KB |
Output is correct |
5 |
Correct |
1 ms |
6492 KB |
Output is correct |
6 |
Correct |
1 ms |
6492 KB |
Output is correct |
7 |
Correct |
1 ms |
6492 KB |
Output is correct |
8 |
Correct |
1 ms |
6540 KB |
Output is correct |
9 |
Correct |
1 ms |
6488 KB |
Output is correct |
10 |
Correct |
1 ms |
6492 KB |
Output is correct |
11 |
Correct |
1 ms |
6664 KB |
Output is correct |
12 |
Correct |
1 ms |
6616 KB |
Output is correct |
13 |
Correct |
1 ms |
6492 KB |
Output is correct |
14 |
Correct |
1 ms |
6608 KB |
Output is correct |
15 |
Correct |
1 ms |
6492 KB |
Output is correct |
16 |
Correct |
1 ms |
6492 KB |
Output is correct |
17 |
Correct |
1 ms |
6492 KB |
Output is correct |
18 |
Correct |
1 ms |
6492 KB |
Output is correct |
19 |
Correct |
1 ms |
6492 KB |
Output is correct |
20 |
Correct |
1 ms |
6492 KB |
Output is correct |
21 |
Correct |
3 ms |
6748 KB |
Output is correct |
22 |
Correct |
2 ms |
6748 KB |
Output is correct |
23 |
Correct |
3 ms |
6748 KB |
Output is correct |
24 |
Correct |
2 ms |
6620 KB |
Output is correct |
25 |
Correct |
1 ms |
6492 KB |
Output is correct |
26 |
Correct |
3 ms |
6748 KB |
Output is correct |
27 |
Correct |
2 ms |
6640 KB |
Output is correct |
28 |
Correct |
3 ms |
6748 KB |
Output is correct |
29 |
Correct |
2 ms |
6748 KB |
Output is correct |
30 |
Correct |
3 ms |
6748 KB |
Output is correct |
31 |
Correct |
3 ms |
6744 KB |
Output is correct |
32 |
Correct |
2 ms |
6748 KB |
Output is correct |
33 |
Correct |
2 ms |
6744 KB |
Output is correct |
34 |
Correct |
2 ms |
6748 KB |
Output is correct |
35 |
Correct |
3 ms |
6776 KB |
Output is correct |
36 |
Correct |
3 ms |
6748 KB |
Output is correct |
37 |
Correct |
2 ms |
6748 KB |
Output is correct |
38 |
Correct |
2 ms |
6748 KB |
Output is correct |
39 |
Correct |
3 ms |
6632 KB |
Output is correct |
40 |
Correct |
3 ms |
6748 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
6488 KB |
Output is correct |
2 |
Correct |
1 ms |
6492 KB |
Output is correct |
3 |
Correct |
1 ms |
6492 KB |
Output is correct |
4 |
Correct |
1 ms |
6492 KB |
Output is correct |
5 |
Correct |
1 ms |
6492 KB |
Output is correct |
6 |
Correct |
1 ms |
6492 KB |
Output is correct |
7 |
Correct |
1 ms |
6492 KB |
Output is correct |
8 |
Correct |
1 ms |
6540 KB |
Output is correct |
9 |
Correct |
1 ms |
6488 KB |
Output is correct |
10 |
Correct |
1 ms |
6492 KB |
Output is correct |
11 |
Correct |
1 ms |
6664 KB |
Output is correct |
12 |
Correct |
1 ms |
6616 KB |
Output is correct |
13 |
Correct |
1 ms |
6492 KB |
Output is correct |
14 |
Correct |
1 ms |
6608 KB |
Output is correct |
15 |
Correct |
1 ms |
6492 KB |
Output is correct |
16 |
Correct |
1 ms |
6492 KB |
Output is correct |
17 |
Correct |
1 ms |
6492 KB |
Output is correct |
18 |
Correct |
1 ms |
6492 KB |
Output is correct |
19 |
Correct |
1 ms |
6492 KB |
Output is correct |
20 |
Correct |
1 ms |
6492 KB |
Output is correct |
21 |
Correct |
3 ms |
6748 KB |
Output is correct |
22 |
Correct |
2 ms |
6748 KB |
Output is correct |
23 |
Correct |
3 ms |
6748 KB |
Output is correct |
24 |
Correct |
2 ms |
6620 KB |
Output is correct |
25 |
Correct |
1 ms |
6492 KB |
Output is correct |
26 |
Correct |
3 ms |
6748 KB |
Output is correct |
27 |
Correct |
2 ms |
6640 KB |
Output is correct |
28 |
Correct |
3 ms |
6748 KB |
Output is correct |
29 |
Correct |
2 ms |
6748 KB |
Output is correct |
30 |
Correct |
3 ms |
6748 KB |
Output is correct |
31 |
Correct |
3 ms |
6744 KB |
Output is correct |
32 |
Correct |
2 ms |
6748 KB |
Output is correct |
33 |
Correct |
2 ms |
6744 KB |
Output is correct |
34 |
Correct |
2 ms |
6748 KB |
Output is correct |
35 |
Correct |
3 ms |
6776 KB |
Output is correct |
36 |
Correct |
3 ms |
6748 KB |
Output is correct |
37 |
Correct |
2 ms |
6748 KB |
Output is correct |
38 |
Correct |
2 ms |
6748 KB |
Output is correct |
39 |
Correct |
3 ms |
6632 KB |
Output is correct |
40 |
Correct |
3 ms |
6748 KB |
Output is correct |
41 |
Correct |
24 ms |
17316 KB |
Output is correct |
42 |
Correct |
24 ms |
17232 KB |
Output is correct |
43 |
Correct |
23 ms |
17232 KB |
Output is correct |
44 |
Correct |
24 ms |
17236 KB |
Output is correct |
45 |
Correct |
23 ms |
17216 KB |
Output is correct |
46 |
Correct |
24 ms |
17232 KB |
Output is correct |
47 |
Correct |
24 ms |
17236 KB |
Output is correct |
48 |
Correct |
24 ms |
17244 KB |
Output is correct |
49 |
Correct |
24 ms |
17372 KB |
Output is correct |
50 |
Correct |
24 ms |
17348 KB |
Output is correct |
51 |
Correct |
26 ms |
17348 KB |
Output is correct |
52 |
Correct |
23 ms |
17232 KB |
Output is correct |
53 |
Correct |
23 ms |
17220 KB |
Output is correct |
54 |
Correct |
23 ms |
17232 KB |
Output is correct |
55 |
Correct |
23 ms |
17224 KB |
Output is correct |
56 |
Correct |
24 ms |
17452 KB |
Output is correct |
57 |
Correct |
23 ms |
17232 KB |
Output is correct |
58 |
Correct |
23 ms |
17236 KB |
Output is correct |
59 |
Correct |
24 ms |
17236 KB |
Output is correct |
60 |
Correct |
24 ms |
17244 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
6488 KB |
Output is correct |
2 |
Correct |
1 ms |
6492 KB |
Output is correct |
3 |
Correct |
1 ms |
6492 KB |
Output is correct |
4 |
Correct |
1 ms |
6492 KB |
Output is correct |
5 |
Correct |
1 ms |
6492 KB |
Output is correct |
6 |
Correct |
1 ms |
6492 KB |
Output is correct |
7 |
Correct |
1 ms |
6492 KB |
Output is correct |
8 |
Correct |
1 ms |
6540 KB |
Output is correct |
9 |
Correct |
1 ms |
6488 KB |
Output is correct |
10 |
Correct |
1 ms |
6492 KB |
Output is correct |
11 |
Correct |
1 ms |
6664 KB |
Output is correct |
12 |
Correct |
1 ms |
6616 KB |
Output is correct |
13 |
Correct |
1 ms |
6492 KB |
Output is correct |
14 |
Correct |
1 ms |
6608 KB |
Output is correct |
15 |
Correct |
1 ms |
6492 KB |
Output is correct |
16 |
Correct |
1 ms |
6492 KB |
Output is correct |
17 |
Correct |
1 ms |
6492 KB |
Output is correct |
18 |
Correct |
1 ms |
6492 KB |
Output is correct |
19 |
Correct |
1 ms |
6492 KB |
Output is correct |
20 |
Correct |
1 ms |
6492 KB |
Output is correct |
21 |
Correct |
3 ms |
6748 KB |
Output is correct |
22 |
Correct |
2 ms |
6748 KB |
Output is correct |
23 |
Correct |
3 ms |
6748 KB |
Output is correct |
24 |
Correct |
2 ms |
6620 KB |
Output is correct |
25 |
Correct |
1 ms |
6492 KB |
Output is correct |
26 |
Correct |
3 ms |
6748 KB |
Output is correct |
27 |
Correct |
2 ms |
6640 KB |
Output is correct |
28 |
Correct |
3 ms |
6748 KB |
Output is correct |
29 |
Correct |
2 ms |
6748 KB |
Output is correct |
30 |
Correct |
3 ms |
6748 KB |
Output is correct |
31 |
Correct |
3 ms |
6744 KB |
Output is correct |
32 |
Correct |
2 ms |
6748 KB |
Output is correct |
33 |
Correct |
2 ms |
6744 KB |
Output is correct |
34 |
Correct |
2 ms |
6748 KB |
Output is correct |
35 |
Correct |
3 ms |
6776 KB |
Output is correct |
36 |
Correct |
3 ms |
6748 KB |
Output is correct |
37 |
Correct |
2 ms |
6748 KB |
Output is correct |
38 |
Correct |
2 ms |
6748 KB |
Output is correct |
39 |
Correct |
3 ms |
6632 KB |
Output is correct |
40 |
Correct |
3 ms |
6748 KB |
Output is correct |
41 |
Correct |
24 ms |
17316 KB |
Output is correct |
42 |
Correct |
24 ms |
17232 KB |
Output is correct |
43 |
Correct |
23 ms |
17232 KB |
Output is correct |
44 |
Correct |
24 ms |
17236 KB |
Output is correct |
45 |
Correct |
23 ms |
17216 KB |
Output is correct |
46 |
Correct |
24 ms |
17232 KB |
Output is correct |
47 |
Correct |
24 ms |
17236 KB |
Output is correct |
48 |
Correct |
24 ms |
17244 KB |
Output is correct |
49 |
Correct |
24 ms |
17372 KB |
Output is correct |
50 |
Correct |
24 ms |
17348 KB |
Output is correct |
51 |
Correct |
26 ms |
17348 KB |
Output is correct |
52 |
Correct |
23 ms |
17232 KB |
Output is correct |
53 |
Correct |
23 ms |
17220 KB |
Output is correct |
54 |
Correct |
23 ms |
17232 KB |
Output is correct |
55 |
Correct |
23 ms |
17224 KB |
Output is correct |
56 |
Correct |
24 ms |
17452 KB |
Output is correct |
57 |
Correct |
23 ms |
17232 KB |
Output is correct |
58 |
Correct |
23 ms |
17236 KB |
Output is correct |
59 |
Correct |
24 ms |
17236 KB |
Output is correct |
60 |
Correct |
24 ms |
17244 KB |
Output is correct |
61 |
Correct |
377 ms |
90040 KB |
Output is correct |
62 |
Correct |
363 ms |
90120 KB |
Output is correct |
63 |
Correct |
378 ms |
90196 KB |
Output is correct |
64 |
Correct |
381 ms |
90108 KB |
Output is correct |
65 |
Correct |
381 ms |
90244 KB |
Output is correct |
66 |
Correct |
391 ms |
90092 KB |
Output is correct |
67 |
Correct |
380 ms |
90484 KB |
Output is correct |
68 |
Correct |
372 ms |
90196 KB |
Output is correct |
69 |
Correct |
375 ms |
90156 KB |
Output is correct |
70 |
Correct |
400 ms |
90060 KB |
Output is correct |
71 |
Correct |
381 ms |
90708 KB |
Output is correct |
72 |
Correct |
382 ms |
91148 KB |
Output is correct |
73 |
Correct |
389 ms |
90912 KB |
Output is correct |
74 |
Correct |
513 ms |
90568 KB |
Output is correct |
75 |
Correct |
404 ms |
90672 KB |
Output is correct |
76 |
Correct |
404 ms |
90716 KB |
Output is correct |
77 |
Correct |
388 ms |
90852 KB |
Output is correct |
78 |
Correct |
370 ms |
90704 KB |
Output is correct |
79 |
Correct |
357 ms |
90704 KB |
Output is correct |
80 |
Correct |
389 ms |
90904 KB |
Output is correct |