社区讨论
有心人可以看看
P11230[CSP-J 2024] 接龙参与者 1已保存回复 0
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 0 条
- 当前快照
- 1 份
- 快照标识符
- @mhk7cncu
- 此快照首次捕获于
- 2025/11/04 14:43 4 个月前
- 此快照最后确认于
- 2025/11/04 14:43 4 个月前
场上代码,我已经放弃了,但是不知道哪里错的,又WA又TLE,10pts
CPP//#pragma GCC optimize(2,3,"Ofast","inline")
#include <bits/stdc++.h>
#define endl "\n"
#define pb(x) push_back(x)
#define pii pair<int,int>
#define fi first
#define se second
#define mp(x,y) make_pair(x,y)
using namespace std;
void inline solve();
signed main(){
ios::sync_with_stdio(false);
cin.tie(0),cout.tie(0);
int t=1;cin >> t;
while(t--) solve();
return 0;
}
const int N=2e5+10,M=2e5,R=100,inf=2114514134;
int n,k,q,l[N];
vector<int> s[N],dp[N],g[N];
int a[N],b[N];bool ans[N];
vector<pii> p[N],c[N];
void inline solve(){
cin >> n >> k >> q;
for(int i=1;i<=n;i++){
s[i].clear(),dp[i].clear(),g[i].clear();
a[i]=b[i]=l[i]=0;
}
for(int i=1;i<=M;i++) c[i].clear();
for(int i=1;i<=q;i++) ans[i]=false;
for(int i=1;i<=R;i++) p[i].clear();
for(int i=1;i<=n;i++){
cin >> l[i];
s[i].pb(0),g[i].pb(inf),dp[i].pb(inf);
for(int j=1;j<=l[i];j++){
int x;
cin >> x;
s[i].pb(x),g[i].pb(inf),dp[i].pb(inf);
c[x].pb(mp(i,j));
}
}
for(int i=1;i<=q;i++){
int r,c;
cin >> r >> c;
p[r].pb(mp(c,i));
}
a[1]=2114514134;
for(int i=1;i<=R;i++){
for(int j=1;j<=n;j++){
for(int x=1;x<=l[j];x++){
dp[j][x]=g[j][x]=inf;
}
}
for(int j=1;j<=M;j++){
for(auto x:c[j]){
if(x.fi!=a[j] && a[j]!=0 || b[j]!=0){
g[x.fi][x.se]=1;
}
}
}
for(int j=1;j<=M;j++) a[j]=b[j]=0;
for(int j=1;j<=n;j++){
for(int x=2;x<=l[j];x++){
dp[j][x]=min(dp[j][x],dp[j][x-1]+1);
dp[j][x]=min(dp[j][x],g[j][x-1]+1);
if(dp[j][x]<=k){
if(a[s[j][x]]==0){
a[s[j][x]]=j;
}else if(a[s[j][x]]!=j){
b[s[j][x]]=j;
}
}
}
}
for(auto x:p[i]){
if(a[x.fi]){
ans[x.se]=true;
}
}
}
for(int i=1;i<=q;i++){
if(ans[i]) cout << 1 << endl;
else cout << 0 << endl;
}
}
回复
共 0 条回复,欢迎继续交流。
正在加载回复...