Submission #654772

# Submission time Handle Problem Language Result Execution time Memory
654772 2022-11-01T15:03:02 Z t6twotwo Catfish Farm (IOI22_fish) C++17
52 / 100
1000 ms 2097152 KB
#include "fish.h"
#include <bits/stdc++.h>
using namespace std;
const long long inf = -(1LL << 60);
long long max_weights(int n, int m, vector<int> x, vector<int> y, vector<int> w) {
  vector p(n, vector<int>(n + 1));
  for (int i = 0; i < m; i++) {
    p[x[i]][y[i] + 1] = w[i];
  }
  vector s(n, vector<long long>(n + 2));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j <= n; j++) {
      s[i][j + 1] = s[i][j] + p[i][j];
    }
  }
  auto range_sum = [&](int i, int l, int r) -> long long {
    if (i == -1) {
      return 0;
    }
    return s[i][r + 1] - s[i][l + 1];
  };
  vector dp(n + 1, array<long long, 2>{inf, inf});
  dp[0] = {0, 0};
  for (int i = 0; i < n; i++) {
    auto pd = dp;
    vector<long long> pmax(n + 2, inf);
    for (int j = 1; j <= n; j++) {
      pmax[j + 1] = max(pmax[j], pd[j][0] + range_sum(i - 1, j, n));
    }
    vector<long long> smax(n + 2, inf);
    for (int j = n; j >= 1; j--) {
      smax[j] = max(smax[j + 1], max(pd[j][0], pd[j][1]) - range_sum(i, j, n));
    }
    dp = vector(n + 1, array<long long, 2>{inf, inf});
    for (int j = 0; j <= n; j++) {
      dp[0][0] = max(dp[0][0], max(pd[j][0], pd[j][1]));
      dp[0][1] = max(dp[0][1], max(pd[j][0], pd[j][1]) + range_sum(i, 0, j));
    }
    for (int j = 1; j <= n; j++) {
      dp[j][0] = max(dp[j][0], max(pd[0][1], pd[0][0] + range_sum(i - 1, 0, j)));
      dp[j][1] = max(dp[j][1], max(pd[0][1], pd[0][0] + range_sum(i - 1, 0, j)));
      dp[j][0] = max(dp[j][0], pmax[j + 1] - range_sum(i - 1, j, n));
      dp[j][1] = max(dp[j][1], smax[j] + range_sum(i, j, n));
      // for (int k = 1; k <= j; k++) {
      //   dp[j][0] = max(dp[j][0], pd[k][0] + range_sum(i - 1, k, j));
      // }
      // for (int k = j; k <= n; k++) {
      //   dp[j][1] = max(dp[j][1], max(pd[k][0], pd[k][1]) + range_sum(i, j, k));
      // }
    }
  }
  long long ans = inf;
  for (int i = 0; i <= n; i++) {
    ans = max(ans, max(dp[i][0], dp[i][1]));
  }
  return ans;
}
# Verdict Execution time Memory Grader output
1 Runtime error 809 ms 2097152 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Execution timed out 1147 ms 2014724 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 733 ms 2097152 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 308 KB Output is correct
3 Correct 1 ms 216 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 224 KB Output is correct
6 Correct 1 ms 224 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 596 KB Output is correct
10 Correct 3 ms 1364 KB Output is correct
11 Correct 1 ms 596 KB Output is correct
12 Correct 3 ms 1364 KB Output is correct
13 Correct 1 ms 472 KB Output is correct
14 Correct 2 ms 1368 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 308 KB Output is correct
3 Correct 1 ms 216 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 224 KB Output is correct
6 Correct 1 ms 224 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 596 KB Output is correct
10 Correct 3 ms 1364 KB Output is correct
11 Correct 1 ms 596 KB Output is correct
12 Correct 3 ms 1364 KB Output is correct
13 Correct 1 ms 472 KB Output is correct
14 Correct 2 ms 1368 KB Output is correct
15 Correct 2 ms 1368 KB Output is correct
16 Correct 2 ms 344 KB Output is correct
17 Correct 15 ms 3008 KB Output is correct
18 Correct 20 ms 3028 KB Output is correct
19 Correct 14 ms 3000 KB Output is correct
20 Correct 13 ms 3036 KB Output is correct
21 Correct 14 ms 3028 KB Output is correct
22 Correct 26 ms 4788 KB Output is correct
23 Correct 4 ms 1620 KB Output is correct
24 Correct 10 ms 2484 KB Output is correct
25 Correct 3 ms 1364 KB Output is correct
26 Correct 5 ms 1556 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 308 KB Output is correct
3 Correct 1 ms 216 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 224 KB Output is correct
6 Correct 1 ms 224 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 596 KB Output is correct
10 Correct 3 ms 1364 KB Output is correct
11 Correct 1 ms 596 KB Output is correct
12 Correct 3 ms 1364 KB Output is correct
13 Correct 1 ms 472 KB Output is correct
14 Correct 2 ms 1368 KB Output is correct
15 Correct 2 ms 1368 KB Output is correct
16 Correct 2 ms 344 KB Output is correct
17 Correct 15 ms 3008 KB Output is correct
18 Correct 20 ms 3028 KB Output is correct
19 Correct 14 ms 3000 KB Output is correct
20 Correct 13 ms 3036 KB Output is correct
21 Correct 14 ms 3028 KB Output is correct
22 Correct 26 ms 4788 KB Output is correct
23 Correct 4 ms 1620 KB Output is correct
24 Correct 10 ms 2484 KB Output is correct
25 Correct 3 ms 1364 KB Output is correct
26 Correct 5 ms 1556 KB Output is correct
27 Correct 175 ms 106504 KB Output is correct
28 Correct 66 ms 15632 KB Output is correct
29 Correct 304 ms 118928 KB Output is correct
30 Correct 253 ms 119052 KB Output is correct
31 Correct 252 ms 118976 KB Output is correct
32 Correct 80 ms 15820 KB Output is correct
33 Correct 276 ms 118976 KB Output is correct
34 Correct 255 ms 119076 KB Output is correct
35 Correct 215 ms 111080 KB Output is correct
36 Correct 263 ms 118924 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 733 ms 2097152 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 809 ms 2097152 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -