QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#751903#9574. StripsHashbinWA 0ms3612kbC++232.7kb2024-11-15 21:14:412024-11-15 21:14:41

Judging History

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

  • [2024-11-15 21:14:41]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3612kb
  • [2024-11-15 21:14:41]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define int long long
void solve()
{
    int n, m, k, w;
    cin >> n >> m >> k >> w;
    vector<int> a(n + 10), b(m + 10);
    for (int i = 1; i <= n; i++)
    {
        cin >> a[i];
    }
    for (int i = 1; i <= m; i++)
        cin >> b[i];
    sort(a.begin() + 1, a.begin() + n + 1);
    sort(b.begin() + 1, b.begin() + m + 1);
    int flag = 1;
    vector<int>e;
    auto check = [&](int l, int r) -> int
    {
        vector<int>q;
        int cnt = 0;
        int k1 = lower_bound(a.begin() + 1, a.begin() + n + 1, l) - a.begin();
        int kk = lower_bound(a.begin() + 1, a.begin() + n + 1, r) - a.begin();
        if (k1 == n + 1)
            return 0;
        int sum = 0;
        for (int i = k1 ; i < kk; i++)
        {
            if (l >= a[i])
                continue;
            if (a[i] + k - 1 < r)
                sum += a[i] - l - 1, l = a[i] + k - 1, cnt++,q.push_back(a[i]);
            if (a[i] + k - 1 >= r)
            {
                int w = a[i] + k - 1 - r + 1;
                if (sum >= w)
                {
                    sum -= w, l = r - 1, cnt++;
                    int len=q.size()-1;
                    int pos=len+1;
                    for(int j=len;j>=1;j--)
                    {
                        if(q[j]-(q[j-1]+k-1)-1>=w)  
                        {
                            q[j]-=w;
                            pos=j;
                            break;
                        }
                        else
                        {
                            w-=q[j]-(q[j-1]+k-1)-1;
                            q[j]=q[j-1]+k;
                        }
                    }
                    for(int j=pos+1;j<=len;j++)  q[j]=q[j-1]+k;
                    q.push_back(r-k);
                }
                else
                {
                    flag = 0;
                    return 0;
                }
            }
        }
        if(!q.empty()) 
        {
            for(auto x : q)  e.push_back(x);
        }
        return cnt;
    };
    int ans = 0;
    b[0]=0;
    for (int i = 1; i <= m; i++)
    {
        ans += check(b[i-1], b[i]);
        if (flag == 0)
        {
            cout << "-1" << '\n';
            return;
        }
    }
    if (w != b[m])
        ans += check(b[m], w+1);
    if (flag == 0)
    {
        cout << "-1" << '\n';
        return;
    }
    for(auto x : e)  cout << x <<' ';
    cout <<'\n'; 
}
signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    int t = 1;
    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: 3612kb

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:

2 7 10 14 
-1
1 5 
-1

result:

wrong answer There is no stripe covering red cell 2 (test case 1)