QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#725400#9574. StripsXiaoMo247#RE 0ms3564kbC++202.8kb2024-11-08 17:28:572024-11-08 17:28:57

Judging History

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

  • [2024-11-08 17:28:57]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:3564kb
  • [2024-11-08 17:28:57]
  • 提交

answer

#include <bits/stdc++.h>
const int INF = 0x3f3f3f3f;

void solve() {
    int n, m, k, w; std::cin >> n >> m >> k >> w;
    std::vector<int> a(n), b(m);
    std::vector<int> p;
    p.push_back(k);
    for (int i = 0; i < n; i++) {
        std::cin >> a[i];
        if (a[i] - k + 1 >= 1) p.push_back(a[i]);
    }
    for (int i = 0; i < m; i++) {
        std::cin >> b[i];
        if (b[i] + k <= w) p.push_back(b[i] + k);
    }
    std::sort(a.begin(), a.end());
    std::sort(b.begin(), b.end());
    std::sort(p.begin(), p.end());
    p.erase(std::unique(p.begin(),p.end()), p.end());

    auto sum_a = [&] (int L, int R) -> bool {
        auto it_L = std::lower_bound(a.begin(), a.end(), L);
        auto it_R = std::upper_bound(a.begin(), a.end(), R);
        return it_L != it_R;
    };

    auto sum_b = [&] (int L, int R) -> bool {
        auto it_L = std::lower_bound(b.begin(), b.end(), L);
        auto it_R = std::upper_bound(b.begin(), b.end(), R);
        return it_L != it_R;
    };

    std::map<int, int> dp;
    std::map<int, int> ans_pre;
    std::priority_queue<std::pair<int, int>, std::vector<std::pair<int, int>>, std::greater<std::pair<int, int>>> pq;

    int ans = INF, ans_i = 0;

    for (auto i : p) {
        if (sum_b(i - k + 1, i) == true) continue;
        int ql = k, qr = i - k;
        auto pre_it = std::lower_bound(a.begin(), a.end(), i - k + 1);
        if (pre_it == a.begin()) { // 前面没有红色
            dp[i] = 1;
        }
        else {
            int pre_pos = *(--pre_it);
            ql = std::max(ql, pre_pos), qr = std::min(qr, pre_pos + k - 1);
            if (ql > qr) continue;

            while (!dp.empty() && dp.begin()->first <= qr)
                pq.push({dp.begin()->second, dp.begin()->first}), dp.erase(dp.begin());

            while (!pq.empty() && pq.top().second < ql)
                pq.pop();
            
            if (pq.empty()) {std::cout << -1 << '\n'; return ;}
            dp[i] = pq.top().first + 1;
            ans_pre[i] = pq.top().second;
        }
        // std::cout << i << " " << dp[i] << "\n";
        if (std::upper_bound(a.begin(), a.end(), i) - a.begin() == n && ans > dp[i])
            ans = dp[i], ans_i = i;
    }

    std::vector<int> ans_ans;

    std::cout << ans << '\n';
    for (int i = ans_i;; ) {
        ans_ans.push_back(i - k + 1);
        if (ans_pre.find(i) == ans_pre.end())
            break;
        i = ans_pre[i];
    }
    std::sort(ans_ans.begin(), ans_ans.end());

    assert(ans_ans.size() == ans);

    for (auto x : ans_ans)
        std::cout << x << " ";
    std::cout << "\n";
}

int main() {
    std::ios::sync_with_stdio(0);
    std::cin.tie(0); std::cout.tie(0);

    int T; std::cin >> T;
    while (T--) solve();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

4
5 2 3 16
7 11 2 9 14
13 5
3 2 4 11
6 10 2
1 11
2 1 2 6
1 5
3
2 1 2 6
1 5
2

output:

4
1 6 9 14 
-1
2
1 4 
-1

result:

ok ok 4 cases (4 test cases)

Test #2:

score: -100
Runtime Error

input:

11000
3 8 2 53
32 3 33
35 19 38 20 1 30 10 6
7 10 1 42
3 14 4 36 28 40 22
17 20 12 41 27 7 1 19 13 9
6 6 13 78
55 76 53 32 54 58
62 45 21 4 7 61
8 7 3 68
9 26 54 31 22 3 38 65
34 16 58 47 52 29 53
5 8 4 33
33 5 30 6 15
27 12 9 28 19 2 13 10
6 1 2 48
8 12 48 1 41 31
40
7 6 7 61
20 19 30 52 49 17 40
3...

output:


result: