제출 #1201708

#제출 시각아이디문제언어결과실행 시간메모리
1201708TimoshCatfish Farm (IOI22_fish)C++20
9 / 100
952 ms2162688 KiB
#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)
{
  long long cur;
  bool ok = 1;
  for (auto &i : X)
    ok &= (i % 2 == 0);
  if (ok)
    return accumulate(W.begin(), W.end(), 0ll);
  if (*max_element(X.begin(), X.end()) <= 1)
  {
    vector<long long> A(N), B(N);
    for (int i = 0; i < M; i++)
    {
      if (X[i])
        B[Y[i]] = W[i];
      else
        A[Y[i]] = W[i];
    }
    if (N == 2)
    {
      return max(A[0] + A[1], B[0] + B[1]);
    }
    long long mx, s;
    s = mx = 0;
    for (int i = 0; i < N; i++)
    {
      s += A[i] - B[i];
      mx = max(mx, s);
    }
    return mx + accumulate(B.begin(), B.end(), 0ll);
  }
  vector<vector<long long>> A(N, vector<long long>(N)), dp(N + 2, vector<long long>(N + 1));
  dp[0][0] = 0;
  for (int i = 0; i < M; i++)
    A[X[i]][Y[i]] = W[i];
  for (int i = 0; i < N; i++)
  {
    long long s = 0;
    for (int j = 0; j < N; j++)
    {
      s = max(s, dp[i][j]);
      s += A[i][j];
      dp[i + 1][j + 1] = max(s, dp[i + 1][j + 1]);
    }
    s = 0;
    for (int j = N; j >= 0; j--)
    {
      if (j)
        s = max(s, dp[i][j - 1]);
      dp[i + 2][j] = max(s, dp[i + 2][j]);
    }
  }
  return dp[N + 1][0];
}

// int main()
// {
//   int n, m;
//   cin >> n >> m;
//   vector<int> x(m), y(m), w(m);
//   for (auto &i : x)
//     cin >> i;
//   for (auto &i : y)
//     cin >> i;
//   for (auto &i : w)
//     cin >> i;
//   cout << max_weights(n, m, x, y, w);
//   return 0;
// }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...