Submission #627348

# Submission time Handle Problem Language Result Execution time Memory
627348 2022-08-12T13:21:32 Z minhcool Catfish Farm (IOI22_fish) C++17
53 / 100
1000 ms 230304 KB
#include<bits/stdc++.h>
using namespace std;

//#define int long long
#define ll long long
#define fi first
#define se second
#define pb push_back
//#define mp make_pair
#define foru(i, l, r) for(int i = l; i <= r; i++)
#define ford(i, r, l) for(int i = r; i >= l; i--)

typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef pair<ii, ii> iiii;

const int N = 3e5 + 5;

const ll oo = 1e18 + 7, mod = 1e9 + 7;

ll n, m;
ll x[N], y[N], w[N];

ll solve1(){
	ll tol = 0;
	for(int i = 1; i <= m; i++) tol += w[i];
	return tol;
}

map<ii, ll> mp;

ll solve2(){
	for(int i = 1; i <= m; i++) mp[{x[i], y[i]}] = w[i];
	if(n >= 3){
		ll mx = -1, total = 0;
		for(int i = 1; i <= n; i++) total += mp[{2, i}];
		mx = total;
		for(int i = 1; i <= n; i++){
			total += (mp[{1, i}] - mp[{2, i}]);
			mx = max(mx, total);
		}
		return mx;
	}
	else{
		return max(mp[{1, 1}] + mp[{1, 2}], mp[{2, 1}] + mp[{2, 2}]);
	}
}

ll dp1[N][2][2];

ll solve3(){
	//cout << "OK\n";
	for(int i = 1; i <= m; i++) mp[{x[i], y[i]}] = w[i];
	for(int i = 1; i <= n; i++){
		for(int j = 0; j < 2; j++){
			for(int k = 0; k < 2; k++) dp1[i][j][k] = -oo;
		}
	}
	dp1[1][0][0] = dp1[1][1][0] = 0;
	for(int i = 2; i <= (n + 1); i++){
		for(int j = 0; j < 2; j++){
			if(i == (n + 1) && j) break;
			for(int k = 0; k < 2; k++){
				for(int h = 0; h < 2; h++){
					dp1[i][j][k] = max(dp1[i][j][k], dp1[i - 1][k][h] + mp[{i - 1, 1}] * (!k && (j | h)));
				}
				//cout << i << " " << j << " " << k << " " << dp1[i][j][k] << "\n";
			}
		}
	}
	return max(dp1[n + 1][0][0], dp1[n + 1][0][1]);
}

ll dp2[305][305][305];
ll cell[305][305];

ll solve4_5(){
	for(int i = 1; i <= m; i++) cell[x[i]][y[i]] = w[i];
	/*
	for(int i = 1; i <= n; i++){
		for(int j = 1; j <= n; j++) cout << cell[i][j] << " ";
		cout << "\n";
	}*/
	for(int i = 1; i <= n; i++){
		for(int j = 0; j <= n; j++){
			for(int k = 0; k <= n; k++) dp2[i][j][k] = -oo;
		}
	}
	for(int i = 0; i <= n; i++) dp2[1][i][0] = 0;
	//cout << "OK\n";
	/*
	j >= max(i, k) => j = n, b/c why not?
	j <= min(i, k) => j = 0, b/c why not?
	i > j >= k => (i, j) = f(i, j) + max(dp[-1][j][0 -> j])
	i < j <= k => (i, j) = f(i, j) + max(dp[-1][j][j -> k] + f(j, j -> k))
	*/
	for(int r = 2; r <= (n + 1); r++){
		// j = n
		for(int i = 0; i <= n; i++){
			for(int k = 0; k <= n; k++){
				dp2[r][i][n] = max(dp2[r][i][n], dp2[r - 1][n][k]);
			}
		}
		// j = 0
		ll pref = 0;
		for(int i = 0; i <= n; i++){
			pref += cell[r - 1][i];
			ll pref2 = pref;
			for(int k = 0; k <= n; k++){
				if(k > i) pref2 += cell[r - 1][k];
				dp2[r][i][0] = max(dp2[r][i][0], dp2[r - 1][0][k] + pref2);
				//cout << i << " " << k << " " << dp2[r - 1][0][k] + pref2 << "\n";
			}
		}
		// i > j >= k
		for(int j = 0; j <= n; j++){
			ll pref = 0;
			for(int k = 0; k < j; k++) pref = max(pref, dp2[r - 1][j][k]);
			for(int i = j + 1; i <= n; i++){
				pref += cell[r - 1][i];
				dp2[r][i][j] = max(dp2[r][i][j], pref);
			}
		}
		for(int j = 0; j <= n; j++){
			ll mx = 0, pref = 0;
			for(int k = j + 1; k <= n; k++){
				pref += cell[r - 1][k];
				mx = max(mx, dp2[r - 1][j][k] + pref);
			}
			for(int i = 0; i < j; i++) dp2[r][i][j] = max(dp2[r][i][j], mx);
		}
		/*
		for(int i = 0; i <= n; i++){
			for(int j = 0; j <= n; j++) cout << r << " " << i << " " << j << " " << dp2[r][i][j] << "\n";
		}*/
	}
	ll mx = -1;
	for(int i = 0; i <= n; i++) mx = max(mx, dp2[n + 1][0][i]);
	return mx;
}

