Submission #627107

# Submission time Handle Problem Language Result Execution time Memory
627107 2022-08-12T07:53:34 Z movl228 Catfish Farm (IOI22_fish) C++17
26 / 100
1000 ms 2097152 KB
#include "fish.h"

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

long long max_weights(int n,int m,vector <int> x,vector <int> y,vector <int> w){
	bool sub1=1;
	for (int i:x){
		if (i%2==1) sub1=0;
	}
	if (sub1){
		return accumulate(w.begin(),w.end(),0ll);
	}
	if (*max_element(x.begin(),x.end())<=1){
		long long mx[2]={0,0};
		for (int i=0; i<m; i++) mx[y[i]]+=w[i];
		if (n==2) return max(mx[0],mx[1]);
		int a[2][n];
		for (int i=0; i<2; i++){
			for (int j=0; j<n; j++) a[i][j]=0;
		}
		for (int i=0; i<m; i++) a[x[i]][y[i]]=w[i];
		long long ans=mx[1],cur=mx[1];
		for (int j=0; j<n; j++){
			cur+=a[0][j];
			cur-=a[1][j];
			ans=max(ans,cur);
		}
		return ans;
	}
	if (n<=300&&*max_element(y.begin(),y.end())<=8||*max_element(y.begin(),y.end())==0){
		int l=*max_element(y.begin(),y.end())+1;
		long long a[l+1][n+1],s[n+1][l+1];
		for (int i=0; i<=n; i++){
			for (int j=0; j<=l; j++) a[j][i]=s[i][j]=0;
		}
		for (int i=0; i<m; i++) a[y[i]+1][x[i]+1]=w[i];
		for (int col=0; col<=n; col++){
			for (int i=1; i<=l; i++) s[col][i]=s[col][i-1]+a[i][col];
		}
		long long dp[n+1][l+1][l+1];
		for (int i=0; i<=n; i++){
			for (int j=0; j<=l; j++){
				for (int k=0; k<=l; k++) dp[i][j][k]=-1e18;
			}
		}
		dp[0][0][0]=0;
		for (int i=0; i<n; i++){
			for (int j=0; j<=l; j++){
				for (int k=0; k<=l; k++){
					for (int nxt=0; nxt<=l; nxt++){
						dp[i+1][k][nxt]=max(dp[i+1][k][nxt],dp[i][j][k]+(nxt>max(j,k)?s[i][nxt]-s[i][max(j,k)]:0ll)-s[i+1][min(k,nxt)]+(i+2<=n?s[i+2][nxt]:0ll));
					}
				}
			}
		}
		long long ans=0;
		for (int i=0; i<=n; i++){
			for (int j=0; j<=l; j++){
				for (int k=0; k<=l; k++){
					ans=max(ans,dp[i][j][k]);
				}
			}
		}
		return ans;
	}
}

Compilation message

fish.cpp: In function 'long long int max_weights(int, int, std::vector<int>, std::vector<int>, std::vector<int>)':
fish.cpp:31:12: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   31 |  if (n<=300&&*max_element(y.begin(),y.end())<=8||*max_element(y.begin(),y.end())==0){
      |      ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
fish.cpp:67:1: warning: control reaches end of non-void function [-Wreturn-type]
   67 | }
      | ^
# Verdict Execution time Memory Grader output
1 Correct 21 ms 2156 KB Output is correct
2 Correct 26 ms 2644 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 87 ms 7284 KB Output is correct
6 Correct 85 ms 7268 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Runtime error 51 ms 8084 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 9 ms 6484 KB Output is correct
3 Correct 20 ms 7088 KB Output is correct
4 Correct 16 ms 7336 KB Output is correct
5 Correct 33 ms 8780 KB Output is correct
6 Correct 28 ms 8916 KB Output is correct
7 Correct 31 ms 8916 KB Output is correct
8 Correct 33 ms 8912 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 2 ms 468 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 468 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 2 ms 468 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 468 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Execution timed out 1057 ms 213708 KB Time limit exceeded
16 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 2 ms 468 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 468 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Execution timed out 1057 ms 213708 KB Time limit exceeded
16 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 9 ms 6484 KB Output is correct
3 Correct 20 ms 7088 KB Output is correct
4 Correct 16 ms 7336 KB Output is correct
5 Correct 33 ms 8780 KB Output is correct
6 Correct 28 ms 8916 KB Output is correct
7 Correct 31 ms 8916 KB Output is correct
8 Correct 33 ms 8912 KB Output is correct
9 Runtime error 866 ms 2097152 KB Execution killed with signal 9
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 21 ms 2156 KB Output is correct
2 Correct 26 ms 2644 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 87 ms 7284 KB Output is correct
6 Correct 85 ms 7268 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Runtime error 51 ms 8084 KB Execution killed with signal 11
9 Halted 0 ms 0 KB -