QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#729189#9574. Stripsucup-team987#WA 27ms3840kbC++201.6kb2024-11-09 16:39:322024-11-09 16:39:33

Judging History

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

  • [2024-11-09 16:39:33]
  • 评测
  • 测评结果:WA
  • 用时:27ms
  • 内存:3840kb
  • [2024-11-09 16:39:32]
  • 提交

answer

#include<iostream>
#include<vector>
#include<algorithm>
#include<cassert>
using namespace std;
int K;
vector<int>solve(vector<int>A,int L,int R)
{//[L,R)
	vector<int>ans;
	for(int a:A)
	{
		if(ans.empty()||ans.back()+K<=a)ans.push_back(a);
	}
	assert(!ans.empty());
	int over=ans.back()+K-R;
	vector<int>del(ans.size());
	for(int i=ans.size()-1;i>=0;i--)
	{
		int l=i==0?L:ans[i-1]+K;
		assert(l<=ans[i]);
		int t=min(over,ans[i]-l);
		del[i]=t;
		over-=t;
	}
	if(over>0)return vector<int>();
	int D=0;
	for(int i=0;i<ans.size();i++)
	{
		D+=del[i];
		ans[i]-=D;
	}
	return ans;
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int T;cin>>T;
	for(;T--;)
	{
		int N,M,W;
		cin>>N>>M>>K>>W;
		vector<pair<int,bool> >A(N+M+2);
		for(int i=0;i<N;i++)
		{
			int a;cin>>a;
			A[i]=make_pair(a,false);
		}
		for(int i=0;i<M;i++)
		{
			int a;cin>>a;
			A[N+i]=make_pair(a,true);
		}
		A[N+M]=make_pair(0,true);
		A[N+M+1]=make_pair(W+1,true);
		sort(A.begin(),A.end());
		bool ok=true;
		vector<int>ans;
		for(int i=0;i+1<A.size();)
		{
			assert(A[i].second);
			int j=i+1;
			while(!A[j].second)j++;
			if(i+1<j)
			{
				vector<int>now;now.reserve(j-i);
				for(int k=i+1;k<j;k++)now.push_back(A[k].first);
				vector<int>T=solve(now,A[i].first+1,A[j].first);
				if(T.empty())
				{
					ok=false;
					break;
				}
				for(int L:T)ans.push_back(L);
			}
			i=j;
		}
		if(!ok)cout<<"-1\n";
		else
		{
			cout<<ans.size()<<"\n";
			for(int i=0;i<ans.size();i++)cout<<ans[i]<<(i+1==ans.size()?"\n":" ");
		}
	}
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
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
2 7 10 14
-1
2
1 5
-1

result:

ok ok 4 cases (4 test cases)

Test #2:

score: -100
Wrong Answer
time: 27ms
memory: 3668kb

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
4 33
7
3 6 16 26 28 36 40
3
32 48 66
8
3 13 22 26 31 44 55 66
3
5 15 30
6
1 8 12 38 41 47
4
17 30 39 55
2
52 84
1
31
1
22
1
62
5
24 33 43 48 64
2
16 57
3
11 20 31
3
3 18 33
3
25 30 79
3
3 28 60
4
1 11 21 33
2
54 66
3
50 60 69
3
50 67 79
1
81
4
4 11 16 43
5
3 14 17 36 50
2
1 45
2
7 25
1
4
4
13 18 2...

result:

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