답안 #728784

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
728784 2023-04-23T05:52:28 Z kwongweng 메기 농장 (IOI22_fish) C++17
0 / 100
854 ms 2097152 KB
#include "fish.h"
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef long double ld;
typedef pair<ll, ll> pll;
#define FOR(i, a, b) for(int i = a; i < b; i++)
#define ROF(i, a, b) for(int i = a; i >= b; i--)
#define ms memset
#define pb push_back
#define fi first
#define se second

// O(n^2) dp

ll max_weights(int n, int m, vi X, vi Y, vi W) {
  ll mat[n][n]; //position of all fishes
  ms(mat, 0, sizeof(mat));
  FOR(i,0,m){
    mat[X[i]][Y[i]] = W[i];
  }
  ll dp[n][n][2];
  // dp[i][j][0] - mat[i][j] chosen, while increasing
  // dp[i][j][1] - while decreasing
  ms(dp,0,sizeof(dp));
  FOR(i,0,n){
    if (i > 0){
      ROF(j,n-1,0){
        //decreasing
        if (j<n-1){
          dp[i][j][1] = max(dp[i][j][1], dp[i][j+1][1]);
          dp[i][j][1] = max(dp[i][j][1], dp[i-1][j+1][1]);
        }
        if (i>1){
          dp[i][j][1] = max(dp[i][j][1], dp[i-2][j][0]);
        }
        dp[i][j][1] += mat[i][j];
      }
    }
    if (i < n-1){
      if (i>0){
        FOR(k,0,i){
          dp[i][0][0] = max(dp[i][0][0], dp[k][0][1]);
        }
      }
      FOR(j,0,n){
        // increasing
        if (j>0){
          dp[i][j][0] = max(dp[i][j][0], dp[i][j-1][0]);
        }
        if (i>0 && j>0){
          dp[i][j][0] = max(dp[i][j][0], dp[i-1][j-1][0]);
        }
        dp[i][j][0] += mat[i][j];
      }
    }
  }
  ll ans = 0;
  FOR(i,0,n){
    FOR(j,0,n){
      ans = max(ans, max(dp[i][j][0], dp[i][j][1]));
    }
  }
  if (n > 2){
    ll val = 0;
    FOR(i,0,n){
      val += mat[n-1][i];
    }
    ans = max(ans, dp[n-3][0][1] + val);
  }
  return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Runtime error 854 ms 2097152 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Runtime error 828 ms 2097152 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 808 ms 2097152 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Incorrect 1 ms 724 KB 1st lines differ - on the 1st token, expected: '216624184325', found: '214837477243'
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Incorrect 1 ms 724 KB 1st lines differ - on the 1st token, expected: '216624184325', found: '214837477243'
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Incorrect 1 ms 724 KB 1st lines differ - on the 1st token, expected: '216624184325', found: '214837477243'
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 808 ms 2097152 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 854 ms 2097152 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -