답안 #925244

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
925244 2024-02-11T07:49:02 Z IS_Rushdi 메기 농장 (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){
    int mx = *max_element(y.begin(),y.end());
    if(mx <= 8){
        long long dp[n+1][mx+2][mx+2]{};
        int sum[n+1][mx+2]{};
        for(int i = 0; i < m; i++) x[i] += 1;
        for(int i = 0; i < m; i++) y[i] += 1;
        for(int i = 0; i < m; i++) sum[x[i]][y[i]] += w[i];
        long long ans = 0;
        
        for(int i = 0; i < 1; i++){
            for(int j = 0; j < mx+2; j++){
                for(int k = 0; k < mx+2; k++){
                    dp[i][j][k] = -1e18;
                }
            }
        }
        dp[0][0][0] = 0;
        for(int i = 1; i <= n; i++){
            for(int j = 0; j < mx+2; j++){
                for(int k = 0; k < mx+2; k++){
                    for(int v = 0; v < mx+2; v++){
                        long long now = dp[i-1][k][j];
                        int cur = v;
                        while(cur > max(j,k)) now += sum[i-1][cur--];
                        cur = k;
                        while(cur > v) now += sum[i][cur--];
                        
                        dp[i][v][k] = max(dp[i][v][k],now);
                        ans = max(ans,now);
                    }
                }
            }
        }
    }
    
    return ans;
}

// int main(){
//     cout << max_weights(5, 4, {0, 1, 4, 3}, {2, 1, 4, 3}, {5, 2, 1, 3}) << '\n';
// }

Compilation message

fish.cpp: In function 'long long int max_weights(int, int, std::vector<int>, std::vector<int>, std::vector<int>)':
fish.cpp:42:12: error: 'ans' was not declared in this scope; did you mean 'abs'?
   42 |     return ans;
      |            ^~~
      |            abs