답안 #627106

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
627106 2022-08-12T07:52:39 Z movl228 메기 농장 (IOI22_fish) C++17
컴파일 오류
0 ms 0 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];
		}
		int l=min(8,n);
		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:32:41: error: expected ')' before ';' token
   32 |   int l=*max_element(y.begin(),y.end()+1;
      |                     ~                   ^
      |                                         )
fish.cpp:41:7: error: redeclaration of 'int l'
   41 |   int l=min(8,n);
      |       ^
fish.cpp:32:7: note: 'int l' previously declared here
   32 |   int l=*max_element(y.begin(),y.end()+1;
      |       ^
fish.cpp:68:1: warning: control reaches end of non-void function [-Wreturn-type]
   68 | }
      | ^