Submission #872041

# Submission time Handle Problem Language Result Execution time Memory
872041 2023-11-12T07:36:26 Z Nonoze Catfish Farm (IOI22_fish) C++17
32 / 100
1000 ms 128720 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<pair<int, 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;
	int empl1=0, empl2=0, empl3=0;
	int sz1=(empl?values[empl-1].size():0), sz2=values[empl].size(), sz3=(empl+1<n?values[empl+1].size():0);
	while (empl1<sz1 || empl2<sz2 || empl3<sz3) {
		int i=LLONG_MAX, indice=1;
		if (empl2<sz2 && values[empl][empl2].first<i) {
			i=values[empl][empl2].first;
			indice=2;
		}
		if (empl1<sz1 && values[empl-1][empl1].first<i) {
			i=values[empl-1][empl1].first;
			indice=1;
		}
		if (empl3<sz3 && values[empl+1][empl3].first<i) {
			i=values[empl+1][empl3].first;
			indice=3;
		}
		if (indice==1) {
			if (pretake<i+1 && take<i+1) {
				sum+=values[empl-1][empl1].second;
			}
			empl1++;
		} else if (indice==2) {
			if (take>=i+1) {
				sum-=values[empl][empl2].second;
			}
			empl2++;
		} else {
			sum+=values[empl+1][empl3].second;
			empl3++;
		}
		ans=max(ans, dp(empl+1, i+1, take)+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;
	for (int i = 0; i < m; ++i)
	{
		if (x[i]%2) tacha=false;
		if (x[i]>1) tachb=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);
	for (int i=0; i<m; i++) {
		values[x[i]].push_back({y[i], w[i]});
	}
	for (int i=0; i<n; i++) {
		sort(values[i].begin(), values[i].end());
	}
	return dp(0, 0, 0);
	#undef int
}
# Verdict Execution time Memory Grader output
1 Correct 17 ms 3164 KB Output is correct
2 Correct 22 ms 4288 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 65 ms 13652 KB Output is correct
6 Correct 68 ms 13908 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 39 ms 9416 KB Output is correct
3 Correct 48 ms 12876 KB Output is correct
4 Correct 22 ms 3552 KB Output is correct
5 Correct 23 ms 4292 KB Output is correct
6 Correct 0 ms 348 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 348 KB Output is correct
12 Correct 20 ms 7572 KB Output is correct
13 Correct 26 ms 9028 KB Output is correct
14 Correct 20 ms 7580 KB Output is correct
15 Correct 22 ms 8436 KB Output is correct
16 Correct 21 ms 7568 KB Output is correct
17 Correct 25 ms 8372 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 29 ms 29144 KB Output is correct
3 Correct 121 ms 44004 KB Output is correct
4 Correct 125 ms 42064 KB Output is correct
5 Correct 354 ms 59192 KB Output is correct
6 Correct 354 ms 58928 KB Output is correct
7 Correct 384 ms 59372 KB Output is correct
8 Correct 354 ms 59476 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 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 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 4 ms 604 KB Output is correct
10 Correct 61 ms 2384 KB Output is correct
11 Correct 23 ms 1364 KB Output is correct
12 Correct 30 ms 1816 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 13 ms 1108 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 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 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 4 ms 604 KB Output is correct
10 Correct 61 ms 2384 KB Output is correct
11 Correct 23 ms 1364 KB Output is correct
12 Correct 30 ms 1816 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 13 ms 1108 KB Output is correct
15 Correct 2 ms 860 KB Output is correct
16 Execution timed out 1074 ms 5236 KB Time limit exceeded
17 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 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 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 4 ms 604 KB Output is correct
10 Correct 61 ms 2384 KB Output is correct
11 Correct 23 ms 1364 KB Output is correct
12 Correct 30 ms 1816 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 13 ms 1108 KB Output is correct
15 Correct 2 ms 860 KB Output is correct
16 Execution timed out 1074 ms 5236 KB Time limit exceeded
17 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 29 ms 29144 KB Output is correct
3 Correct 121 ms 44004 KB Output is correct
4 Correct 125 ms 42064 KB Output is correct
5 Correct 354 ms 59192 KB Output is correct
6 Correct 354 ms 58928 KB Output is correct
7 Correct 384 ms 59372 KB Output is correct
8 Correct 354 ms 59476 KB Output is correct
9 Execution timed out 1033 ms 128720 KB Time limit exceeded
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 17 ms 3164 KB Output is correct
2 Correct 22 ms 4288 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 65 ms 13652 KB Output is correct
6 Correct 68 ms 13908 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 39 ms 9416 KB Output is correct
9 Correct 48 ms 12876 KB Output is correct
10 Correct 22 ms 3552 KB Output is correct
11 Correct 23 ms 4292 KB Output is correct
12 Correct 0 ms 348 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 348 KB Output is correct
18 Correct 20 ms 7572 KB Output is correct
19 Correct 26 ms 9028 KB Output is correct
20 Correct 20 ms 7580 KB Output is correct
21 Correct 22 ms 8436 KB Output is correct
22 Correct 21 ms 7568 KB Output is correct
23 Correct 25 ms 8372 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 29 ms 29144 KB Output is correct
26 Correct 121 ms 44004 KB Output is correct
27 Correct 125 ms 42064 KB Output is correct
28 Correct 354 ms 59192 KB Output is correct
29 Correct 354 ms 58928 KB Output is correct
30 Correct 384 ms 59372 KB Output is correct
31 Correct 354 ms 59476 KB Output is correct
32 Correct 0 ms 344 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 1 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 348 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 4 ms 604 KB Output is correct
41 Correct 61 ms 2384 KB Output is correct
42 Correct 23 ms 1364 KB Output is correct
43 Correct 30 ms 1816 KB Output is correct
44 Correct 1 ms 348 KB Output is correct
45 Correct 13 ms 1108 KB Output is correct
46 Correct 2 ms 860 KB Output is correct
47 Execution timed out 1074 ms 5236 KB Time limit exceeded
48 Halted 0 ms 0 KB -