ll dp3[N][11][11];

vector<int> cells[N];

ll solve7(){
	for(int i = 1; i <= m; i++){
		mp[{x[i], y[i]}] = y[i];
		for(int j = max(1LL, x[i] - 1); j <= min(n, x[i] + 1); j++){
			cells[j].pb(y[i]);
		}
	}
	for(int i = 1; i <= n; i++){
		cells[i].pb(0);
		sort(cells[i].begin(), cells[i].end());
		cells[i].resize(unique(cells[i].begin(), cells[i].end()) - cells[i].begin());
	}
	/*
	for(int i = 1; i <= n + 1; i++){
		for(int j = 0; j <= 6; j++){
			for(int k = 0; k <= 6; k++) cells[j][k] = 
		}
	}*/
	for(int i = 0; i <= cells[1].size(); i++) dp3[1][i][0] = 0;
	for(int r = 2; r <= (n + 1); r++){
		// j = n
		for(int i = 0; i <= n; i++){
			for(int k = 0; k <= n; k++){
				dp2[r][i][n] = max(dp2[r][i][n], dp2[r - 1][n][k]);
			}
		}
		// j = 0
		ll pref = 0;
		for(int i = 0; i <= n; i++){
			pref += cell[r - 1][i];
			ll pref2 = pref;
			for(int k = 0; k <= n; k++){
				if(k > i) pref2 += cell[r - 1][k];
				dp2[r][i][0] = max(dp2[r][i][0], dp2[r - 1][0][k] + pref2);
				//cout << i << " " << k << " " << dp2[r - 1][0][k] + pref2 << "\n";
			}
		}
		// i > j >= k
		for(int j = 0; j <= n; j++){
			ll pref = 0;
			for(int k = 0; k < j; k++) pref = max(pref, dp2[r - 1][j][k]);
			for(int i = j + 1; i <= n; i++){
				pref += cell[r - 1][i];
				dp2[r][i][j] = max(dp2[r][i][j], pref);
			}
		}
		for(int j = 0; j <= n; j++){
			ll mx = 0, pref = 0;
			for(int k = j + 1; k <= n; k++){
				pref += cell[r - 1][k];
				mx = max(mx, dp2[r - 1][j][k] + pref);
			}
			for(int i = 0; i < j; i++) dp2[r][i][j] = max(dp2[r][i][j], mx);
		}
	}
}

ll max_weights(int _n, int _m, vector<int> _x, vector<int> _y, vector<int> _w){
	n = _n, m = _m;
	for(int i = 1; i <= m; i++){
		x[i] = _x[i - 1] + 1, y[i] = _y[i - 1] + 1, w[i] = _w[i - 1];
		//cout << x[i] << " " << y[i] << " " << w[i] << "\n";
	}
	bool ck = 1;
	for(int i = 1; i <= m; i++) ck &= (x[i] % 2);
	if(ck) return solve1();
	ck = 1;
	for(int i = 1; i <= m; i++) ck &= (x[i] <= 2);
	if(ck) return solve2();
	ck = 1;
	for(int i = 1; i <= m; i++) ck &= (y[i] == 1);
	if(ck) return solve3();
	ck = (n <= 300);
	if(ck) return solve4_5();
	return solve7();
	//assert(0);
}
/*
void process(){
	int n, m;
	vector<int> a, b, c;
	cin >> n >> m;
	for(int i = 1; i <= m; i++){
		int x, y, z;
		cin >> x >> y >> z;
		a.pb(x), b.pb(y), c.pb(z);
	}
	cout << max_weights(n, m, a, b, c) << "\n";
}

signed main(){
	ios_base::sync_with_stdio(0);
	freopen("fish.inp", "r", stdin);
	freopen("fish.out", "w", stdout);
	//cout << "OK\n";
	//return 0;
	process();
}*/

Compilation message

fish.cpp: In function 'long long int solve7()':
fish.cpp:164:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  164 |  for(int i = 0; i <= cells[1].size(); i++) dp3[1][i][0] = 0;
      |                 ~~^~~~~~~~~~~~~~~~~~
