Submission #627104

# Submission time Handle Problem Language Result Execution time Memory
627104 2022-08-12T07:50:44 Z movl228 Catfish Farm (IOI22_fish) C++17
Compilation error
0 ms 0 KB
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[x[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[i][j]=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:1:35: error: 'vector' has not been declared
    1 | long long max_weights(int n,int m,vector <int> x,vector <int> y,vector <int> w){
      |                                   ^~~~~~
fish.cpp:1:42: error: expected ',' or '...' before '<' token
    1 | long long max_weights(int n,int m,vector <int> x,vector <int> y,vector <int> w){
      |                                          ^
fish.cpp: In function 'long long int max_weights(int, int, int)':
fish.cpp:3:13: error: 'x' was not declared in this scope
    3 |  for (int i:x){
      |             ^
fish.cpp:7:21: error: 'w' was not declared in this scope
    7 |   return accumulate(w.begin(),w.end(),0ll);
      |                     ^
fish.cpp:7:10: error: 'accumulate' was not declared in this scope
    7 |   return accumulate(w.begin(),w.end(),0ll);
      |          ^~~~~~~~~~
fish.cpp:9:19: error: 'x' was not declared in this scope
    9 |  if (*max_element(x.begin(),x.end())<=1){
      |                   ^
fish.cpp:9:7: error: 'max_element' was not declared in this scope
    9 |  if (*max_element(x.begin(),x.end())<=1){
      |       ^~~~~~~~~~~
fish.cpp:11:37: error: 'w' was not declared in this scope
   11 |   for (int i=0; i<m; i++) mx[x[i]]+=w[i];
      |                                     ^
fish.cpp:12:20: error: 'max' was not declared in this scope; did you mean 'mx'?
   12 |   if (n==2) return max(mx[0],mx[1]);
      |                    ^~~
      |                    mx
fish.cpp:17:35: error: 'y' was not declared in this scope
   17 |   for (int i=0; i<m; i++) a[x[i]][y[i]]=w[i];
      |                                   ^
fish.cpp:17:41: error: 'w' was not declared in this scope
   17 |   for (int i=0; i<m; i++) a[x[i]][y[i]]=w[i];
      |                                         ^
fish.cpp:22:8: error: 'max' was not declared in this scope; did you mean 'mx'?
   22 |    ans=max(ans,cur);
      |        ^~~
      |        mx
fish.cpp:26:27: error: 'y' was not declared in this scope
   26 |  if (n<=300&&*max_element(y.begin(),y.end())<=8||*max_element(y.begin(),y.end())==0){
      |                           ^
fish.cpp:26:15: error: 'max_element' was not declared in this scope
   26 |  if (n<=300&&*max_element(y.begin(),y.end())<=8||*max_element(y.begin(),y.end())==0){
      |               ^~~~~~~~~~~
fish.cpp:32:37: error: 'x' was not declared in this scope
   32 |   for (int i=0; i<m; i++) a[y[i]+1][x[i]+1]=w[i];
      |                                     ^
fish.cpp:32:45: error: 'w' was not declared in this scope
   32 |   for (int i=0; i<m; i++) a[y[i]+1][x[i]+1]=w[i];
      |                                             ^
fish.cpp:47:60: error: 'max' was not declared in this scope
   47 |       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));
      |                                                            ^~~
fish.cpp:47:106: error: 'min' was not declared in this scope
   47 |       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));
      |                                                                                                          ^~~
fish.cpp:47:23: error: 'max' was not declared in this scope
   47 |       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));
      |                       ^~~
fish.cpp:56:10: error: 'max' was not declared in this scope
   56 |      ans=max(ans,dp[i][j][k]);
      |          ^~~