QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#225318#6400. Game: CelesteYouKn0wWhoWA 201ms32044kbC++231.4kb2023-10-24 14:43:542023-10-24 14:43:55

Judging History

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

  • [2023-10-24 14:43:55]
  • 评测
  • 测评结果:WA
  • 用时:201ms
  • 内存:32044kb
  • [2023-10-24 14:43:54]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;

const int N = 1e6 + 9;
int a[N], x[N];
vector<int> dp[N];
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int t; cin >> t;
  while (t--) {
    int n, l, r; cin >> n >> l >> r;
    for (int i = 1; i <= n; i++) {
      cin >> x[i];
    }
    for (int i = 1; i <= n; i++) {
      cin >> a[i];
      dp[i].clear();
    }
    deque<int> dq;
    dq.push_back(1);
    dp[1].push_back(a[1]);
    auto add = [&](int i) {
      while (!dq.empty() and dp[dq.back()] < dp[i]) {
        dq.pop_back();
      }
      dq.push_back(i);
    };
    auto rem = [&](int i) {
      while (!dq.empty() and dq.front() <= i) {
        dq.pop_front();
      }
    };
    auto get = [&]() {
      if (dq.empty()) return -1;
      return dq.front();
    };
    int lid = 1, rid = 0;
    for (int i = 2; i <= n; i++) {
      while (rid + 1 <= n and x[rid + 1] <= x[i] - l) {
        add(++rid);
      }
      while (lid <= n and x[lid] < x[i] - r) {
        rem(lid++);
      }
      int mx = get();
      if (mx != -1) {
        dp[i] = dp[mx];
        dp[i].push_back(a[i]);
        sort(dp[i].rbegin(), dp[i].rend());
      }
      else {
        dp[i].push_back(-1);
      }
    }
    if (find(dp[n].begin(), dp[n].end(), -1) != dp[n].end()) {
      cout << -1 << '\n';
    }
    else {
      cout << dp[n].size() << '\n';
      for (auto x: dp[n]) {
        cout << x << ' ';
      }
      cout << '\n';
    }
  }
  return 0;
}

详细

Test #1:

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

input:

2
5 2 3
1 2 3 4 5
5 2 3 1 4
3 1 2
1 4 7
3 3 3

output:

3
5 4 3 
-1

result:

ok 3 lines

Test #2:

score: -100
Wrong Answer
time: 201ms
memory: 32044kb

input:

10000
57 8 11
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
11 16 7 7 10 13 9 14 10 1 12 4 8 13 3 20 16 7 16 19 20 8 19 7 16 6 17 13 7 19 17 11 12 17 6 3 7 8 14 2 4 15 5 18 16 7 20 9 1...

output:

8
20 20 19 16 14 12 11 3 
28
20 19 16 16 15 15 14 13 13 12 12 11 11 8 8 7 7 6 6 5 5 4 4 4 4 4 2 1 
6
6 5 3 2 1 1 
10
19 18 18 17 17 11 10 9 7 7 
185
20 20 20 20 20 20 20 20 19 19 19 19 19 19 19 19 19 19 19 19 18 18 18 18 18 17 17 17 17 17 17 17 17 16 16 16 16 16 16 16 16 15 15 15 15 15 15 15 15 15 1...

result:

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