社区讨论
WA求条,悬两关
P14024 [ICPC 2024 Nanjing R] 纸条参与者 2已保存回复 2
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 2 条
- 当前快照
- 1 份
- 快照标识符
- @mhja99ch
- 此快照首次捕获于
- 2025/11/03 23:16 4 个月前
- 此快照最后确认于
- 2025/11/03 23:16 4 个月前
CPP
#include<bits/stdc++.h>
using namespace std;
int cl[200005];
int c[200005];
int cnt;
int cntans;
int ans[200005];
//1:red 2: black 3:white
main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int T;
cin>>T;
for(int KKK=1; KKK<=T; KKK++) {
int n,m,k,w;
cin>>n>>m>>k>>w;
cnt=cntans=0;
for(int i=1; i<=w; i++) cl[i]=3,c[i]=ans[i]=0;
for(int i=1; i<=n; i++) {
int x;
cin>>x;
cl[x]=1;
}
for(int i=1; i<=m; i++) {
int x;
cin>>x;
cl[x]=2;
c[++cnt]=x;
}
c[0]=0;
c[++cnt]=w+1;
sort(c,c+1+cnt);
for(int i=0; i<=cnt-1; i++) {
int now=c[i];
int cha=c[i+1]-c[i]-1;
if(c[i+1]==c[i]) continue;
if(cha<k){
for(int j=c[i]+1;j<=c[i+1];j++) if(cl[j]==1){
cout<<-1<<'\n';
goto end;
}
continue;
}
for(int j=c[i]+1;j<=c[i+1];j++){
if(cl[j]==1){
ans[++cntans]=j;
if(j+k-1>=c[i+1]){
for(int z=cntans;z>=1;z--){
if(ans[z]>c[i]+1){
ans[z]--;
if(cl[ans[z]+k]==1){
cntans++;
for(int y=cntans;y>=z+2;y--) ans[y]=ans[y-1];
ans[z+1]=ans[z]+k;
cout<<ans[z+1]<<' '<<ans[z+2]<<'\n';
if(ans[z+1]+k-1>ans[z+2]){
cout<<-1<<'\n';
goto end;
}
}
}
else if(ans[z]==c[i]+1){
cout<<-1<<'\n';
goto end;
}
else break;
}
}
j+=k;
j--;
}
}
}
cout<<cntans<<'\n';
for(int i=1;i<=cntans;i++) cout<<ans[i]<<' ';
cout<<'\n';
end:
;
}
}
/*
1
5 2 3 16
7 11 2 9 14
13 5
*/
回复
共 2 条回复,欢迎继续交流。
正在加载回复...