QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#725508#9574. StripsXiaoMo247#WA 41ms3608kbC++202.8kb2024-11-08 18:23:592024-11-08 18:23:59

Judging History

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

  • [2024-11-08 18:23:59]
  • 评测
  • 测评结果:WA
  • 用时:41ms
  • 内存:3608kb
  • [2024-11-08 18:23:59]
  • 提交

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_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;
    }

    if (ans == INF) {
        std::cout << -1 << '\n';
        return ;
    }

    std::vector<int> ans_ans;

    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);
    if(ans_ans.size() != ans) {
        std::cout << -1 << "\n";
        return ;
    }

    std::cout << ans << '\n';
    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: 3608kb

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
Wrong Answer
time: 41ms
memory: 3564kb

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:

2
2 32 
7
3 4 14 22 28 36 40 
3
22 46 64 
8
1 7 20 24 30 36 54 63 
3
3 14 30 
6
1 7 11 30 41 47 
4
14 27 34 47 
2
42 65 
1
27 
1
9 
1
62 
5
24 33 42 47 60 
2
3 31 
-1
3
2 15 33 
3
25 30 42 
3
2 17 59 
-1
2
53 65 
3
49 58 65 
3
43 60 78 
1
78 
4
1 11 15 21 
5
3 7 17 36 48 
2
1 44 
2
7 25 
1
4 
4
9 18...

result:

wrong answer Participant didn't find a solution but the jury found one. (test case 14)