Submission #830758

# Submission time Handle Problem Language Result Execution time Memory
830758 2023-08-19T10:08:39 Z NeroZein Catfish Farm (IOI22_fish) C++17
26 / 100
1000 ms 2097152 KB
#include "fish.h"
#include <bits/stdc++.h>
using namespace std;

const int N = 302;
int n; 
int max_m, max_n;
vector<vector<long long>> a;
vector<vector<long long>> pref;
vector<vector<vector<long long>>> dp;

long long bt(int col, int last, int last2) {
  if (col > min(n, max_m + 1)) {
    return 0;
  }
  long long& ret = dp[col][last][last2];
  if (ret != -1) {
    return ret;
  }
  long long sum = 0; 
  long long ps = pref[col][last]; 
  for (int nlast = 0; nlast <= min(n, max_n + 1); ++nlast) {
    if (nlast > last2 && nlast > last) sum += a[col - 1][nlast];
    if (nlast <= last) ps -= a[col][nlast];
    ret = max(ret, bt(col + 1, nlast, last) + sum + ps); 
  }
  return ret;
}

long long max_weights(int N_, int M, vector<int> X, vector<int> Y, vector<int> W) {
  n = N_; 
  bool even = true;
  for (int i = 0; i < M; ++i) {
    max_m = max(max_m, X[i] + 1); 
    max_n = max(max_n, Y[i] + 1); 
    even &= (X[i] % 2 == 0);
  }
  if (even) {
    return accumulate(W.begin(), W.end(), 0LL);
  }
  dp.resize(max_m + 2); 
  for (int i = 0; i < max_m + 2; ++i) {
    dp[i].resize(max_n + 2);
    for (int j = 0; j < max_n + 2; ++j) {
      dp[i][j].assign(max_n + 2, -1);
    }
  }
  a.resize(max_m + 2);
  for (int i = 0; i < max_m + 2; ++i) {
    a[i].resize(max_n + 2); 
  }
  for (int i = 0; i < M; ++i) {
    a[X[i] + 1][Y[i] + 1] = W[i];
  }
  pref.resize(max_m + 2);
  for (int i = 0; i < max_m + 2; ++i) {
    pref[i].resize(max_n + 2); 
  }
  for (int i = 1; i < max_m + 2; ++i) {
    for (int j = 1; j < max_n + 2; ++j) {
      pref[i][j] = pref[i][j - 1] + a[i][j];      
    } 
  }
  return bt(1, 0, 0); 
}
# Verdict Execution time Memory Grader output
1 Correct 19 ms 2144 KB Output is correct
2 Correct 22 ms 2636 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 74 ms 13648 KB Output is correct
6 Correct 80 ms 13920 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Execution timed out 1044 ms 2097152 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 300 KB Output is correct
2 Correct 56 ms 40140 KB Output is correct
3 Correct 72 ms 38048 KB Output is correct
4 Correct 63 ms 37708 KB Output is correct
5 Correct 75 ms 44108 KB Output is correct
6 Correct 72 ms 43436 KB Output is correct
7 Correct 74 ms 44056 KB Output is correct
8 Correct 77 ms 44132 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 300 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 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 Correct 1 ms 340 KB Output is correct
10 Correct 3 ms 824 KB Output is correct
11 Correct 2 ms 440 KB Output is correct
12 Correct 3 ms 724 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 2 ms 596 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 300 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 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 Correct 1 ms 340 KB Output is correct
10 Correct 3 ms 824 KB Output is correct
11 Correct 2 ms 440 KB Output is correct
12 Correct 3 ms 724 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 2 ms 596 KB Output is correct
15 Execution timed out 1092 ms 218020 KB Time limit exceeded
16 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 300 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 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 Correct 1 ms 340 KB Output is correct
10 Correct 3 ms 824 KB Output is correct
11 Correct 2 ms 440 KB Output is correct
12 Correct 3 ms 724 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 2 ms 596 KB Output is correct
15 Execution timed out 1092 ms 218020 KB Time limit exceeded
16 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 300 KB Output is correct
2 Correct 56 ms 40140 KB Output is correct
3 Correct 72 ms 38048 KB Output is correct
4 Correct 63 ms 37708 KB Output is correct
5 Correct 75 ms 44108 KB Output is correct
6 Correct 72 ms 43436 KB Output is correct
7 Correct 74 ms 44056 KB Output is correct
8 Correct 77 ms 44132 KB Output is correct
9 Runtime error 673 ms 2097152 KB Execution killed with signal 9
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 19 ms 2144 KB Output is correct
2 Correct 22 ms 2636 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 74 ms 13648 KB Output is correct
6 Correct 80 ms 13920 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Execution timed out 1044 ms 2097152 KB Time limit exceeded
9 Halted 0 ms 0 KB -