Submission #961367

# Submission time Handle Problem Language Result Execution time Memory
961367 2024-04-11T23:54:05 Z TAhmed33 Netrpeljivost (COI23_netrpeljivost) C++
59 / 100
1500 ms 79336 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int n, a[2049][2049];
const ll inf = 1e18;
void chmin (ll &x, ll y) {
	if (x > y) x = y;
}
vector <vector <ll>> recurse (int l, int r) {
	if (l == r - 1) {
		vector <vector <ll>> dp(2, vector <ll> (2, inf));
		dp[0][1] = dp[1][0] = a[l][r];
		return dp;
	}
	int sze = r - l + 1; 
	vector <vector <ll>> dp(sze, vector <ll> (sze, inf));
	sze >>= 1;
	int mid = (l + r) >> 1;
	auto g = recurse(l, mid), h = recurse(1 + mid, r);
	for (int i = 0; i < sze; i++) {
		for (int j = 0; j < sze; j++) {
			ll mn = inf;
			for (int k = 0; k < sze; k++) {
				chmin(mn, g[i][k] + a[k + l][j + mid + 1]);
			}
			for (int k = 0; k < sze; k++) {
				chmin(dp[i][k + sze], mn + h[k][j]);
			}
		}	
	}
	sze <<= 1;
	for (int i = 0; i < (sze >> 1); i++) for (int j = (sze >> 1); j < sze; j++) dp[j][i] = dp[i][j];
	return dp;
}
signed main () {
	ios::sync_with_stdio(0); cin.tie(0);
	cin >> n;
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= n; j++) {
			cin >> a[i][j];
		}
	}
	if (n == 2) {
		cout << a[1][2] << '\n';
		return 0;
	}
	auto g = recurse(1, n / 2), h = recurse(n / 2 + 1, n);
	ll mn[n / 2 + 1][2];
	for (int i = 0; i <= n / 2; i++) {
		for (int j = 0; j < 2; j++) {
			mn[i][j] = inf;
		}
	}
	ll ans = inf;
	for (int i = 0; i < n / 2; i++) {
		for (int j = 0; j < n / 2; j++) {
			chmin(mn[i][0], g[i][j]);
			chmin(mn[i][1], h[i][j]);
		}
	}
	for (int i = 0; i < n / 2; i++) {
		for (int j = 0; j < n / 2; j++) {
			chmin(ans, mn[i][0] + mn[j][1] + a[i + 1][j + n / 2 + 1]);
		}
	}
	cout << ans << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 392 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 388 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 344 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 600 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 0 ms 352 KB Output is correct
