QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#511220#5303. No Bug No Game__YSC__Compile Error//C++201.7kb2024-08-09 17:41:132024-08-09 17:41:13

Judging History

你现在查看的是最新测评结果

  • [2024-08-09 17:41:13]
  • 评测
  • [2024-08-09 17:41:13]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
using pii = pair<int, int>;

const int MAXN = 3001, INF = int(1e9);

int dp[MAXN], last[MAXN], k, ans, w[MAXN][MAXN];

struct Segment_Tree {
  int l[MAXN << 2], r[MAXN << 2];
  vector<pii> ve[MAXN << 2];
  void build(int u, int s, int t) {
    l[u] = s, r[u] = t;
    if(s == t) {
      return;
    }
    int mid = (s + t) >> 1;
    build(u << 1, s, mid), build((u << 1) | 1, mid + 1, t);
  }
  void update(int u, int s, int t, pii x) {
    if(s > t) {
      return;
    }
    if(l[u] >= s && r[u] <= t) {
      ve[u].push_back(x);
      return;
    }
    if(s <= r[u << 1]) {
      update(u << 1, s, t, x);
    }
    if(t >= l[(u << 1) | 1]) {
      update((u << 1) | 1, s, t, x);
    }
  }
  void DP(int u) {
    for(int i = 0; i <= k; ++i) {
      last[i] = dp[i];
    }
    for(auto [w, v] : ve[u]) {
      for(int i = k; i >= w; --i) {
        dp[i] = max(dp[i], dp[i - w] + v);
      }
    }
    if(l[u] == r[u]) {
      for(int i = 1; i <= min(p[i], k); ++i) {
        ans = max(ans, dp[k - i] + w[l[u]][i]);
      }
      for(int i = 0; i <= k; ++i) {
        dp[i] = last[i];
      }
      return;
    }
    DP(u << 1), DP((u << 1) | 1);
    for(int i = 0; i <= k; ++i) {
      dp[i] = last[i];
    }
  }
}tr;

int n, p[MAXN];

int main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  cin >> n >> k;
  tr.build(1, 1, n);
  for(int i = 1; i <= n; ++i) {
    cin >> p[i];
    for(int j = 1; j <= p[i]; ++j) {
      cin >> w[i][j];
    }
    tr.update(1, 1, i - 1, {p[i], w[i][p[i]]});
    tr.update(1, i + 1, n, {p[i], w[i][p[i]]});
  }
  fill(dp, dp + k + 1, -INF);
  dp[0] = 0;
  tr.DP(1);
  cout << ans;
  return 0;
}

詳細信息

answer.code: In member function ‘void Segment_Tree::DP(int)’:
answer.code:45:31: error: ‘p’ was not declared in this scope
   45 |       for(int i = 1; i <= min(p[i], k); ++i) {
      |                               ^