답안 #791524

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
791524 2023-07-24T07:11:08 Z GEN 이지후(#10078) Netrpeljivost (COI23_netrpeljivost) C++17
100 / 100
1395 ms 451504 KB
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using pi = array<int, 2>;
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(), (v).end()
const int MAXN = 2050;

int n;
int f[MAXN][MAXN];
lint dp[12][MAXN][MAXN], aux[MAXN][MAXN];

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin >> n;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			cin >> f[i][j];
		}
	}
	memset(dp, 0x3f, sizeof(dp));
	for (int i = 0; i < n; i++)
		dp[0][i][i] = 0;
	int lev = 0;
	while ((2 << lev) <= n)
		lev++;
	if (n <= 4) {
		for (int i = 0; i < lev; i++) {
			memset(aux, 0x3f, sizeof(aux));
			for (int j = 0; j < n; j += (2 << i)) {
				int s1 = j, e1 = j + (1 << i);
				int s2 = j + (1 << i), e2 = j + (2 << i);
				for (int k = s1; k < e1; k++) {
					for (int x = s1; x < e1; x++) {
						for (int y = s2; y < e2; y++) {
							aux[k][y] = min(aux[k][y], dp[i][k][x] + f[x][y]);
						}
					}
				}
				for (int k = s1; k < e1; k++) {
					for (int l = s2; l < e2; l++) {
						for (int y = s2; y < e2; y++) {
							dp[i + 1][k][l] = min(dp[i + 1][k][l], aux[k][y] + dp[i][y][l]);
						}
					}
				}
				for (int k = s1; k < e1; k++) {
					for (int l = s2; l < e2; l++) {
						dp[i + 1][l][k] = dp[i + 1][k][l];
					}
				}
			}
		}
		lint ans = 1e18;
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < i; j++) {
				ans = min(ans, dp[lev][i][j]);
			}
		}
		cout << ans << "\n";
		return 0;
	}
	for (int i = 0; i < lev - 1; i++) {
		memset(aux, 0x3f, sizeof(aux));
		for (int j = 0; j < n; j += (2 << i)) {
			int s1 = j, e1 = j + (1 << i);
			int s2 = j + (1 << i), e2 = j + (2 << i);
			for (int k = s1; k < e1; k++) {
				for (int x = s1; x < e1; x++) {
					for (int y = s2; y < e2; y++) {
						aux[k][y] = min(aux[k][y], dp[i][k][x] + f[x][y]);
					}
				}
			}
			for (int k = s1; k < e1; k++) {
				for (int l = s2; l < e2; l++) {
					for (int y = s2; y < e2; y++) {
						dp[i + 1][k][l] = min(dp[i + 1][k][l], aux[k][y] + dp[i][y][l]);
					}
				}
			}
			for (int k = s1; k < e1; k++) {
				for (int l = s2; l < e2; l++) {
					dp[i + 1][l][k] = dp[i + 1][k][l];
				}
			}
		}
	}
	lint ans = 1e18;
	vector<lint> L(n, 1e18), R(n, 1e18);
	for (int i = 0; i < n / 2; i++) {
		for (int j = 0; j < n / 2; j++) {
			L[i] = min(L[i], dp[lev - 1][i][j]);
			R[i + n / 2] = min(R[i + n / 2], dp[lev - 1][i + n / 2][j + n / 2]);
		}
	}
	for (int i = 0; i < n / 2; i++) {
		for (int j = n / 2; j < n; j++) {
			ans = min(ans, L[i] + R[j] + f[i][j]);
		}
	}
	cout << ans << "\n";
}
# 결과 실행 시간 메모리 Grader output
1 Correct 142 ms 427972 KB Output is correct
2 Correct 136 ms 427952 KB Output is correct
3 Correct 134 ms 427952 KB Output is correct
4 Correct 151 ms 427980 KB Output is correct
5 Correct 134 ms 428080 KB Output is correct
6 Correct 139 ms 428012 KB Output is correct
7 Correct 144 ms 427940 KB Output is correct
8 Correct 139 ms 427960 KB Output is correct
9 Correct 154 ms 427948 KB Output is correct
10 Correct 144 ms 427980 KB Output is correct
11 Correct 146 ms 427984 KB Output is correct
12 Correct 137 ms 427980 KB Output is correct
13 Correct 146 ms 427964 KB Output is correct
14 Correct 139 ms 427968 KB Output is correct
15 Correct 144 ms 427948 KB Output is correct
16 Correct 136 ms 427940 KB Output is correct
17 Correct 135 ms 428024 KB Output is correct
18 Correct 144 ms 428032 KB Output is correct
19 Correct 137 ms 427980 KB Output is correct
20 Correct 137 ms 427972 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 142 ms 427972 KB Output is correct
2 Correct 136 ms 427952 KB Output is correct
3 Correct 134 ms 427952 KB Output is correct
4 Correct 151 ms 427980 KB Output is correct
5 Correct 134 ms 428080 KB Output is correct
6 Correct 139 ms 428012 KB Output is correct
7 Correct 144 ms 427940 KB Output is correct
8 Correct 139 ms 427960 KB Output is correct
9 Correct 154 ms 427948 KB Output is correct
10 Correct 144 ms 427980 KB Output is correct
11 Correct 146 ms 427984 KB Output is correct
12 Correct 137 ms 427980 KB Output is correct
13 Correct 146 ms 427964 KB Output is correct
14 Correct 139 ms 427968 KB Output is correct
15 Correct 144 ms 427948 KB Output is correct
16 Correct 136 ms 427940 KB Output is correct
17 Correct 135 ms 428024 KB Output is correct
18 Correct 144 ms 428032 KB Output is correct
19 Correct 137 ms 427980 KB Output is correct
20 Correct 137 ms 427972 KB Output is correct
21 Correct 146 ms 428468 KB Output is correct
22 Correct 151 ms 428484 KB Output is correct
23 Correct 144 ms 428440 KB Output is correct
24 Correct 149 ms 428176 KB Output is correct
25 Correct 141 ms 428112 KB Output is correct
26 Correct 152 ms 428584 KB Output is correct
27 Correct 154 ms 428360 KB Output is correct
28 Correct 149 ms 428452 KB Output is correct
29 Correct 145 ms 428396 KB Output is correct
30 Correct 153 ms 428416 KB Output is correct
31 Correct 145 ms 428384 KB Output is correct
32 Correct 158 ms 428376 KB Output is correct
33 Correct 147 ms 428472 KB Output is correct
34 Correct 151 ms 428372 KB Output is correct
35 Correct 147 ms 428412 KB Output is correct
36 Correct 147 ms 428464 KB Output is correct
37 Correct 146 ms 428460 KB Output is correct
38 Correct 147 ms 428372 KB Output is correct
39 Correct 143 ms 428420 KB Output is correct
40 Correct 143 ms 428412 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 142 ms 427972 KB Output is correct
2 Correct 136 ms 427952 KB Output is correct
3 Correct 134 ms 427952 KB Output is correct
4 Correct 151 ms 427980 KB Output is correct
5 Correct 134 ms 428080 KB Output is correct
6 Correct 139 ms 428012 KB Output is correct
7 Correct 144 ms 427940 KB Output is correct
8 Correct 139 ms 427960 KB Output is correct
9 Correct 154 ms 427948 KB Output is correct
10 Correct 144 ms 427980 KB Output is correct
11 Correct 146 ms 427984 KB Output is correct
12 Correct 137 ms 427980 KB Output is correct
13 Correct 146 ms 427964 KB Output is correct
14 Correct 139 ms 427968 KB Output is correct
15 Correct 144 ms 427948 KB Output is correct
16 Correct 136 ms 427940 KB Output is correct
17 Correct 135 ms 428024 KB Output is correct
18 Correct 144 ms 428032 KB Output is correct
19 Correct 137 ms 427980 KB Output is correct
20 Correct 137 ms 427972 KB Output is correct
21 Correct 146 ms 428468 KB Output is correct
22 Correct 151 ms 428484 KB Output is correct
23 Correct 144 ms 428440 KB Output is correct
24 Correct 149 ms 428176 KB Output is correct
25 Correct 141 ms 428112 KB Output is correct
26 Correct 152 ms 428584 KB Output is correct
27 Correct 154 ms 428360 KB Output is correct
28 Correct 149 ms 428452 KB Output is correct
29 Correct 145 ms 428396 KB Output is correct
30 Correct 153 ms 428416 KB Output is correct
31 Correct 145 ms 428384 KB Output is correct
32 Correct 158 ms 428376 KB Output is correct
33 Correct 147 ms 428472 KB Output is correct
34 Correct 151 ms 428372 KB Output is correct
35 Correct 147 ms 428412 KB Output is correct
36 Correct 147 ms 428464 KB Output is correct
37 Correct 146 ms 428460 KB Output is correct
38 Correct 147 ms 428372 KB Output is correct
39 Correct 143 ms 428420 KB Output is correct
40 Correct 143 ms 428412 KB Output is correct
41 Correct 183 ms 430924 KB Output is correct
42 Correct 187 ms 430948 KB Output is correct
43 Correct 183 ms 430952 KB Output is correct
44 Correct 181 ms 431028 KB Output is correct
45 Correct 183 ms 431000 KB Output is correct
46 Correct 184 ms 430924 KB Output is correct
47 Correct 191 ms 431032 KB Output is correct
48 Correct 181 ms 430960 KB Output is correct
49 Correct 182 ms 430924 KB Output is correct
50 Correct 182 ms 431028 KB Output is correct
51 Correct 177 ms 431004 KB Output is correct
52 Correct 185 ms 431032 KB Output is correct
53 Correct 183 ms 430952 KB Output is correct
54 Correct 179 ms 430924 KB Output is correct
55 Correct 178 ms 430964 KB Output is correct
56 Correct 184 ms 430924 KB Output is correct
57 Correct 183 ms 431000 KB Output is correct
58 Correct 181 ms 431036 KB Output is correct
59 Correct 182 ms 431176 KB Output is correct
60 Correct 184 ms 430960 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 142 ms 427972 KB Output is correct
2 Correct 136 ms 427952 KB Output is correct
3 Correct 134 ms 427952 KB Output is correct
4 Correct 151 ms 427980 KB Output is correct
5 Correct 134 ms 428080 KB Output is correct
6 Correct 139 ms 428012 KB Output is correct
7 Correct 144 ms 427940 KB Output is correct
8 Correct 139 ms 427960 KB Output is correct
9 Correct 154 ms 427948 KB Output is correct
10 Correct 144 ms 427980 KB Output is correct
11 Correct 146 ms 427984 KB Output is correct
12 Correct 137 ms 427980 KB Output is correct
13 Correct 146 ms 427964 KB Output is correct
14 Correct 139 ms 427968 KB Output is correct
15 Correct 144 ms 427948 KB Output is correct
16 Correct 136 ms 427940 KB Output is correct
17 Correct 135 ms 428024 KB Output is correct
18 Correct 144 ms 428032 KB Output is correct
19 Correct 137 ms 427980 KB Output is correct
20 Correct 137 ms 427972 KB Output is correct
21 Correct 146 ms 428468 KB Output is correct
22 Correct 151 ms 428484 KB Output is correct
23 Correct 144 ms 428440 KB Output is correct
24 Correct 149 ms 428176 KB Output is correct
25 Correct 141 ms 428112 KB Output is correct
26 Correct 152 ms 428584 KB Output is correct
27 Correct 154 ms 428360 KB Output is correct
28 Correct 149 ms 428452 KB Output is correct
29 Correct 145 ms 428396 KB Output is correct
30 Correct 153 ms 428416 KB Output is correct
31 Correct 145 ms 428384 KB Output is correct
32 Correct 158 ms 428376 KB Output is correct
33 Correct 147 ms 428472 KB Output is correct
34 Correct 151 ms 428372 KB Output is correct
35 Correct 147 ms 428412 KB Output is correct
36 Correct 147 ms 428464 KB Output is correct
37 Correct 146 ms 428460 KB Output is correct
38 Correct 147 ms 428372 KB Output is correct
39 Correct 143 ms 428420 KB Output is correct
40 Correct 143 ms 428412 KB Output is correct
41 Correct 183 ms 430924 KB Output is correct
42 Correct 187 ms 430948 KB Output is correct
43 Correct 183 ms 430952 KB Output is correct
44 Correct 181 ms 431028 KB Output is correct
45 Correct 183 ms 431000 KB Output is correct
46 Correct 184 ms 430924 KB Output is correct
47 Correct 191 ms 431032 KB Output is correct
48 Correct 181 ms 430960 KB Output is correct
49 Correct 182 ms 430924 KB Output is correct
50 Correct 182 ms 431028 KB Output is correct
51 Correct 177 ms 431004 KB Output is correct
52 Correct 185 ms 431032 KB Output is correct
53 Correct 183 ms 430952 KB Output is correct
54 Correct 179 ms 430924 KB Output is correct
55 Correct 178 ms 430964 KB Output is correct
56 Correct 184 ms 430924 KB Output is correct
57 Correct 183 ms 431000 KB Output is correct
58 Correct 181 ms 431036 KB Output is correct
59 Correct 182 ms 431176 KB Output is correct
60 Correct 184 ms 430960 KB Output is correct
61 Correct 1257 ms 444388 KB Output is correct
62 Correct 1220 ms 446080 KB Output is correct
63 Correct 1267 ms 450508 KB Output is correct
64 Correct 1227 ms 446040 KB Output is correct
65 Correct 1279 ms 451168 KB Output is correct
66 Correct 1288 ms 450592 KB Output is correct
67 Correct 1249 ms 446540 KB Output is correct
68 Correct 1213 ms 446520 KB Output is correct
69 Correct 1283 ms 444388 KB Output is correct
70 Correct 1395 ms 445460 KB Output is correct
71 Correct 1240 ms 446372 KB Output is correct
72 Correct 1250 ms 451504 KB Output is correct
73 Correct 1308 ms 446612 KB Output is correct
74 Correct 1295 ms 446788 KB Output is correct
75 Correct 1231 ms 446872 KB Output is correct
76 Correct 1247 ms 446840 KB Output is correct
77 Correct 1295 ms 446752 KB Output is correct
78 Correct 1315 ms 446664 KB Output is correct
79 Correct 1233 ms 446640 KB Output is correct
80 Correct 1237 ms 446524 KB Output is correct