QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#732537#9574. Stripsucup-team059WA 0ms3796kbC++202.9kb2024-11-10 15:03:462024-11-10 15:03:54

Judging History

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

  • [2024-11-10 15:03:54]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3796kb
  • [2024-11-10 15:03:46]
  • 提交

answer

#include <bits/stdc++.h>
#define ll long long
void solve() {
    int n, m, k, w;
    std::cin >> n >> m >> k >> w;

    std::vector<int> a(n), b(n);
    std::vector<std::pair<int, int>> p;
    for (int i = 0; i < n; i++){
        std::cin >> a[i];
        p.push_back({a[i], 0});
    }
    for (int i = 0; i < m; i++){
        std::cin >> b[i];
        p.push_back({b[i], 1});
    }
    p.push_back({0, 1});
    p.push_back({w + 1, 1});
    std::sort(p.begin(), p.end());
    int siz = p.size();
    int L = 0, R = 0, Li = 0, Ri = 0;
    std::vector<int> ans;
    while(Li < siz){
        while (p[Li].second == 1){
            Li++;
        }
        Ri = Li;
        std::vector<int> r;
        while (p[Ri].second == 0){
            r.push_back(p[Ri].first);
            Ri++;
        }
        L = p[Li - 1].first + 1;
        R = p[Ri].first - 1;
//        for (auto z : r){
//            std::cout << z << " ";
//        }
//        std::cout << '\n';
        if (!r.empty()) {
            std::stack<int> block;
            block.push(r[0] - L);
            int st = 0;
            std::vector<int> ret;
            ret.push_back(r[0]);
            for (int i = 1; i < r.size(); i++){
                while (r[i] - r[st] < k){
                    i++;
                }
                int ed = r[st] + k - 1;
                block.push(r[i] - ed - 1);
                st = i;
                ret.push_back(r[i]);
            }
            int ed =  ret.back() + k - 1;
            int x = ed - R;
            if (x > 0){
                int j = ret.size() - 1;
                int Fn = ret.back();
                while (!block.empty() && x){
                    int y = block.top();
                    block.pop();
                    int d = std::min(y, x);
                    x -= d;
                    Fn -= d;
                    if (d == y){
                        Fn = r[j];
                    }
                    j--;
                }
                if (x){
                    std::cout << -1 << '\n';
                    return;
                }
                int lst = Fn;
                for (int i : ret){
                    if (i < Fn){
                        ans.push_back(i);
                    }else{
                        ans.push_back(lst);
                        lst += k;
                    }
                }
            }else{
                for (int i : ret){
                    ans.push_back(i);
                }
            }
        }
        Li = Ri + 1;
    }


    std::cout << ans.size() << '\n';
    for (int i = 0; i < ans.size(); i++){
        std::cout << ans[i] << " \n"[i == (int)ans.size() - 1];
    }

}
int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);

    int t;

    std::cin >> t;

    while (t--){
        solve();
    }

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3796kb

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
2 7 9 14
-1
2
1 5
-1

result:

wrong answer There are more than one stripe covering cell 9 (test case 1)