답안 #955353

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
955353 2024-03-30T08:15:39 Z Gray 메기 농장 (IOI22_fish) C++17
컴파일 오류
0 ms 0 KB
// #include <bits/stdc++.h>

// #pragma GCC optimize("Ofast,unroll-loops,no-stack-protector,fast-math,inline")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,lzcnt,mmx,abm,avx,avx2,fma")
#include <algorithm>
#include <cassert>
#include <iostream>
#include <vector>

#define M_PI 3.14159265358979323846
#define ll long long
using ld = double;
#define ff first
#define ss second
#define ln "\n"
#define gcd(x,y) __gcd(x,y)
using namespace std;

// const ll MOD = 1e9+7;
const ll INF = 2e18;
// const ll MAXN = 1e6+1;

ll max_weights(int n, int m, vector<int> cx, vector<int> cy, vector<int> cw){
    n++;
    vector<pair<pair<ll, ll>, ll>> fish(m);
    for (ll i=0; i<m; i++){
        fish[i] = {{cx[i], cy[i]+1}, cw[i]};
    }
    sort(fish.begin(), fish.end(), [](auto op1, auto op2)->bool{
        return op1.ff.ss<op2.ff.ss;
    });
    vector<vector<ll>> A(n, vector<ll>(n));
    for (ll i=0; i<m; i++){
        A[fish[i].ff.ff][fish[i].ff.ss]=fish[i].ss;
    }
    vector<vector<ll>> pref(n, vector<ll>(n,0));
    for (ll i=0; i<n; i++){
        for (ll j=0; j<n; j++){
            pref[i][j] = (j==0?A[i][j]:pref[i][j-1]+A[i][j]);
        }
    }
    // return 0;
    vector<vector<vector<ll>>> dp(n, vector<vector<ll>>(n, vector<ll>(n, 0)));
    vector<vector<vector<ll>>> dp2(n, vector<vector<ll>>(n, vector<ll>(n, 0)));
    for (ll i=1; i<n; i++){
        for (ll j=0; j<n; j++){
            for (ll k=0; k<n; k++){
                if (j>k){
                    dp[i][j][k] = max(dp[i-1][k][n-1], dp[i-1][k][k]+pref[i-1][j]-pref[i-1][k]);
                }else dp[i][j][k] = dp[i-1][k][n-1]+pref[i][k]-pref[i][j];
                if (k) dp[i][j][k]=max(dp[i][j][k], dp[i][j][k-1]);
            }
            // for (ll k=n-1; k>=0; k--){
            //     dp2[i][j][k] = dp[i][j][k]+(i+1<n?A[i+1][j]:0);
            //     if (k+1<n) dp2[i][j][k]=max(dp2[i][j][k+1], dp2[i][j][k]);
            // }
        }
    }
    ll mx = 0;
    // for (ll i=0; i<n; i++){
    //     cout << i << ": \n";
    //     for (ll j=0; j<n; j++){
    //         for (ll k=0; k<n; k++){
    //             cout << dp[i][j][k] << " ";
    //         }
    //         cout << ln;
    //     }
    // }
    for (ll i=0; i<n; i++){
        mx = max(mx, dp[n-2][i][n-1]);
    }
    return mx;
}

// int main(){
//  ios_base::sync_with_stdio(false);
//  cin.tie(NULL);
//  ll t=1;
//  cin >> t;
//  // while (t--) solve();
// }


int main() {
  int N, M;
  assert(2 == scanf("%d %d", &N, &M));

  std::vector<int> X(M), Y(M), W(M);
  for (long long i = 0; i < M; ++i) {
    assert(3 == scanf("%d %d %d", &X[i], &Y[i], &W[i]));
  }

  long long result = max_weights(N, M, X, Y, W);
  printf("%lld\n", result);
  return 0;
}

Compilation message

/usr/bin/ld: /tmp/ccJhLe6G.o: in function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/ccZQRBTE.o:fish.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status