QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#527442#7686. The Phantom MenacehansiyuanCompile Error//C++142.8kb2024-08-22 15:20:462024-08-22 15:20:47

Judging History

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

  • [2024-10-08 14:11:03]
  • hack成功,自动添加数据
  • (/hack/941)
  • [2024-10-08 10:05:28]
  • hack成功,自动添加数据
  • (/hack/940)
  • [2024-10-07 19:51:15]
  • hack成功,自动添加数据
  • (/hack/938)
  • [2024-10-07 19:28:01]
  • hack成功,自动添加数据
  • (/hack/937)
  • [2024-10-07 17:16:32]
  • hack成功,自动添加数据
  • (/hack/936)
  • [2024-10-07 16:53:09]
  • hack成功,自动添加数据
  • (/hack/935)
  • [2024-10-07 16:22:17]
  • hack成功,自动添加数据
  • (/hack/934)
  • [2024-08-22 15:20:47]
  • 评测
  • [2024-08-22 15:20:46]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef long long lol;
const int N=4e6+5;
const lol p1=131,p2=1e9+9,nip=526717562;
int T,n,m,tot,cnt[3],ok;
int p[N];
int res[N][3];
lol pw[N];
string A[N],B[N];
lol Alh[N],Blh[N],Arh[N],Brh[N];
map<string,vector<int> > mp;
map<int,int> mpl,mpr;
int in[N],out[N];
int h[N],to[N],ne[N],we[N],bel[N],idx;
void add(int u,int v,int w,int op){
	//printf("%d %d\n",u,v);
	out[u]++; in[v]++;
	to[++idx]=v; we[idx]=w; bel[idx]=op;
	ne[idx]=h[u]; h[u]=idx;
}
void add_front(lol &hsh,int x){
	hsh = (hsh*p1+x)%p2;
}
void add_back(lol &hsh,int x,int p){
	hsh = (hsh+pw[p]*x%p2)%p2;
}
void del_front(lol &hsh,int x){
	hsh = (hsh-x+p2)%p2*nip%p2;
}
void del_back(lol &hsh,int x,int p){
	hsh = (hsh-pw[p]*x%p2+p2)%p2;
}
void init(){
	ok=0;
	mp.clear();
	for(int i=1;i<=n;i++)
		Alh[i] = Blh[i] = Arh[i] = Brh[i] = 0;
}
void dfs(int u){
	for(int i=h[u];i;i=head[u]){
		h[u] = ne[i];
		dfs(to[i]);
		res[++cnt[bel[i]]][bel[i]]=we[i];
	}
}
int main(){
	int a = clock();
	pw[0] = 1;
	for(int i=1;i<=1e6;i++) pw[i]=(pw[i-1]*p1)%p2;
	scanf("%d",&T);
	while(T--){
		init();
		scanf("%d%d",&n,&m);
		for(int i=1;i<=n;i++) cin>>A[i];
		for(int i=1;i<=n;i++) cin>>B[i];

		bool flag=1;
		for(int i=1;i<=n;i++) mp[A[i]].push_back(i);
		for(int i=1;i<=n;i++){
			if(!mp[B[i]].size()){flag=0; break;}
			p[mp[B[i]].back()] = i;
			mp[B[i]].pop_back();
		}
		if(flag){
			for(int i=1;i<=n;i++) printf("%d ",i); puts("");
			for(int i=1;i<=n;i++) printf("%d ",p[i]); puts("");
			continue;
		}

		for(int i=1;i<=n;i++)
			for(int j=0;j<m;j++){
				add_back(Arh[i],A[i][j]-'a'+1,j);
				add_back(Brh[i],B[i][j]-'a'+1,j);
			}
		for(int p=0;p<m-1;p++){
			for(int i=1;i<=tot;i++) h[i]=in[i]=out[i]=0;
			idx=0;
			mpl.clear(); mpr.clear(); tot=0;
			cnt[1]=cnt[2]=0;
			for(int i=1;i<=n;i++){
				int ca=A[i][p]-'a'+1,cb=B[i][m-p-1]-'a'+1;
				del_front(Arh[i],ca);
				del_back(Brh[i],cb,m-p-1);
				add_back(Alh[i],ca,p);
				add_front(Blh[i],cb);
			}
			bool flag=1;
			for(int i=1;i<=n;i++){
				if(!mpl[Alh[i]]) mpl[Alh[i]]=++tot;
				if(!mpr[Arh[i]]) mpr[Arh[i]]=++tot;
				add(mpl[Alh[i]],mpr[Arh[i]],i,1);
			}
			for(int i=1;i<=n;i++){
				if(!mpl[Blh[i]]) mpl[Blh[i]]=++tot;
				if(!mpr[Brh[i]]) mpr[Brh[i]]=++tot;
				add(mpr[Brh[i]],mpl[Blh[i]],i,2);
			}
			// for(int i=1;i<=n;i++) printf("%d|%d ",Alh[i],Arh[i]); puts("");
			// for(int i=1;i<=n;i++) printf("%d|%d ",Blh[i],Brh[i]); puts("");
			// for(int i=1;i<=tot;i++){
			// 	for(int j=h[i];j;j=ne[j])
			// 		printf("%d--%d\n",i,to[j]);
			// 	puts("");
			// }
			for(int i=1;i<=tot;i++) if(in[i]!=out[i]) flag=0;
			if(!flag) continue;
			dfs(1);
			if(cnt[1]==n && cnt[2]==n){
				ok=1;
				for(int i=n;i>=1;i--) printf("%d ",res[i][1]); puts("");
				for(int i=n;i>=1;i--) printf("%d ",res[i][2]); puts("");
				break;
			}
		}
		if(!ok) puts("-1");
	}
	cerr<<clock()-a<<"ms"<<endl;
	return 0;
}

Details

answer.code: In function ‘void dfs(int)’:
answer.code:41:28: error: ‘head’ was not declared in this scope
   41 |         for(int i=h[u];i;i=head[u]){
      |                            ^~~~
answer.code: In function ‘int main()’:
answer.code:51:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   51 |         scanf("%d",&T);
      |         ~~~~~^~~~~~~~~
answer.code:54:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   54 |                 scanf("%d%d",&n,&m);
      |                 ~~~~~^~~~~~~~~~~~~~