Submission #654812

# Submission time Handle Problem Language Result Execution time Memory
654812 2022-11-01T17:14:40 Z t6twotwo Catfish Farm (IOI22_fish) C++17
52 / 100
897 ms 2097152 KB
#include "fish.h"
#include <bits/stdc++.h>
using namespace std;
const long long inf = -(1LL << 50);
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 d(n, vector<int>{0});
  for (int i = 0; i < n; i++) {
    for (int j = 1; j <= n; j++) {
      d[i].push_back(j);
    }
  }
  vector<int> e{0};
  vector<array<long long, 2>> dp{{0, 0}};
  for (int i = 0; i < n; i++) {
    auto pd = dp;
    int l = d[i].size();
    dp = vector(l, array<long long, 2>{inf, inf});
    int k = pd.size();
    vector<long long> pmax(k + 1, inf);
    for (int j = 0; j < k; j++) {
      pmax[j + 1] = max(pmax[j], pd[j][0] + range_sum(i - 1, e[j], n)); //suf_sum(i - 1, e[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, e[j])); //pre_sum(i, e[j]));
    }
    vector<long long> smax(k + 1, inf);
    for (int j = k - 1; j >= 0; j--) {
      smax[j] = max(smax[j + 1], max(pd[j][0], pd[j][1]) - range_sum(i, e[j], n)); //suf_sum(i, e[j]));
    }
    for (int j = 1; j < l; j++) {
      dp[j][0] = max({dp[j][0], max(pd[0][1], pd[0][0] + range_sum(i - 1, 0, d[i][j]) /*pre_sum(i - 1, d[i][j])*/), pmax[upper_bound(e.begin(), e.end(), d[i][j]) - e.begin()] - range_sum(i - 1, d[i][j], n)}); //suf_sum(i - 1, d[i][j])});
      dp[j][1] = max({dp[j][1], max(pd[0][1], pd[0][0] + range_sum(i - 1, 0, d[i][j]) /*pre_sum(i - 1, d[i][j])*/), smax[lower_bound(e.begin(), e.end(), d[i][j]) - e.begin()] + range_sum(i, d[i][j], n)}); //suf_sum(i, d[i][j])});
    }
    e.swap(d[i]);
  }
  long long ans = inf;
  for (auto v : dp) {
    ans = max(ans, max(v[0], v[1]));
  }
  return ans;
}
# Verdict Execution time Memory Grader output
1 Runtime error 776 ms 2097152 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Runtime error 814 ms 2097152 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 724 ms 2097152 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 2 ms 724 KB Output is correct
10 Correct 6 ms 1984 KB Output is correct
11 Correct 2 ms 724 KB Output is correct
12 Correct 6 ms 2004 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 6 ms 2004 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 2 ms 724 KB Output is correct
10 Correct 6 ms 1984 KB Output is correct
11 Correct 2 ms 724 KB Output is correct
12 Correct 6 ms 2004 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 6 ms 2004 KB Output is correct
15 Correct 7 ms 2004 KB Output is correct
16 Correct 2 ms 468 KB Output is correct
17 Correct 19 ms 3036 KB Output is correct
18 Correct 17 ms 3012 KB Output is correct
19 Correct 20 ms 3004 KB Output is correct
20 Correct 17 ms 3028 KB Output is correct
21 Correct 17 ms 3172 KB Output is correct
22 Correct 28 ms 4052 KB Output is correct
23 Correct 10 ms 2136 KB Output is correct
24 Correct 14 ms 2704 KB Output is correct
25 Correct 6 ms 2004 KB Output is correct
26 Correct 9 ms 2220 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 2 ms 724 KB Output is correct
10 Correct 6 ms 1984 KB Output is correct
11 Correct 2 ms 724 KB Output is correct
12 Correct 6 ms 2004 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 6 ms 2004 KB Output is correct
15 Correct 7 ms 2004 KB Output is correct
16 Correct 2 ms 468 KB Output is correct
17 Correct 19 ms 3036 KB Output is correct
18 Correct 17 ms 3012 KB Output is correct
19 Correct 20 ms 3004 KB Output is correct
20 Correct 17 ms 3028 KB Output is correct
21 Correct 17 ms 3172 KB Output is correct
22 Correct 28 ms 4052 KB Output is correct
23 Correct 10 ms 2136 KB Output is correct
24 Correct 14 ms 2704 KB Output is correct
25 Correct 6 ms 2004 KB Output is correct
26 Correct 9 ms 2220 KB Output is correct
27 Correct 769 ms 153852 KB Output is correct
28 Correct 91 ms 15108 KB Output is correct
29 Correct 897 ms 160996 KB Output is correct
30 Correct 872 ms 160916 KB Output is correct
31 Correct 858 ms 166412 KB Output is correct
32 Correct 100 ms 18124 KB Output is correct
33 Correct 840 ms 166428 KB Output is correct
34 Correct 852 ms 166400 KB Output is correct
35 Correct 799 ms 158504 KB Output is correct
36 Correct 855 ms 166352 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 724 ms 2097152 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 776 ms 2097152 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -