QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#276342#7686. The Phantom Menaceship2077WA 390ms84264kbC++142.1kb2023-12-05 20:07:232023-12-05 20:07:24

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)
  • [2023-12-05 20:07:24]
  • 评测
  • 测评结果:WA
  • 用时:390ms
  • 内存:84264kb
  • [2023-12-05 20:07:23]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
constexpr int M=1e6+5;
constexpr ull base=998244353;
vector<ull>pre1[M],pre2[M];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<n;i++){
		mp.clear();Index=0;
		for (int j=1;j<=n;j++)
			g[idx(pre1[j][i])].push_back({idx(pre1[j][n]-pre1[j][i]*pw[n-i]+base),j}),
			g[idx(pre2[j][n-i]+base)].push_back({idx(pre2[j][n]-pre2[j][n-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;
}

详细

Test #1:

score: 100
Accepted
time: 8ms
memory: 82300kb

input:

2
3 3
abc
ghi
def
bcd
efg
hia
1 3
abc
def

output:

1 3 2 
1 2 3 
-1

result:

ok 2 cases (2 test cases)

Test #2:

score: 0
Accepted
time: 390ms
memory: 84264kb

input:

1000000
1 1
b
b
1 1
a
b
1 1
b
a
1 1
a
a
1 1
b
b
1 1
a
b
1 1
b
a
1 1
a
a
1 1
b
b
1 1
a
b
1 1
b
a
1 1
a
a
1 1
b
b
1 1
a
b
1 1
b
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1 
-1
-1
-1
1 
1 
-1
-1
-1
1 
1 
-1
-1
-1
1 
1 
-1
-1
-1
-1
1 
1 
-1
-1
-1
1 
1 
-1
-1
-1
1 
1 
-1
-1
-1
1 
1 
-1
...

result:

wrong answer not cyclic isomorphism (test case 3)