QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#806076#9574. StripszhangwansenWA 0ms3512kbC++231.8kb2024-12-08 21:12:222024-12-08 21:12:23

Judging History

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

  • [2024-12-08 21:12:23]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3512kb
  • [2024-12-08 21:12:22]
  • 提交

answer

#include <bits/stdc++.h>
#define int long long
using namespace std;
void solve()
{
    int n, m, k, w;
    cin >> n >> m >> k >> w;
    vector<int> a(n + 1);
    vector<int> b(m + 2);
    for (int i = 1; i <= n; i++)
        cin >> a[i];
    b[0] = 0;
    b[m + 1] = w + 1;
    for (int i = 1; i <= m; i++)
        cin >> b[i];
    sort(a.begin(), a.end());
    int idx = 1;
    sort(b.begin(), b.end());
    vector<int> res;
    for (int i = 1; i <= m + 1; i++)
    {

        int l = b[i - 1] + 1, r = b[i] - 1; //[l,r]可放
        if(r < l ) continue;
        // cout << l << ' ' << r << endl;
        vector<int> c;
        while (idx <= n && l <= a[idx] && a[idx] <= r)
        {
            // cout << a[idx] <<endl;
            c.push_back(a[idx++]);
        }
        vector<int> t;
        int rr = l - 1;
        for (auto &lr : c)
        {

            if (lr > rr)
            {
                t.push_back(lr);
                // cout << lr << endl;
                rr = lr + k - 1;
            }
        }
        // cout << endl;
        int idx = t.size() - 1;
        if (idx >= 0 && t[idx] + k - 1 > r)
        {
            // t[idx] + k - 1  ==  r
            // cout << t[idx] << endl;
            if (t[idx] + k - 1 > r)
            {
                t[idx] = r - k + 1 ;
                r = t[idx] - 1;
                // cout << r << endl;
                idx--;
            }
        }

        if (l > r)
        {
            puts("-1");
            return;
        }
        res.insert(res.end(), t.begin(), t.end());
    }
    cout << res.size() << endl;
    for (auto &item : res)
    {
        cout << item << ' ';
    }
    cout << endl;
    return;
}
signed main()
{
    int t = 1;
    cin >> t;
    while (t--)
        solve();
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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 10 14 
3
2 6 7 
2
1 5 
-1

result:

wrong answer There are more than one stripe covering cell 7 (test case 2)