QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#734775 | #9574. Strips | Ufowoqqqo | WA | 58ms | 3840kb | C++14 | 1.8kb | 2024-11-11 15:03:01 | 2024-11-11 15:03:09 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+5;
int n,m,k,w;
int a[N],b[N];
int cur;
vector<int>res;
bool solve(int l,int r)
{
if(l>r)return true;
vector<int>v;
while(cur<=n&&a[cur]>=l&&a[cur]<=r)
{
v.push_back(a[cur]);
cur++;
}
if(v.empty())return true;
int x=v.front(),y=v.back();
int len=y-x+1;
int cnt=(len-1)/k+1;
if(l+cnt*k-1>=y&&l+cnt*k-1<=r)
{
for(int i=0;i<cnt;i++)
{
res.push_back(l);
l+=k;
}
return true;
}
if(r-cnt*k+1<=x&&r-cnt*k+1>=l)
{
for(int i=0;i<cnt;i++)
{
res.push_back(r-k+1);
r-=k;
}
return true;
}
if(x+cnt*k-1<=r)
{
for(int i=0;i<cnt;i++)
{
res.push_back(x);
x+=k;
}
return true;
}
if(y-cnt*k+1>=l)
{
for(int i=0;i<cnt;i++)
{
res.push_back(y-k+1);
y-=k;
}
return true;
}
return false;
}
bool work()
{
sort(a+1,a+n+1);
sort(b+1,b+m+1);
res.clear();
cur=1;
if(!solve(1,b[1]-1))return false;
for(int i=1;i<m;i++)
if(!solve(b[i]+1,b[i+1]-1))return false;
if(!solve(b[m]+1,w))return false;
return true;
}
int main()
{
int t;
cin>>t;
while(t--)
{
cin>>n>>m>>k>>w;
for(int i=1;i<=n;i++)
cin>>a[i];
for(int i=1;i<=m;i++)
cin>>b[i];
if(!work())cout<<-1<<endl;
else
{
cout<<res.size()<<endl;
for(auto &x:res)
cout<<x<<" ";
cout<<endl;
}
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 3840kb
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: 58ms
memory: 3792kb
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 17 3 4 14 22 28 29 30 31 32 33 34 35 36 37 38 39 40 3 22 46 66 9 1 4 7 22 25 30 38 54 65 3 3 14 30 20 1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 41 43 45 47 4 17 27 34 47 3 52 63 74 1 27 1 9 1 62 14 24 43 41 39 37 35 33 48 50 52 54 56 58 60 2 4 31 3 11 19 29 3 3 16 33 7 30 29 2...
result:
wrong answer Integer parameter [name=c] equals to 17, violates the range [-1, 7] (test case 2)