fish.cpp:201:1: warning: no return statement in function returning non-void [-Wreturn-type]
  201 | }
      | ^
# Verdict Execution time Memory Grader output
1 Correct 26 ms 11212 KB Output is correct
2 Correct 32 ms 12364 KB Output is correct
3 Correct 4 ms 7252 KB Output is correct
4 Correct 4 ms 7380 KB Output is correct
5 Correct 92 ms 22132 KB Output is correct
6 Correct 104 ms 22140 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 7380 KB Output is correct
2 Correct 155 ms 26188 KB Output is correct
3 Correct 190 ms 29600 KB Output is correct
4 Correct 30 ms 11500 KB Output is correct
5 Correct 32 ms 12376 KB Output is correct
6 Correct 4 ms 7276 KB Output is correct
7 Correct 4 ms 7364 KB Output is correct
8 Correct 5 ms 7324 KB Output is correct
9 Correct 5 ms 7380 KB Output is correct
10 Correct 5 ms 7268 KB Output is correct
11 Correct 5 ms 7380 KB Output is correct
12 Correct 104 ms 22844 KB Output is correct
13 Correct 113 ms 24988 KB Output is correct
14 Correct 97 ms 22756 KB Output is correct
15 Correct 128 ms 24524 KB Output is correct
16 Correct 101 ms 22804 KB Output is correct
17 Correct 115 ms 24412 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 7380 KB Output is correct
2 Correct 106 ms 16724 KB Output is correct
3 Correct 74 ms 18240 KB Output is correct
4 Correct 93 ms 18388 KB Output is correct
5 Correct 108 ms 21388 KB Output is correct
6 Correct 108 ms 21584 KB Output is correct
7 Correct 109 ms 21368 KB Output is correct
8 Correct 122 ms 21452 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 7380 KB Output is correct
2 Correct 4 ms 7508 KB Output is correct
3 Correct 4 ms 7252 KB Output is correct
4 Correct 3 ms 7252 KB Output is correct
5 Correct 4 ms 7380 KB Output is correct
6 Correct 4 ms 7252 KB Output is correct
7 Correct 4 ms 7328 KB Output is correct
8 Correct 4 ms 7380 KB Output is correct
9 Correct 46 ms 62628 KB Output is correct
10 Correct 216 ms 225668 KB Output is correct
11 Correct 46 ms 62636 KB Output is correct
12 Correct 219 ms 225740 KB Output is correct
13 Correct 13 ms 21568 KB Output is correct
14 Correct 215 ms 225568 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 7380 KB Output is correct
2 Correct 4 ms 7508 KB Output is correct
3 Correct 4 ms 7252 KB Output is correct
4 Correct 3 ms 7252 KB Output is correct
5 Correct 4 ms 7380 KB Output is correct
6 Correct 4 ms 7252 KB Output is correct
7 Correct 4 ms 7328 KB Output is correct
8 Correct 4 ms 7380 KB Output is correct
9 Correct 46 ms 62628 KB Output is correct
10 Correct 216 ms 225668 KB Output is correct
11 Correct 46 ms 62636 KB Output is correct
12 Correct 219 ms 225740 KB Output is correct
13 Correct 13 ms 21568 KB Output is correct
14 Correct 215 ms 225568 KB Output is correct
15 Correct 225 ms 225528 KB Output is correct
16 Correct 14 ms 21588 KB Output is correct
17 Correct 238 ms 227788 KB Output is correct
18 Correct 230 ms 227824 KB Output is correct
19 Correct 231 ms 228052 KB Output is correct
20 Correct 243 ms 228016 KB Output is correct
21 Correct 229 ms 228044 KB Output is correct
22 Correct 244 ms 230304 KB Output is correct
23 Correct 221 ms 226096 KB Output is correct
24 Correct 245 ms 227304 KB Output is correct
25 Correct 231 ms 225580 KB Output is correct
26 Correct 223 ms 226044 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 7380 KB Output is correct
2 Correct 4 ms 7508 KB Output is correct
3 Correct 4 ms 7252 KB Output is correct
4 Correct 3 ms 7252 KB Output is correct
5 Correct 4 ms 7380 KB Output is correct
6 Correct 4 ms 7252 KB Output is correct
7 Correct 4 ms 7328 KB Output is correct
8 Correct 4 ms 7380 KB Output is correct
9 Correct 46 ms 62628 KB Output is correct
10 Correct 216 ms 225668 KB Output is correct
11 Correct 46 ms 62636 KB Output is correct
12 Correct 219 ms 225740 KB Output is correct
13 Correct 13 ms 21568 KB Output is correct
14 Correct 215 ms 225568 KB Output is correct
15 Correct 225 ms 225528 KB Output is correct
16 Correct 14 ms 21588 KB Output is correct
17 Correct 238 ms 227788 KB Output is correct
18 Correct 230 ms 227824 KB Output is correct
19 Correct 231 ms 228052 KB Output is correct
20 Correct 243 ms 228016 KB Output is correct
21 Correct 229 ms 228044 KB Output is correct
22 Correct 244 ms 230304 KB Output is correct
23 Correct 221 ms 226096 KB Output is correct
24 Correct 245 ms 227304 KB Output is correct
25 Correct 231 ms 225580 KB Output is correct
26 Correct 223 ms 226044 KB Output is correct
27 Execution timed out 1081 ms 28776 KB Time limit exceeded
28 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 7380 KB Output is correct
2 Correct 106 ms 16724 KB Output is correct
3 Correct 74 ms 18240 KB Output is correct
4 Correct 93 ms 18388 KB Output is correct
5 Correct 108 ms 21388 KB Output is correct
6 Correct 108 ms 21584 KB Output is correct
7 Correct 109 ms 21368 KB Output is correct
8 Correct 122 ms 21452 KB Output is correct
9 Runtime error 113 ms 28748 KB Execution killed with signal 11
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 26 ms 11212 KB Output is correct
2 Correct 32 ms 12364 KB Output is correct
3 Correct 4 ms 7252 KB Output is correct
4 Correct 4 ms 7380 KB Output is correct
5 Correct 92 ms 22132 KB Output is correct
6 Correct 104 ms 22140 KB Output is correct
7 Correct 4 ms 7380 KB Output is correct
8 Correct 155 ms 26188 KB Output is correct
9 Correct 190 ms 29600 KB Output is correct
10 Correct 30 ms 11500 KB Output is correct
11 Correct 32 ms 12376 KB Output is correct
12 Correct 4 ms 7276 KB Output is correct
13 Correct 4 ms 7364 KB Output is correct
14 Correct 5 ms 7324 KB Output is correct
15 Correct 5 ms 7380 KB Output is correct
16 Correct 5 ms 7268 KB Output is correct
17 Correct 5 ms 7380 KB Output is correct
18 Correct 104 ms 22844 KB Output is correct
19 Correct 113 ms 24988 KB Output is correct
20 Correct 97 ms 22756 KB Output is correct
21 Correct 128 ms 24524 KB Output is correct
22 Correct 101 ms 22804 KB Output is correct
23 Correct 115 ms 24412 KB Output is correct
24 Correct 5 ms 7380 KB Output is correct
25 Correct 106 ms 16724 KB Output is correct
26 Correct 74 ms 18240 KB Output is correct
27 Correct 93 ms 18388 KB Output is correct
28 Correct 108 ms 21388 KB Output is correct
29 Correct 108 ms 21584 KB Output is correct
30 Correct 109 ms 21368 KB Output is correct
31 Correct 122 ms 21452 KB Output is correct
32 Correct 4 ms 7380 KB Output is correct
33 Correct 4 ms 7508 KB Output is correct
34 Correct 4 ms 7252 KB Output is correct
35 Correct 3 ms 7252 KB Output is correct
36 Correct 4 ms 7380 KB Output is correct
37 Correct 4 ms 7252 KB Output is correct
38 Correct 4 ms 7328 KB Output is correct
39 Correct 4 ms 7380 KB Output is correct
40 Correct 46 ms 62628 KB Output is correct
41 Correct 216 ms 225668 KB Output is correct
42 Correct 46 ms 62636 KB Output is correct
43 Correct 219 ms 225740 KB Output is correct
44 Correct 13 ms 21568 KB Output is correct
45 Correct 215 ms 225568 KB Output is correct
46 Correct 225 ms 225528 KB Output is correct
47 Correct 14 ms 21588 KB Output is correct
48 Correct 238 ms 227788 KB Output is correct
49 Correct 230 ms 227824 KB Output is correct
50 Correct 231 ms 228052 KB Output is correct
51 Correct 243 ms 228016 KB Output is correct
52 Correct 229 ms 228044 KB Output is correct
53 Correct 244 ms 230304 KB Output is correct
54 Correct 221 ms 226096 KB Output is correct
55 Correct 245 ms 227304 KB Output is correct
56 Correct 231 ms 225580 KB Output is correct
57 Correct 223 ms 226044 KB Output is correct
58 Execution timed out 1081 ms 28776 KB Time limit exceeded
59 Halted 0 ms 0 KB -