QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#590990#8780. Training, Round 2Forever_Young#WA 38ms199704kbC++202.1kb2024-09-26 13:29:592024-09-26 13:30:01

Judging History

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

  • [2024-09-26 13:30:01]
  • 评测
  • 测评结果:WA
  • 用时:38ms
  • 内存:199704kb
  • [2024-09-26 13:29:59]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

using pii = pair<int, int>;
pii dp[5010][5010];
int min_x[5010], max_x[5010], min_y[5010], max_y[5010];

pii range_intersect(pii p1, pii p2) {
  if (p1.first < 0 || p2.first < 0) {
    return pii(-1, -1);
  }
  int u = max(p1.first, p2.first);
  int v = min(p1.second, p2.second);
  if (u > v) {
    return pii(-1, -1);
  }
  return pii(u, v);
}

pii range_union(pii p1, pii p2) {
  if (p1.first < 0) {
    return p2;
  }
  if (p2.first < 0) {
    return p1;
  }
  if (p1 >= p2) {
    swap(p1, p2);
  }
  assert(p2.first <= p1.second + 1);
  return pii(p1.first, p2.second);
}

bool inrange(int x, pii p) {
  if (p.first < 0) return false;
  return p.first <= x && x <= p.second;
}

bool ok(int x, int y, int min_x, int max_x, int min_y, int max_y) {
  return min_x <= x && x <= max_x && min_y <= y && y <= max_y;
}

int main() {
  int n;
  {
    int x, y;
    scanf("%d%d%d", &n, &x, &y);
    for (int i = 1; i <= n; i++) {
      scanf("%d%d%d%d", &min_x[i], &max_x[i], &min_y[i], &max_y[i]);
      min_x[i] -= x;
      max_x[i] -= x;
      min_y[i] -= y;
      max_y[i] -= y;
    }
  }
  for (int i = 0; i <= n; i++) {
    for (int j = 0; j <= n; j++) {
      dp[i][j] = pii(-1, -1);
    }
  }
  dp[0][0] = pii(0, 0);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j <= n; j++) {
      if (dp[i][j].first < 0) continue;
      if (j >= min_y[i + 1] && j <= max_y[i + 1]) {
        pii intersect =
            range_intersect(dp[i][j], pii(min_x[i + 1], max_x[i + 1]));
        if (intersect.first >= 0) {
          dp[i + 1][j + 1] = range_union(dp[i + 1][j + 1], intersect);
          dp[i + 1][j] = range_union(
              dp[i + 1][j], pii(intersect.first + 1, intersect.second + 1));
        } else {
          dp[i + 1][j] = range_union(dp[i + 1][j], dp[i][j]);
        }
      } else {
        dp[i + 1][j] = range_union(dp[i + 1][j], dp[i][j]);
      }
    }
  }
  int ans = 0;
  for (int i = 0; i <= n; i++) {
    if (dp[n][i].first >= 0) {
      ans = max(ans, i + dp[n][i].second);
    }
  }
  printf("%d\n", ans);
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 3920kb

input:

3 0 0
0 1 0 1
1 1 0 1
1 1 1 1

output:

3

result:

ok single line: '3'

Test #2:

score: 0
Accepted
time: 38ms
memory: 199684kb

input:

5000 801577551 932138594
801577551 801577551 932138594 932138594
801577552 801577552 932138594 932138594
801577552 801577552 932138595 932138595
801577552 801577552 932138596 932138596
801577553 801577553 932138596 932138596
801577553 801577553 932138597 932138597
801577553 801577553 932138598 93213...

output:

5000

result:

ok single line: '5000'

Test #3:

score: 0
Accepted
time: 31ms
memory: 199544kb

input:

5000 932138594 801577551
932138594 932138594 801577551 801577551
932138594 932138594 801577552 801577552
932138595 932138595 801577552 801577552
932138596 932138596 801577552 801577552
932138596 932138596 801577553 801577553
932138597 932138597 801577553 801577553
932138598 932138598 801577553 80157...

output:

5000

result:

ok single line: '5000'

Test #4:

score: -100
Wrong Answer
time: 28ms
memory: 199704kb

input:

5000 76836128 716580777
76836128 76836128 716580777 716580777
76836129 76836129 716580777 716580777
76836130 76836130 716580777 716580777
76836131 76836131 716580777 716580777
76836131 76836131 716580778 716580778
76836131 76836131 716580779 716580779
76836131 76836131 716580780 716580780
76836128 7...

output:

7

result:

wrong answer 1st lines differ - expected: '4994', found: '7'