답안 #1028570

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1028570 2024-07-20T05:07:19 Z TrieTr Netrpeljivost (COI23_netrpeljivost) C++14
100 / 100
1197 ms 164608 KB
#include<bits/stdc++.h>
using namespace std;

void local() {
    #define taskname ""
    if (fopen(taskname".inp", "r")) {
        freopen(taskname".inp", "r", stdin);
        freopen(taskname".out", "w", stdout);
    }
}

#define ll long long
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

template<class X, class Y> bool mini(X &a, const Y &b) {return (a > b) ? a = b, true : false;}
template<class X, class Y> bool maxi(X &a, const Y &b) {return (a < b) ? a = b, true : false;}

const int N = 3e3 + 5;

int n;
ll a[N][N];

namespace sub1 {
	bool check() {
		return n <= 16;
	}
	ll solve(int st, int en, int l, int r) {
		int mid = (l + r) >> 1;
		if((st <= mid && en <= mid) || (st > mid && en > mid)) return 1e18;
		if(r - l == 1) {
			return a[st][en];
		}
		ll res = 1e18;
		for(int i = l; i <= mid; i++) {
			for(int j = mid + 1; j <= r; j++) {
				if(st <= mid) {
					mini(res, a[i][j] + solve(st, i, l, mid) + solve(j, en, mid + 1, r));
				}
				else {
					mini(res, a[i][j] + solve(st, j, mid + 1, r) + solve(i, en, l, mid));
				}
			}
		}
		return res;
	}
	void solve() {
		ll res = 1e18;
	    for(int i = 1; i <= n / 2; i++) {
	    	for(int j = n / 2 + 1; j <= n; j++) {
	    		mini(res, solve(i, j, 1, n));
	    		mini(res, solve(j, i, 1, n));
	    	}
	    }
	    cout << res;
	}
}
namespace sub4 {
	ll dp[N][N], cur[N][N];
	void solve(int l, int r) {
		if(r - l == 1) {
			dp[l][r] = dp[r][l] = a[l][r];
			return;
		}
		int mid = (l + r) >> 1, mid1 = (l + mid) >> 1, mid2 = (mid + 1 + r) >> 1;
		solve(l, mid); solve(mid + 1, r);
		for(int i1 = l; i1 <= mid1; i1++) {
			for(int i2 = mid1 + 1; i2 <= mid; i2++) {
				for(int j = mid + 1; j <= r; j++) {
					mini(cur[i1][j], dp[i1][i2] + a[i2][j]);
					mini(cur[i2][j], dp[i1][i2] + a[i1][j]);
				}
			}
		}
		for(int i = l; i <= mid; i++) {
			for(int j1 = mid + 1; j1 <= mid2; j1++) {
				for(int j2 = mid2 + 1; j2 <= r; j2++) {
					mini(dp[i][j1], cur[i][j2] + dp[j1][j2]);
					mini(dp[i][j2], cur[i][j1] + dp[j1][j2]);
				}
			}
		}
	}
	void solve() {
		ll res = 1e18;
		for(int i = 1; i <= n; i++) {
			for(int j = 1; j <= n; j++) {
				dp[i][j] = 1e18;
				cur[i][j] = 1e18;
			}
		}
		for(int i = 1; i <= n; i++) a[i][i] = 1e18;
		solve(1, n);
	    for(int i = 1; i <= n / 2; i++) {
	    	for(int j = n / 2 + 1; j <= n; j++) {
	    		mini(res, dp[i][j]);
	    	}
	    }
	    cout << res;
	}
}


int main() {
    fastio; local();
    cin >> n;
    for(int i = 1; i <= n; i++) {
    	for(int j = 1; j <= n; j++) {
    		cin >> a[i][j];
    	}
    }
    sub4::solve();
}

Compilation message

