답안 #871725

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
871725 2023-11-11T11:51:04 Z Nonoze 메기 농장 (IOI22_fish) C++17
23 / 100
1000 ms 87232 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 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<8; i++) {
		int temp=dp(empl+1, (1<<(i+1))-1, take);
		if ((pretake&(1<<i))!=(1<<i) && (take&(1<<i))!=(1<<i) && empl>0) {
			sum+=values[empl-1][i];
		}
		if (empl+1<n) sum+=values[empl+1][i];
		if ((take&(1<<i))==(1<<i)) 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;
	}
	values.resize(n, vector<int>(8, 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:33:31: warning: variable 'tachc' set but not used [-Wunused-but-set-variable]
   33 |  bool tacha=true, tachb=true, tachc=true;
      |                               ^~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 3676 KB Output is correct
2 Correct 22 ms 4444 KB Output is correct
3 Correct 0 ms 600 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 86 ms 13672 KB Output is correct
6 Correct 71 ms 14036 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 39 ms 10724 KB Output is correct
3 Correct 48 ms 13120 KB Output is correct
4 Correct 18 ms 3676 KB Output is correct
5 Correct 24 ms 4424 KB Output is correct
6 Correct 0 ms 360 KB Output is correct
7 Correct 0 ms 444 KB Output is correct
8 Correct 1 ms 360 KB Output is correct
9 Correct 0 ms 356 KB Output is correct
10 Correct 0 ms 360 KB Output is correct
11 Correct 1 ms 360 KB Output is correct
12 Correct 21 ms 7472 KB Output is correct
13 Correct 25 ms 8892 KB Output is correct
14 Correct 21 ms 7320 KB Output is correct
15 Correct 25 ms 8724 KB Output is correct
16 Correct 22 ms 7588 KB Output is correct
17 Correct 24 ms 8368 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Execution timed out 1068 ms 87232 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 360 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 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 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 12 ms 1352 KB Output is correct
10 Correct 21 ms 2384 KB Output is correct
11 Correct 10 ms 1328 KB Output is correct
12 Correct 20 ms 2396 KB Output is correct
13 Correct 5 ms 860 KB Output is correct
14 Correct 20 ms 2396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 360 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 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 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 12 ms 1352 KB Output is correct
10 Correct 21 ms 2384 KB Output is correct
11 Correct 10 ms 1328 KB Output is correct
12 Correct 20 ms 2396 KB Output is correct
13 Correct 5 ms 860 KB Output is correct
14 Correct 20 ms 2396 KB Output is correct
15 Runtime error 22 ms 4440 KB Execution killed with signal 6
16 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 360 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 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 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 12 ms 1352 KB Output is correct
10 Correct 21 ms 2384 KB Output is correct
11 Correct 10 ms 1328 KB Output is correct
12 Correct 20 ms 2396 KB Output is correct
13 Correct 5 ms 860 KB Output is correct
14 Correct 20 ms 2396 KB Output is correct
15 Runtime error 22 ms 4440 KB Execution killed with signal 6
16 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Execution timed out 1068 ms 87232 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 3676 KB Output is correct
2 Correct 22 ms 4444 KB Output is correct
3 Correct 0 ms 600 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 86 ms 13672 KB Output is correct
6 Correct 71 ms 14036 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 39 ms 10724 KB Output is correct
9 Correct 48 ms 13120 KB Output is correct
10 Correct 18 ms 3676 KB Output is correct
11 Correct 24 ms 4424 KB Output is correct
12 Correct 0 ms 360 KB Output is correct
13 Correct 0 ms 444 KB Output is correct
14 Correct 1 ms 360 KB Output is correct
15 Correct 0 ms 356 KB Output is correct
16 Correct 0 ms 360 KB Output is correct
17 Correct 1 ms 360 KB Output is correct
18 Correct 21 ms 7472 KB Output is correct
19 Correct 25 ms 8892 KB Output is correct
20 Correct 21 ms 7320 KB Output is correct
21 Correct 25 ms 8724 KB Output is correct
22 Correct 22 ms 7588 KB Output is correct
23 Correct 24 ms 8368 KB Output is correct
24 Correct 0 ms 344 KB Output is correct
25 Execution timed out 1068 ms 87232 KB Time limit exceeded
26 Halted 0 ms 0 KB -