QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#829304#9574. Strips1145141919#WA 30ms11900kbC++172.1kb2024-12-24 09:03:272024-12-24 09:03:59

Judging History

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

  • [2024-12-24 09:03:59]
  • 评测
  • 测评结果:WA
  • 用时:30ms
  • 内存:11900kb
  • [2024-12-24 09:03:27]
  • 提交

answer

#include<bits/stdc++.h>
#define For(i,l,r) for(int i=l,i##_e=r;i<=i##_e;++i)
#define rFor(i,r,l) for(int i=r,i##_e=l;i>=i##_e;--i)
#define y0 y_zero
#define y1 y_one
#define all(a) a.begin(),a.end()
#define cmin(a,b) a=min(a,b)
#define cmax(a,b) a=max(a,b)
#define vect basic_string
// #define ensure(_) if(!(_)) __builtin_unreachable();
using namespace std;
using u32=unsigned;
using i64=long long;
using ll=long long;
using u64=unsigned long long;
using ull=unsigned long long;
#if __SIZEOF_POINTER__==8
using i128=__int128;
using u128=__uint128_t;
#endif
using pii=array<int,2>;
using pll=array<ll,2>;
using a3=array<int,3>;
using a4=array<int,4>;
#define mtc() int T; cin>>T; while(T--) work();

const int N=5e5+10,Z=1e9;
int n,m,a[N],b[N],k,lst,c[N];
bool nos;
vect<int> ans;
void solve(int L,int R) {
	int l=lst+1,r=lst;
	while(r<n && a[r+1]<R) ++r; lst=r;
	if(l>r) return;
	// cerr<<L<<" "<<R<<" "<<l<<" "<<r<<"\n";
	if(L+k>=R) return nos=1,void();
	int t=0;
	For(i,l,r) c[++t]=a[i];
	For(i,1,r-l+1) {
		if(L+k*i>=R) break;
		c[++t]=L+k*i;
	}
	For(i,1,r-l+1) {
		if(R-1-k*(i-1)<=L) break;
		c[++t]=R-1-k*(i-1);
	}
	// cerr<<L<<" "<<R<<" "<<l<<" "<<r<<"\n";
	sort(c+1,c+t+1); t=unique(c+1,c+t+1)-c-1;
	static int f[N],g[N];
	int j=0;
	For(i,1,t) {
		if(c[i]<L+k) { f[i]=Z; continue; }
		while(c[i]-c[j+1]>=k) ++j;
		f[i]=f[j]+1; g[i]=j;
		// cerr<<i<<" "<<j<<"\n";
		if(!binary_search(a+1,a+n+1,c[i])) {
			if(f[i-1]<f[i]) f[i]=f[i-1],g[i]=-114514;
		}
	}
	// cerr<<f[t]<<"\n";
	if(f[t]>n) return nos=1,void();
	int x=t;
	while(x) {
		if(g[x]==-114514) --x;
		else ans+=c[x]-k+1,x=g[x];
	}
}
void work() {
	cin>>n>>m>>k; cin>>b[m+1]; ++b[m+1];
	For(i,1,n) cin>>a[i];
	For(i,1,m) cin>>b[i];
	sort(a+1,a+n+1); sort(b+1,b+m+1);
	lst=0; nos=0; ans={};
	For(i,1,m+1) solve(b[i-1],b[i]);
	if(nos) cout<<"-1\n";
	else {
		cout<<ans.size()<<"\n";
		for(auto x:ans) cout<<x<<" "; cout<<"\n";
	}
}
int main() {
#ifdef LOCAL
	freopen(".in","r",stdin);
	// freopen(".out","w",stdout);
	// freopen(".debug","w",stderr);
#endif
#ifndef with_buffer
	ios::sync_with_stdio(0); cin.tie(0);
#endif
	mtc();
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 11900kb

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

result:

ok ok 4 cases (4 test cases)

Test #2:

score: -100
Wrong Answer
time: 30ms
memory: 9776kb

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 
7
4 3 14 22 40 36 28 
3
32 46 66 
8
7 1 26 20 31 36 54 63 
-1
6
30 11 7 1 47 41 
5
17 8 39 27 48 
2
65 48 
2
28 18 
1
9 
1
62 
5
24 43 33 60 48 
2
3 31 
3
20 11 31 
3
3 15 33 
3
30 25 42 
3
3 17 60 
4
21 11 1 33 
2
66 53 
3
50 58 65 
3
62 43 78 
1
81 
4
1 11 21 15 
5
3 7 36 17 48 
2
1 44 
2
...

result:

wrong answer Participant didn't find a solution but the jury found one. (test case 5)