19 Correct 1 ms 344 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 348 KB Output is correct
3 Correct 0 ms 392 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 388 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 344 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 600 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 0 ms 352 KB Output is correct
19 Correct 1 ms 344 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 3 ms 2672 KB Output is correct
22 Correct 2 ms 2652 KB Output is correct
23 Correct 3 ms 2764 KB Output is correct
24 Correct 3 ms 2652 KB Output is correct
25 Correct 1 ms 2616 KB Output is correct
26 Correct 3 ms 2828 KB Output is correct
27 Correct 4 ms 2648 KB Output is correct
28 Correct 2 ms 2652 KB Output is correct
29 Correct 2 ms 2656 KB Output is correct
30 Correct 2 ms 2652 KB Output is correct
31 Correct 3 ms 2652 KB Output is correct
32 Correct 2 ms 2648 KB Output is correct
33 Correct 2 ms 2652 KB Output is correct
34 Correct 2 ms 2768 KB Output is correct
35 Correct 2 ms 2652 KB Output is correct
36 Correct 2 ms 2652 KB Output is correct
37 Correct 3 ms 2656 KB Output is correct
38 Correct 2 ms 2652 KB Output is correct
39 Correct 2 ms 2656 KB Output is correct
40 Correct 3 ms 2660 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 392 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 388 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 344 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 600 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 0 ms 352 KB Output is correct
19 Correct 1 ms 344 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 3 ms 2672 KB Output is correct
22 Correct 2 ms 2652 KB Output is correct
23 Correct 3 ms 2764 KB Output is correct
24 Correct 3 ms 2652 KB Output is correct
25 Correct 1 ms 2616 KB Output is correct
26 Correct 3 ms 2828 KB Output is correct
27 Correct 4 ms 2648 KB Output is correct
28 Correct 2 ms 2652 KB Output is correct
29 Correct 2 ms 2656 KB Output is correct
30 Correct 2 ms 2652 KB Output is correct
31 Correct 3 ms 2652 KB Output is correct
32 Correct 2 ms 2648 KB Output is correct
33 Correct 2 ms 2652 KB Output is correct
34 Correct 2 ms 2768 KB Output is correct
35 Correct 2 ms 2652 KB Output is correct
36 Correct 2 ms 2652 KB Output is correct
37 Correct 3 ms 2656 KB Output is correct
38 Correct 2 ms 2652 KB Output is correct
39 Correct 2 ms 2656 KB Output is correct
40 Correct 3 ms 2660 KB Output is correct
41 Correct 39 ms 8472 KB Output is correct
42 Correct 34 ms 8528 KB Output is correct
43 Correct 35 ms 8528 KB Output is correct
44 Correct 34 ms 8528 KB Output is correct
45 Correct 40 ms 8584 KB Output is correct
46 Correct 35 ms 8464 KB Output is correct
47 Correct 36 ms 8528 KB Output is correct
48 Correct 35 ms 8456 KB Output is correct
49 Correct 37 ms 8332 KB Output is correct
50 Correct 36 ms 8532 KB Output is correct
51 Correct 39 ms 8528 KB Output is correct
52 Correct 34 ms 8536 KB Output is correct
53 Correct 33 ms 8600 KB Output is correct
54 Correct 33 ms 8532 KB Output is correct
55 Correct 33 ms 8532 KB Output is correct
56 Correct 36 ms 8532 KB Output is correct
57 Correct 37 ms 8660 KB Output is correct
58 Correct 37 ms 8532 KB Output is correct
59 Correct 37 ms 8532 KB Output is correct
60 Correct 34 ms 8528 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 392 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 388 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 344 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 600 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 0 ms 352 KB Output is correct
19 Correct 1 ms 344 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 3 ms 2672 KB Output is correct
22 Correct 2 ms 2652 KB Output is correct
23 Correct 3 ms 2764 KB Output is correct
24 Correct 3 ms 2652 KB Output is correct
25 Correct 1 ms 2616 KB Output is correct
26 Correct 3 ms 2828 KB Output is correct
27 Correct 4 ms 2648 KB Output is correct
28 Correct 2 ms 2652 KB Output is correct
29 Correct 2 ms 2656 KB Output is correct
30 Correct 2 ms 2652 KB Output is correct
31 Correct 3 ms 2652 KB Output is correct
32 Correct 2 ms 2648 KB Output is correct
33 Correct 2 ms 2652 KB Output is correct
34 Correct 2 ms 2768 KB Output is correct
35 Correct 2 ms 2652 KB Output is correct
36 Correct 2 ms 2652 KB Output is correct
37 Correct 3 ms 2656 KB Output is correct
38 Correct 2 ms 2652 KB Output is correct
39 Correct 2 ms 2656 KB Output is correct
40 Correct 3 ms 2660 KB Output is correct
41 Correct 39 ms 8472 KB Output is correct
42 Correct 34 ms 8528 KB Output is correct
43 Correct 35 ms 8528 KB Output is correct
44 Correct 34 ms 8528 KB Output is correct
45 Correct 40 ms 8584 KB Output is correct
46 Correct 35 ms 8464 KB Output is correct
47 Correct 36 ms 8528 KB Output is correct
48 Correct 35 ms 8456 KB Output is correct
49 Correct 37 ms 8332 KB Output is correct
50 Correct 36 ms 8532 KB Output is correct
51 Correct 39 ms 8528 KB Output is correct
52 Correct 34 ms 8536 KB Output is correct
53 Correct 33 ms 8600 KB Output is correct
54 Correct 33 ms 8532 KB Output is correct
55 Correct 33 ms 8532 KB Output is correct
56 Correct 36 ms 8532 KB Output is correct
57 Correct 37 ms 8660 KB Output is correct
58 Correct 37 ms 8532 KB Output is correct
59 Correct 37 ms 8532 KB Output is correct
60 Correct 34 ms 8528 KB Output is correct
61 Correct 1439 ms 79336 KB Output is correct
62 Execution timed out 1501 ms 79288 KB Time limit exceeded
63 Halted 0 ms 0 KB -