QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#758529#9574. Stripsnahida_qaqWA 1ms5636kbC++231.6kb2024-11-17 18:43:162024-11-17 18:43:17

Judging History

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

  • [2024-11-17 18:43:17]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:5636kb
  • [2024-11-17 18:43:16]
  • 提交

answer

#include <bits/stdc++.h>
#define int long long
#define io ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define pb push_back
using namespace std;
const int N=1e6+5,mod1=1e9+7,mod2=998244353,inf=1e18;
typedef pair<int,int> pi;
int a[N],b[N];
void solve()
{
    int n,m,k,w;
    cin>>n>>m>>k>>w;
    for(int i=1;i<=n;i++)cin>>a[i];
    sort(a+1,a+1+n);
    for(int i=1;i<=m;i++)cin>>b[i];
    b[m+1]=w+1;
    m++;
    sort(b+1,b+1+m);
    vector<int>ans;
    for(int i=0;i<m;i++)
    {
        int x=b[i],y=b[i+1];
        int w=lower_bound(a+1,a+1+n,x)-a;
        if(a[w]>y)continue;
        int cnt=0;
        vector<pi>q;
        int last=x;
        int sum=0;
        for(int j=w;a[j]<=y&&j<=n;j++)
        {
            if(a[j]>last)
            {
                q.pb({a[j],a[j]+k-1});
                sum+=a[j]-last-1;
                last=a[j]+k-1;
                cnt++;
            }
        }
        int s=max(0ll,last-y+1);
        if(sum<s)
        {
            cout<<-1<<'\n';
            return ;
        }
        for(int j=cnt-1;j>=0;j--)
        {
            if(s)
            {
                ans.pb(q[j].first-s);
                if(j==0)s-=q[j].first-q[j-1].second-1,s=0;
            }
            else
            {
                ans.pb(q[j].first);
            }
        }
    }
    cout<<ans.size()<<'\n';
    sort(ans.begin(),ans.end());
    for(auto i:ans)cout<<i<<' ';
    cout<<'\n';
}
signed main()
{
    io;
    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: 1ms
memory: 5636kb

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

result:

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