답안 #634375

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
634375 2022-08-24T10:14:23 Z l_reho 메기 농장 (IOI22_fish) C++17
컴파일 오류
0 ms 0 KB
#include <bits/stdc++.h>
using namespace std;


vector<vector<int>> V;

long long max_weights(int N, int M, std::vector<int> X, std::vector<int> Y, std::vector<int> W){
	
	// se X[i] è pari, allora posso ergere ponti per prendere tutti
	
	bool subtask1 = true;
	bool subtask2 = true;
	bool subtask3 = true;
	bool subtask4 = true;
	
	long long ans = 0;
	
	// for(int i = 0; i < (int)X.size(); i++)
		// V[X[i]][Y[i]] = W[i];

	for(int i = 0; i < (int)X.size(); i++){
		subtask1 &= X[i] % 2 == 0;
		subtask2 &= X[i] <= 1;
		subtask3 &= Y[i] == 0;
		subtask4 &= N <= 300;
	}
	
	if(subtask1){
		ans = accumulate(W.begin(), W.end(), 0L);
		return ans;
	}
	
	if(subtask2){
		if(N == 1) return 0;
		
		if(N == 2){
			long long x0 = 0, x1 = 0;
			for(int i = 0; i < (int)X.size(); i++){
				if(X[i] == 1) x1 += W[i];
				else x0 += W[i];
			}	
			return max(x1, x0);
		}
		
		
		
		priority_queue<info, vector<info>, CustomCompare> pq;
		
		long long x1 = 0;
		for(int i = 0; i < (int)X.size(); i++){
			pq.push({Y[i], W[i], X[i] == 0});
			if(X[i] == 1) x1 += W[i];
		}
		
		long long curr = x1;
		
		ans = curr;
		while(!pq.empty()){
			info p = pq.top();
			pq.pop();
			
			
			if(p.flag) curr += p.w, ans = max(ans, curr);
			else curr -= p.w;
			
		}
		
		return ans;
		
	}
	
	if(subtask3){
		// dp particolare
		vector<array<int, 3>> A;
		
		long long dp[M][2];
		long long memo[M];
		
		for(int i = 0; i < M; i++) A.push_back({X[i], Y[i], W[i]});
		sort(A.begin(), A.end());
		
		if(M == 1)
			return W[0];
		
		// CONTINUO DOPO
		for(int i = 0; i < M; i++){
				
			if(i){
				if(abs(A[i-1][0] - A[i][0]) <= 1){		
					if(i >= 2){
						dp[i][1] = memo[i-2] + A[i][2];
						dp[i][0] = dp[i][1];
					}
					dp[i][1] = max(dp[i-1][0] + A[i][2], dp[i][1]);
					
				}else{
					dp[i][0] = memo[i-1] + A[i][2];
					dp[i][1] = dp[i][0];
				}				
			}else
				dp[i][1] = A[i][2];
			
			memo[i] = max(memo[i-1], max(dp[i][0], dp[i][1]));
		}
		
		if(A[M-1][0] == N-1){
			ans = max(memo[M-2], dp[M-1][0]);
		}else ans = memo[M-1];
		
		return ans;
	}
	

	
	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:48:18: error: 'info' was not declared in this scope
   48 |   priority_queue<info, vector<info>, CustomCompare> pq;
      |                  ^~~~
fish.cpp:48:35: error: template argument 2 is invalid
   48 |   priority_queue<info, vector<info>, CustomCompare> pq;
      |                                   ^
fish.cpp:48:38: error: 'CustomCompare' was not declared in this scope
   48 |   priority_queue<info, vector<info>, CustomCompare> pq;
      |                                      ^~~~~~~~~~~~~
fish.cpp:48:51: error: template argument 1 is invalid
   48 |   priority_queue<info, vector<info>, CustomCompare> pq;
      |                                                   ^
fish.cpp:48:51: error: template argument 2 is invalid
fish.cpp:48:51: error: template argument 3 is invalid
fish.cpp:52:7: error: request for member 'push' in 'pq', which is of non-class type 'int'
   52 |    pq.push({Y[i], W[i], X[i] == 0});
      |       ^~~~
fish.cpp:59:13: error: request for member 'empty' in 'pq', which is of non-class type 'int'
   59 |   while(!pq.empty()){
      |             ^~~~~
fish.cpp:60:8: error: expected ';' before 'p'
   60 |    info p = pq.top();
      |        ^~
      |        ;
fish.cpp:61:7: error: request for member 'pop' in 'pq', which is of non-class type 'int'
   61 |    pq.pop();
      |       ^~~
fish.cpp:64:7: error: 'p' was not declared in this scope; did you mean 'pq'?
   64 |    if(p.flag) curr += p.w, ans = max(ans, curr);
      |       ^
      |       pq