답안 #1055951

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1055951 2024-08-13T06:47:18 Z mychecksedad 메기 농장 (IOI22_fish) C++17
0 / 100
676 ms 2097152 KB
#include "fish.h"
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define all(x) x.begin(),x.end()
#define ll long long int
#define en cout << '\n'
#define pi pair<int,int>
#define vi vector<int> 
#define ff first
#define ss second
const int N = 3005;

ll dp[N][N], pref[N][N], mx[N], dp2[N][N], suf[N][N], suf2[N][N];
long long max_weights(int n, int m, std::vector<int> X, std::vector<int> Y, std::vector<int> W) {
  vector<vector<ll>> a(n + 1, vector<ll>(n + 1));
  for(int i = 0; i < m; ++i){
    a[X[i]][Y[i] + 1] = W[i];
  }
  for(int i = 0; i < n; ++i){
    pref[i][0] = a[i][0];
    for(int j = 1; j <= n; ++j) pref[i][j] = pref[i][j - 1] + a[i][j];
  }
  for(int i = 0; i <= n; ++i) dp[0][i] = pref[1][i], dp2[0][i] = pref[1][i];
  mx[0] = pref[1][n];
  for(int i = 1; i < n; ++i){
    mx[i] = 0;
    ll mx_pref = 0, mx_pref2 = 0;
    for(int j = 0; j <= n; ++j){
      ll add = pref[i + 1][j] +  pref[i - 1][j];
      dp[i][j] = add;
      if(i > 2) dp[i][j] = max(dp[i][j], mx[i - 3] + add);
      dp2[i][j] = dp[i][j];
    }
    for(int j = 0; j <= n; ++j){
      ll add = pref[i + 1][j] +  pref[i - 1][j];
      // cout << i << ' ' << j << ' ' << add1 << ' ' <<add2 << ' ';
      for(int j2 = 0; j2 <= n; ++j2){
        if(j2 >= j) 0;//dp[i][j] = max(dp[i][j], dp[i - 1][j2] + add - pref[i - 1][j] - pref[i][j]);
        else{
          dp[i][j] = max(dp[i][j],   dp2[i - 1][j2] + add - pref[i - 1][j2] - pref[i][j2]);
          dp2[i][j] = max(dp2[i][j], dp2[i - 1][j2] + add - pref[i - 1][j2] - pref[i][j2]);
        }
      }
      if(i > 1){
        mx_pref = max(mx_pref, dp[i - 2][j] - pref[i - 1][j]);
        dp[i][j] = max(dp[i][j], mx_pref + add);
        dp[i][j] = max(dp[i][j], suf[i - 2][j] - pref[i - 1][j]);
        dp2[i][j] = max(dp2[i][j], mx_pref + add);
        dp2[i][j] = max(dp2[i][j], suf[i - 2][j] - pref[i - 1][j]);
      }
      // mx_pref2 = max(mx_pref2, dp2[i - 1][j] - pref[i - 1][j] - pref[i][j]);
      // dp[i][j] = max(dp[i][j], mx_pref2 + add);
      // dp2[i][j] = max(dp2[i][j], mx_pref2 + add);
      dp[i][j] = max(dp[i][j], suf[i - 1][j] + add - pref[i][j] - pref[i - 1][j]);

      // cout << dp[i][j] << '\n'; 
    }
    for(int j = 0; j <= n; ++j) mx[i] = max(mx[i], dp[i][j]);
    suf[i][n] = dp[i][n];
    // suf2[i][n] = dp[i][n];
    for(int j = n-1; j >= 0 ;--j) suf[i][j] = max(suf[i][j + 1], dp[i][j]);
    // for(int j = n-1; j >= 0 ;--j) suf2[i][j] = max(suf2[i][j + 1], dp[i][j]);
    // en;
  }
  ll ans = mx[n - 1];

  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:39:21: warning: statement has no effect [-Wunused-value]
   39 |         if(j2 >= j) 0;//dp[i][j] = max(dp[i][j], dp[i - 1][j2] + add - pref[i - 1][j] - pref[i][j]);
      |                     ^
fish.cpp:28:21: warning: unused variable 'mx_pref2' [-Wunused-variable]
   28 |     ll mx_pref = 0, mx_pref2 = 0;
      |                     ^~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Runtime error 676 ms 2097152 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Runtime error 669 ms 2097152 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 647 ms 2097152 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB 1st lines differ - on the 1st token, expected: '4044', found: '2022'
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB 1st lines differ - on the 1st token, expected: '4044', found: '2022'
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB 1st lines differ - on the 1st token, expected: '4044', found: '2022'
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 647 ms 2097152 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 676 ms 2097152 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -