Submission #858541

# Submission time Handle Problem Language Result Execution time Memory
858541 2023-10-08T17:12:49 Z jcelin Netrpeljivost (COI23_netrpeljivost) C++14
100 / 100
401 ms 107348 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;

#define ii pair<int,int>
#define pll pair<ll,ll>
#define vi vector<int>
#define vii vector<ii>
#define vll vector<ll>
#define vpll vector<pll>
#define msi multiset<int>
#define si set<int>
#define PB push_back
#define PF push_front
#define PPB pop_back
#define PPF pop_front
#define X first
#define Y second
#define MP make_pair
#define FOR(i, a, b) for (int i = int(a); i < int(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(), (x).end()

const int mod = 1e9 + 7;
const int MOD = 998244353;
const int inf = mod;
const ll INF = 1e18;
const int MAXN = 2049;
const int logo = 11;
const int off = 1 << logo;
const int trsz = off << 1;
const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, 1, -1};

ll c[MAXN][MAXN], dp[MAXN][MAXN];

void solve(){
	int n;
	cin >> n;
	for(int i=0; i<n; i++){
		for(int j=0; j<n; j++) cin >> c[i][j];
	}
	
	for(int p=1; p<n; p++){
		int sz = p & (-p);
		int psz = sz * 2;
		for(int tr=0; tr<n; tr++){
			int bl = tr / psz * psz;
			int ls = bl + psz - 1;
			int mi = (bl + ls) / 2;
			
			int pr = bl;
			if(tr <= mi){
				pr = mi + 1;
			}
			
			dp[p][tr] = INF;
			for(int k=0; k<sz; k++){
				dp[p][tr] = min(dp[p][tr], dp[p - 1][pr + k] + c[pr + k][tr]);
			}
		}
	}
	
	ll ans = INF;
	for(int i=0; i<n; i++) ans = min(ans, dp[n - 1][i]);
	cout << ans << "\n";
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int t = 1;
	//cin >> t;
	while(t--) solve();
	return 0;
}



