QOJ.ac

QOJ

ID提交记录ID题目HackerOwner结果提交时间测评时间
#934#276347#7686. The Phantom MenaceN_z_ship2077Success!2024-10-07 16:21:362024-10-07 16:21:36

詳細信息

Extra Test:

Wrong Answer
time: 8ms
memory: 108132kb

input:

1
1 50
lacakaapaaafaaaaaaaaaaaaaaaaaaaaaaaaaaapiuawiagaea
aeagaiwauipaaaaaaaaaaaaaaaaaaaaaaaaaaafaaapaakacal

output:

1 
1 

result:

wrong answer not cyclic isomorphism (test case 1)

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#276347#7686. The Phantom Menaceship2077WA 517ms333648kbC++142.1kb2023-12-05 20:10:472024-10-13 19:46:14

answer

#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
constexpr int M=2e6+5;
constexpr ull base=998244353;
vector<ull>pre1[M>>1],pre2[M>>1];ull pw[M];char s[M];
int n,m,T,Index,f[M],in[M],ou[M];unordered_map<ull,int>mp;
vector<pair<int,int>>g[M];vector<int>ans,ans1,ans2;
int read(){
	int x=0,f=1;char ch=getchar();
	while (!isdigit(ch)) {if (ch=='-') f=-1;ch=getchar();}
	while (isdigit(ch)) x=x*10+ch-48,ch=getchar();
	return x*f;
}
int idx(ull x){
	if (!mp[x]) return mp[x]=++Index;
	return mp[x];
}
void dfs(int x){
	while (!g[x].empty()){
		const int tmp1=g[x].back().first,
				  tmp2=g[x].back().second;
		g[x].pop_back();dfs(tmp1);ans.push_back(tmp2);
	}
}
int find(int x){return f[x]==x?x:f[x]=find(f[x]);}
bool check(){
	const int n=Index;int cnt=0;
	for (int i=1;i<=n;i++) f[i]=i,in[i]=ou[i]=0;
	for (int i=1;i<=n;i++)
		for (auto k:g[i]){
			const int j=k.first;
			in[j]++;ou[i]++;f[find(i)]=find(j);
		}
	for (int i=1;i<=n;i++)
		cnt+=find(i)==i;
	if (cnt>1) return 0;
	for (int i=1;i<=n;i++)
		if (in[i]^ou[i]) return 0;
	ans.clear();dfs(1);reverse(ans.begin(),ans.end());return 1;
}
void solve(){
	scanf("%d%d",&n,&m);
	for (int i=pw[0]=1;i<=m;i++) pw[i]=pw[i-1]*233;
	for (int i=1;i<=n;i++){
		scanf("%s",s+1);pre1[i].resize(m+1,0);
		for (int j=1;j<=m;j++) pre1[i][j]=pre1[i][j-1]*233+s[j];
	}
	for (int i=1;i<=n;i++){
		scanf("%s",s+1);pre2[i].resize(m+1,0);
		for (int j=1;j<=m;j++) pre2[i][j]=pre2[i][j-1]*233+s[j];
	}
	for (int i=0;i<m;i++){
		mp.clear();Index=0;
		for (int j=1;j<=n;j++)
			g[idx(pre1[j][i])].push_back({idx(pre1[j][m]-pre1[j][i]*pw[m-i]+base),j}),
			g[idx(pre2[j][m-i]+base)].push_back({idx(pre2[j][m]-pre2[j][m-i]*pw[i]),j+n});
		if (check()){ans1.clear();ans2.clear();
			for (auto x:ans)
				if (x<=n) ans1.push_back(x);
				else ans2.push_back(x-n);
			for (auto x:ans1) printf("%d ",x);puts("");
			for (auto x:ans2) printf("%d ",x);puts("");
			for (int j=1;j<=Index;j++) g[j].clear(); return ;
		}
		for (int j=1;j<=Index;j++) g[j].clear();
	}  puts("-1");
}
int main(){
	scanf("%d",&T);
	while (T--) solve();
	return 0;
}