Main.cpp: In function 'void local()':
Main.cpp:7:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    7 |         freopen(taskname".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:8:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    8 |         freopen(taskname".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 600 KB Output is correct
2 Correct 0 ms 604 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 0 ms 604 KB Output is correct
5 Correct 0 ms 600 KB Output is correct
6 Correct 0 ms 604 KB Output is correct
7 Correct 0 ms 604 KB Output is correct
8 Correct 0 ms 604 KB Output is correct
9 Correct 0 ms 604 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Correct 1 ms 472 KB Output is correct
12 Correct 0 ms 604 KB Output is correct
13 Correct 1 ms 656 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Correct 0 ms 604 KB Output is correct
16 Correct 0 ms 604 KB Output is correct
17 Correct 0 ms 604 KB Output is correct
18 Correct 0 ms 604 KB Output is correct
19 Correct 0 ms 604 KB Output is correct
20 Correct 0 ms 604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 600 KB Output is correct
2 Correct 0 ms 604 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 0 ms 604 KB Output is correct
5 Correct 0 ms 600 KB Output is correct
6 Correct 0 ms 604 KB Output is correct
7 Correct 0 ms 604 KB Output is correct
8 Correct 0 ms 604 KB Output is correct
9 Correct 0 ms 604 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Correct 1 ms 472 KB Output is correct
12 Correct 0 ms 604 KB Output is correct
13 Correct 1 ms 656 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Correct 0 ms 604 KB Output is correct
16 Correct 0 ms 604 KB Output is correct
17 Correct 0 ms 604 KB Output is correct
18 Correct 0 ms 604 KB Output is correct
19 Correct 0 ms 604 KB Output is correct
20 Correct 0 ms 604 KB Output is correct
21 Correct 2 ms 2396 KB Output is correct
22 Correct 2 ms 2396 KB Output is correct
23 Correct 2 ms 2396 KB Output is correct
24 Correct 1 ms 1372 KB Output is correct
25 Correct 1 ms 1372 KB Output is correct
26 Correct 2 ms 2396 KB Output is correct
27 Correct 2 ms 2396 KB Output is correct
28 Correct 2 ms 2392 KB Output is correct
29 Correct 2 ms 2396 KB Output is correct
30 Correct 4 ms 2372 KB Output is correct
31 Correct 2 ms 2396 KB Output is correct
32 Correct 2 ms 2396 KB Output is correct
33 Correct 2 ms 2396 KB Output is correct
34 Correct 3 ms 2396 KB Output is correct
35 Correct 2 ms 2476 KB Output is correct
36 Correct 2 ms 2396 KB Output is correct
37 Correct 2 ms 2396 KB Output is correct
38 Correct 2 ms 2396 KB Output is correct
39 Correct 2 ms 2396 KB Output is correct
40 Correct 2 ms 2396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 600 KB Output is correct
2 Correct 0 ms 604 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 0 ms 604 KB Output is correct
5 Correct 0 ms 600 KB Output is correct
6 Correct 0 ms 604 KB Output is correct
7 Correct 0 ms 604 KB Output is correct
8 Correct 0 ms 604 KB Output is correct
9 Correct 0 ms 604 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Correct 1 ms 472 KB Output is correct
12 Correct 0 ms 604 KB Output is correct
13 Correct 1 ms 656 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Correct 0 ms 604 KB Output is correct
16 Correct 0 ms 604 KB Output is correct
17 Correct 0 ms 604 KB Output is correct
18 Correct 0 ms 604 KB Output is correct
19 Correct 0 ms 604 KB Output is correct
20 Correct 0 ms 604 KB Output is correct
21 Correct 2 ms 2396 KB Output is correct
22 Correct 2 ms 2396 KB Output is correct
23 Correct 2 ms 2396 KB Output is correct
24 Correct 1 ms 1372 KB Output is correct
25 Correct 1 ms 1372 KB Output is correct
26 Correct 2 ms 2396 KB Output is correct
27 Correct 2 ms 2396 KB Output is correct
28 Correct 2 ms 2392 KB Output is correct
29 Correct 2 ms 2396 KB Output is correct
30 Correct 4 ms 2372 KB Output is correct
31 Correct 2 ms 2396 KB Output is correct
32 Correct 2 ms 2396 KB Output is correct
33 Correct 2 ms 2396 KB Output is correct
34 Correct 3 ms 2396 KB Output is correct
35 Correct 2 ms 2476 KB Output is correct
36 Correct 2 ms 2396 KB Output is correct
37 Correct 2 ms 2396 KB Output is correct
38 Correct 2 ms 2396 KB Output is correct
39 Correct 2 ms 2396 KB Output is correct
40 Correct 2 ms 2396 KB Output is correct
41 Correct 40 ms 15196 KB Output is correct
42 Correct 39 ms 15184 KB Output is correct
43 Correct 38 ms 15184 KB Output is correct
44 Correct 39 ms 15184 KB Output is correct
45 Correct 48 ms 15072 KB Output is correct
46 Correct 38 ms 15184 KB Output is correct
47 Correct 38 ms 15324 KB Output is correct
48 Correct 43 ms 15188 KB Output is correct
49 Correct 44 ms 15184 KB Output is correct
50 Correct 38 ms 15196 KB Output is correct
51 Correct 35 ms 15276 KB Output is correct
52 Correct 41 ms 15304 KB Output is correct
53 Correct 36 ms 15192 KB Output is correct
54 Correct 38 ms 15196 KB Output is correct
55 Correct 37 ms 15196 KB Output is correct
56 Correct 42 ms 15452 KB Output is correct
57 Correct 40 ms 15352 KB Output is correct
58 Correct 38 ms 15192 KB Output is correct
59 Correct 37 ms 15188 KB Output is correct
60 Correct 47 ms 15184 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 600 KB Output is correct
2 Correct 0 ms 604 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 0 ms 604 KB Output is correct
5 Correct 0 ms 600 KB Output is correct
6 Correct 0 ms 604 KB Output is correct
7 Correct 0 ms 604 KB Output is correct
8 Correct 0 ms 604 KB Output is correct
9 Correct 0 ms 604 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Correct 1 ms 472 KB Output is correct
12 Correct 0 ms 604 KB Output is correct
13 Correct 1 ms 656 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Correct 0 ms 604 KB Output is correct
16 Correct 0 ms 604 KB Output is correct
17 Correct 0 ms 604 KB Output is correct
18 Correct 0 ms 604 KB Output is correct
19 Correct 0 ms 604 KB Output is correct
20 Correct 0 ms 604 KB Output is correct
21 Correct 2 ms 2396 KB Output is correct
22 Correct 2 ms 2396 KB Output is correct
23 Correct 2 ms 2396 KB Output is correct
24 Correct 1 ms 1372 KB Output is correct
25 Correct 1 ms 1372 KB Output is correct
26 Correct 2 ms 2396 KB Output is correct
27 Correct 2 ms 2396 KB Output is correct
28 Correct 2 ms 2392 KB Output is correct
29 Correct 2 ms 2396 KB Output is correct
30 Correct 4 ms 2372 KB Output is correct
31 Correct 2 ms 2396 KB Output is correct
32 Correct 2 ms 2396 KB Output is correct
33 Correct 2 ms 2396 KB Output is correct
34 Correct 3 ms 2396 KB Output is correct
35 Correct 2 ms 2476 KB Output is correct
36 Correct 2 ms 2396 KB Output is correct
37 Correct 2 ms 2396 KB Output is correct
38 Correct 2 ms 2396 KB Output is correct
39 Correct 2 ms 2396 KB Output is correct
40 Correct 2 ms 2396 KB Output is correct
41 Correct 40 ms 15196 KB Output is correct
42 Correct 39 ms 15184 KB Output is correct
43 Correct 38 ms 15184 KB Output is correct
44 Correct 39 ms 15184 KB Output is correct
45 Correct 48 ms 15072 KB Output is correct
46 Correct 38 ms 15184 KB Output is correct
47 Correct 38 ms 15324 KB Output is correct
48 Correct 43 ms 15188 KB Output is correct
49 Correct 44 ms 15184 KB Output is correct
50 Correct 38 ms 15196 KB Output is correct
51 Correct 35 ms 15276 KB Output is correct
52 Correct 41 ms 15304 KB Output is correct
53 Correct 36 ms 15192 KB Output is correct
54 Correct 38 ms 15196 KB Output is correct
55 Correct 37 ms 15196 KB Output is correct
56 Correct 42 ms 15452 KB Output is correct
57 Correct 40 ms 15352 KB Output is correct
58 Correct 38 ms 15192 KB Output is correct
59 Correct 37 ms 15188 KB Output is correct
60 Correct 47 ms 15184 KB Output is correct
61 Correct 1105 ms 164000 KB Output is correct
62 Correct 1188 ms 163868 KB Output is correct
63 Correct 1174 ms 163816 KB Output is correct
64 Correct 1176 ms 163668 KB Output is correct
65 Correct 1177 ms 164180 KB Output is correct
66 Correct 1149 ms 163664 KB Output is correct
67 Correct 1078 ms 163672 KB Output is correct
68 Correct 1101 ms 163928 KB Output is correct
69 Correct 1113 ms 164160 KB Output is correct
70 Correct 1117 ms 163920 KB Output is correct
71 Correct 1014 ms 164368 KB Output is correct
72 Correct 1020 ms 164608 KB Output is correct
73 Correct 991 ms 164348 KB Output is correct
74 Correct 1081 ms 164384 KB Output is correct
75 Correct 1047 ms 164560 KB Output is correct
76 Correct 1139 ms 164556 KB Output is correct
77 Correct 1197 ms 164436 KB Output is correct
78 Correct 1099 ms 164436 KB Output is correct
79 Correct 1056 ms 164372 KB Output is correct
80 Correct 1110 ms 164436 KB Output is correct