# Verdict Execution time Memory Grader output
1 Correct 1 ms 6492 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 6492 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 6492 KB Output is correct
12 Correct 1 ms 6492 KB Output is correct
13 Correct 1 ms 6492 KB Output is correct
14 Correct 1 ms 6492 KB Output is correct
15 Correct 1 ms 6488 KB Output is correct
16 Correct 1 ms 6492 KB Output is correct
17 Correct 1 ms 6488 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
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6492 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 6492 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 6492 KB Output is correct
12 Correct 1 ms 6492 KB Output is correct
13 Correct 1 ms 6492 KB Output is correct
14 Correct 1 ms 6492 KB Output is correct
15 Correct 1 ms 6488 KB Output is correct
16 Correct 1 ms 6492 KB Output is correct
17 Correct 1 ms 6488 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 2 ms 6744 KB Output is correct
22 Correct 2 ms 6748 KB Output is correct
23 Correct 2 ms 6780 KB Output is correct
24 Correct 1 ms 6488 KB Output is correct
25 Correct 2 ms 6492 KB Output is correct
26 Correct 2 ms 6748 KB Output is correct
27 Correct 2 ms 6748 KB Output is correct
28 Correct 2 ms 6748 KB Output is correct
29 Correct 2 ms 6748 KB Output is correct
30 Correct 2 ms 6748 KB Output is correct
31 Correct 2 ms 6748 KB Output is correct
32 Correct 2 ms 6748 KB Output is correct
33 Correct 2 ms 6748 KB Output is correct
34 Correct 2 ms 6776 KB Output is correct
35 Correct 3 ms 6748 KB Output is correct
36 Correct 2 ms 6772 KB Output is correct
37 Correct 2 ms 6776 KB Output is correct
38 Correct 3 ms 6748 KB Output is correct
39 Correct 2 ms 6748 KB Output is correct
40 Correct 2 ms 6748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6492 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 6492 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 6492 KB Output is correct
12 Correct 1 ms 6492 KB Output is correct
13 Correct 1 ms 6492 KB Output is correct
14 Correct 1 ms 6492 KB Output is correct
15 Correct 1 ms 6488 KB Output is correct
16 Correct 1 ms 6492 KB Output is correct
17 Correct 1 ms 6488 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 2 ms 6744 KB Output is correct
22 Correct 2 ms 6748 KB Output is correct
23 Correct 2 ms 6780 KB Output is correct
24 Correct 1 ms 6488 KB Output is correct
25 Correct 2 ms 6492 KB Output is correct
26 Correct 2 ms 6748 KB Output is correct
27 Correct 2 ms 6748 KB Output is correct
28 Correct 2 ms 6748 KB Output is correct
29 Correct 2 ms 6748 KB Output is correct
30 Correct 2 ms 6748 KB Output is correct
31 Correct 2 ms 6748 KB Output is correct
32 Correct 2 ms 6748 KB Output is correct
33 Correct 2 ms 6748 KB Output is correct
34 Correct 2 ms 6776 KB Output is correct
35 Correct 3 ms 6748 KB Output is correct
36 Correct 2 ms 6772 KB Output is correct
37 Correct 2 ms 6776 KB Output is correct
38 Correct 3 ms 6748 KB Output is correct
39 Correct 2 ms 6748 KB Output is correct
40 Correct 2 ms 6748 KB Output is correct
41 Correct 25 ms 21444 KB Output is correct
42 Correct 25 ms 21316 KB Output is correct
43 Correct 24 ms 21332 KB Output is correct
44 Correct 24 ms 21304 KB Output is correct
45 Correct 24 ms 21332 KB Output is correct
46 Correct 24 ms 21312 KB Output is correct
47 Correct 24 ms 21324 KB Output is correct
48 Correct 25 ms 21448 KB Output is correct
49 Correct 24 ms 21332 KB Output is correct
50 Correct 27 ms 21316 KB Output is correct
51 Correct 24 ms 21712 KB Output is correct
52 Correct 24 ms 21320 KB Output is correct
53 Correct 24 ms 21332 KB Output is correct
54 Correct 24 ms 21336 KB Output is correct
55 Correct 30 ms 21724 KB Output is correct
56 Correct 24 ms 21328 KB Output is correct
57 Correct 28 ms 21328 KB Output is correct
58 Correct 24 ms 21340 KB Output is correct
59 Correct 25 ms 21312 KB Output is correct
60 Correct 24 ms 21436 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6492 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 6492 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 6492 KB Output is correct
12 Correct 1 ms 6492 KB Output is correct
13 Correct 1 ms 6492 KB Output is correct
14 Correct 1 ms 6492 KB Output is correct
15 Correct 1 ms 6488 KB Output is correct
16 Correct 1 ms 6492 KB Output is correct
17 Correct 1 ms 6488 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 2 ms 6744 KB Output is correct
22 Correct 2 ms 6748 KB Output is correct
23 Correct 2 ms 6780 KB Output is correct
24 Correct 1 ms 6488 KB Output is correct
25 Correct 2 ms 6492 KB Output is correct
26 Correct 2 ms 6748 KB Output is correct
27 Correct 2 ms 6748 KB Output is correct
28 Correct 2 ms 6748 KB Output is correct
29 Correct 2 ms 6748 KB Output is correct
30 Correct 2 ms 6748 KB Output is correct
31 Correct 2 ms 6748 KB Output is correct
32 Correct 2 ms 6748 KB Output is correct
33 Correct 2 ms 6748 KB Output is correct
34 Correct 2 ms 6776 KB Output is correct
35 Correct 3 ms 6748 KB Output is correct
36 Correct 2 ms 6772 KB Output is correct
37 Correct 2 ms 6776 KB Output is correct
38 Correct 3 ms 6748 KB Output is correct
39 Correct 2 ms 6748 KB Output is correct
40 Correct 2 ms 6748 KB Output is correct
41 Correct 25 ms 21444 KB Output is correct
42 Correct 25 ms 21316 KB Output is correct
43 Correct 24 ms 21332 KB Output is correct
44 Correct 24 ms 21304 KB Output is correct
45 Correct 24 ms 21332 KB Output is correct
46 Correct 24 ms 21312 KB Output is correct
47 Correct 24 ms 21324 KB Output is correct
48 Correct 25 ms 21448 KB Output is correct
49 Correct 24 ms 21332 KB Output is correct
50 Correct 27 ms 21316 KB Output is correct
51 Correct 24 ms 21712 KB Output is correct
52 Correct 24 ms 21320 KB Output is correct
53 Correct 24 ms 21332 KB Output is correct
54 Correct 24 ms 21336 KB Output is correct
55 Correct 30 ms 21724 KB Output is correct
56 Correct 24 ms 21328 KB Output is correct
57 Correct 28 ms 21328 KB Output is correct
58 Correct 24 ms 21340 KB Output is correct
59 Correct 25 ms 21312 KB Output is correct
60 Correct 24 ms 21436 KB Output is correct
61 Correct 378 ms 106540 KB Output is correct
62 Correct 389 ms 106424 KB Output is correct
63 Correct 378 ms 106304 KB Output is correct
64 Correct 394 ms 106460 KB Output is correct
65 Correct 375 ms 106324 KB Output is correct
66 Correct 388 ms 106436 KB Output is correct
67 Correct 379 ms 106544 KB Output is correct
68 Correct 371 ms 106324 KB Output is correct
69 Correct 374 ms 106484 KB Output is correct
70 Correct 401 ms 106312 KB Output is correct
71 Correct 365 ms 107092 KB Output is correct
72 Correct 373 ms 107068 KB Output is correct
73 Correct 374 ms 107316 KB Output is correct
74 Correct 399 ms 106840 KB Output is correct
75 Correct 395 ms 107068 KB Output is correct
76 Correct 376 ms 107292 KB Output is correct
77 Correct 386 ms 107128 KB Output is correct
78 Correct 393 ms 107348 KB Output is correct
79 Correct 373 ms 107260 KB Output is correct
80 Correct 366 ms 107148 KB Output is correct