Submission #871735

# Submission time Handle Problem Language Result Execution time Memory
871735 2023-11-11T12:07:53 Z Nonoze Catfish Farm (IOI22_fish) C++17
32 / 100
1000 ms 1702960 KB
#include "fish.h"
//#include "grader.cpp"

#include <bits/stdc++.h>
using namespace std;
#define int long long

map<pair<int, pair<int, int>>, int> memo;
vector<vector<int>> values;
int n;
int mini=0;

int dp(int empl, int take, int pretake) {
	if (empl>=n) return 0;
	if (memo.count({empl, {take, pretake}})) return memo[{empl, {take, pretake}}];
	int ans=dp(empl+1, 0, take);
	int sum=0;
	for (int i=0; i<mini; i++) {
		int temp=dp(empl+1, i+1, take);
		if (pretake<i+1 && take<i+1 && empl>0) {
			sum+=values[empl-1][i];
		}
		if (empl+1<n) sum+=values[empl+1][i];
		if (take>=i+1) sum-=values[empl][i];
		ans=max(ans, temp+sum);
	}
	return memo[{empl, {take, pretake}}]=ans;
}

#undef int
long long max_weights(int N, int m, vector<int> x, vector<int> y, vector<int> w) {
	#define int long long
	n=N;
	bool tacha=true, tachb=true, tachc=true;
	for (int i = 0; i < m; ++i)
	{
		if (x[i]%2) tacha=false;
		if (x[i]>1) tachb=false;
		if (y[i]) tachc=false;
	}
	if (tacha)
	{
		int ans=0;
		for (int i = 0; i < m; ++i) ans+=w[i];
		return ans;
	}
	if (tachb)
	{
		vector<vector<int>> farm(2, vector<int> (n, 0));
		for (int i=0; i<m; i++) {
			farm[x[i]][y[i]]=w[i];
		}
		vector<int> suml, sumr;
		suml.push_back(farm[0][0]);
		sumr.push_back(farm[1][0]);
		for (int i=1; i<n; i++) {
			suml.push_back(suml.back()+farm[0][i]);
			sumr.push_back(sumr.back()+farm[1][i]);
		}
		if (n==2) return max(suml.back(), sumr.back());
		int ans=sumr.back();
		for (int i=0; i<n; i++) {
			ans=max(ans, suml[i]+sumr.back()-sumr[i]);
		}
		return ans;
	}
	mini=0;
	for (int i=0; i<m; i++) {
		mini=max(mini, (long long) y[i]);
	}
	mini++;
	values.resize(n, vector<int>(mini, 0));
	for (int i=0; i<m; i++) {
		values[x[i]][y[i]]=w[i];
	}
	return dp(0, 0, 0);
	#undef int
}

Compilation message

fish.cpp: In function 'long long int max_weights(int, int, std::vector<int>, std::vector<int>, std::vector<int>)':
fish.cpp:34:31: warning: variable 'tachc' set but not used [-Wunused-but-set-variable]
   34 |  bool tacha=true, tachb=true, tachc=true;
      |                               ^~~~~
# Verdict Execution time Memory Grader output
1 Correct 18 ms 2140 KB Output is correct
2 Correct 21 ms 2648 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 66 ms 7276 KB Output is correct
6 Correct 68 ms 7288 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 37 ms 8044 KB Output is correct
3 Correct 51 ms 9540 KB Output is correct
4 Correct 17 ms 2140 KB Output is correct
5 Correct 22 ms 2640 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 19 ms 6076 KB Output is correct
13 Correct 23 ms 7236 KB Output is correct
14 Correct 20 ms 6072 KB Output is correct
15 Correct 24 ms 6988 KB Output is correct
16 Correct 20 ms 6044 KB Output is correct
17 Correct 26 ms 6860 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 182 ms 54392 KB Output is correct
3 Correct 217 ms 51060 KB Output is correct
4 Correct 183 ms 55680 KB Output is correct
5 Correct 196 ms 58196 KB Output is correct
6 Correct 211 ms 57684 KB Output is correct
7 Correct 200 ms 58192 KB Output is correct
8 Correct 196 ms 58280 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 2 ms 604 KB Output is correct
10 Correct 20 ms 2356 KB Output is correct
11 Correct 11 ms 1440 KB Output is correct
12 Correct 21 ms 2400 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 10 ms 1632 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 2 ms 604 KB Output is correct
10 Correct 20 ms 2356 KB Output is correct
11 Correct 11 ms 1440 KB Output is correct
12 Correct 21 ms 2400 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 10 ms 1632 KB Output is correct
15 Execution timed out 1051 ms 9800 KB Time limit exceeded
16 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 2 ms 604 KB Output is correct
10 Correct 20 ms 2356 KB Output is correct
11 Correct 11 ms 1440 KB Output is correct
12 Correct 21 ms 2400 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 10 ms 1632 KB Output is correct
15 Execution timed out 1051 ms 9800 KB Time limit exceeded
16 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 182 ms 54392 KB Output is correct
3 Correct 217 ms 51060 KB Output is correct
4 Correct 183 ms 55680 KB Output is correct
5 Correct 196 ms 58196 KB Output is correct
6 Correct 211 ms 57684 KB Output is correct
7 Correct 200 ms 58192 KB Output is correct
8 Correct 196 ms 58280 KB Output is correct
9 Execution timed out 1213 ms 1702960 KB Time limit exceeded
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 18 ms 2140 KB Output is correct
2 Correct 21 ms 2648 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 66 ms 7276 KB Output is correct
6 Correct 68 ms 7288 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 37 ms 8044 KB Output is correct
9 Correct 51 ms 9540 KB Output is correct
10 Correct 17 ms 2140 KB Output is correct
11 Correct 22 ms 2640 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 344 KB Output is correct
18 Correct 19 ms 6076 KB Output is correct
19 Correct 23 ms 7236 KB Output is correct
20 Correct 20 ms 6072 KB Output is correct
21 Correct 24 ms 6988 KB Output is correct
22 Correct 20 ms 6044 KB Output is correct
23 Correct 26 ms 6860 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 182 ms 54392 KB Output is correct
26 Correct 217 ms 51060 KB Output is correct
27 Correct 183 ms 55680 KB Output is correct
28 Correct 196 ms 58196 KB Output is correct
29 Correct 211 ms 57684 KB Output is correct
30 Correct 200 ms 58192 KB Output is correct
31 Correct 196 ms 58280 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 1 ms 348 KB Output is correct
34 Correct 1 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 0 ms 348 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 0 ms 344 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 2 ms 604 KB Output is correct
41 Correct 20 ms 2356 KB Output is correct
42 Correct 11 ms 1440 KB Output is correct
43 Correct 21 ms 2400 KB Output is correct
44 Correct 1 ms 344 KB Output is correct
45 Correct 10 ms 1632 KB Output is correct
46 Execution timed out 1051 ms 9800 KB Time limit exceeded
47 Halted 0 ms 0 KB -