QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#564144#7686. The Phantom MenacesyxsyxWA 623ms365232kbC++143.7kb2024-09-14 20:46:002024-09-14 20:46:01

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-09-14 20:46:01]
  • 评测
  • 测评结果:WA
  • 用时:623ms
  • 内存:365232kb
  • [2024-09-14 20:46:00]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int N=2000005,K=26;
const long long mod=1000000000000000003ll,BASE=131;
int T;
int n,m;
string a[N],b[N];
long long fac[N];
vector <long long> hsha[N][2],hshb[N][2];
int srta[N],srtb[N];
bool cmpa(int x,int y){return a[x]<a[y];}
bool cmpb(int x,int y){return b[x]<b[y];}
bool check0()
{
	for(int i=1;i<=n;i++) srta[i]=srtb[i]=i;
	sort(srta+1,srta+n+1,cmpa);
	sort(srtb+1,srtb+n+1,cmpb);
	for(int i=1;i<=n;i++) if(a[srta[i]]!=b[srtb[i]]) return false;
	for(int i=1;i<=n;i++) printf("%d ",srta[i]);printf("\n");
	for(int i=1;i<=n;i++) printf("%d ",srtb[i]);printf("\n");
	return true;
}
long long h[N];
int cnth;
int vis[N],deg[N];
struct E{int v,id;};
vector <E> g[N];
int st[N];
void addedge(long long u,long long v,int id)
{
	u=lower_bound(h+1,h+cnth+1,u)-h;
	v=lower_bound(h+1,h+cnth+1,v)-h;
//	printf("%lld %lld %d\n",u,v,id);
	swap(u,v);
	g[u].push_back((E){v,id});
	deg[u]++;deg[v]--;
}
int res[N],cnt,ans[2][N],cnt0,cnt1;
void dfs(int x)
{
	vis[x]=1;
	while(st[x]<g[x].size())
	{
		int v=g[x][st[x]].v,id=g[x][st[x]].id;
		st[x]++;
		dfs(v);
		res[++cnt]=id;
	}
}
void clr()
{
	for(int i=1;i<=cnth;i++)
	{
		vis[i]=deg[i]=0;
		g[i].clear();st[i]=0;
	}
	cnt=0;
}
bool chk()
{
	for(int i=1;i<=cnth;i++) if(deg[i]) return false;
	return true;
}
bool check(int len)
{
//	printf("%d:::\n",len);
	int now=0;
	for(int i=1;i<=n;i++) h[++now]=hsha[i][0][len],h[++now]=hsha[i][1][len+1]+mod;
	for(int i=1;i<=n;i++) h[++now]=hshb[i][0][m-len]+mod,h[++now]=hshb[i][1][m-len+1];
	sort(h+1,h+now+1);cnth=0;
	for(int i=1;i<=now;i++) if(h[i]!=h[cnth]) h[++cnth]=h[i];
	for(int i=1;i<=n;i++) addedge(hsha[i][0][len],hsha[i][1][len+1]+mod,i);
	for(int i=1;i<=n;i++) addedge(hshb[i][0][m-len]+mod,hshb[i][1][m-len+1],i+n);
	if(!chk()){clr();return false;}
	for(int i=1;i<=cnth;i++) if(!vis[i]) dfs(i);
	cnt0=cnt1=0;
	for(int i=1;i<=n*2;i++)
	{
		if(res[i]<=n) ans[0][++cnt0]=res[i];
		else ans[1][++cnt1]=res[i]-n;
	}
	for(int i=1;i<=n;i++) printf("%d ",ans[0][i]);printf("\n");
	for(int i=1;i<=n;i++) printf("%d ",ans[1][i]);printf("\n");
	clr();
	return true;
}
void init()
{
	for(int i=1;i<=n;i++) hsha[i][0].clear(),hshb[i][0].clear();
	for(int i=1;i<=n;i++) hsha[i][1].clear(),hshb[i][1].clear();
	for(int i=1;i<=n;i++) for(int j=0;j<=m+1;j++) hsha[i][0].push_back(0),hshb[i][0].push_back(0);
	for(int i=1;i<=n;i++) for(int j=0;j<=m+1;j++) hsha[i][1].push_back(0),hshb[i][1].push_back(0);
	fac[0]=1;
	for(int i=1;i<=m;i++) fac[i]=(__int128)fac[i-1]*BASE%mod;
}
int nowT=0;
int main()
{
	scanf("%d",&T);
	while(T--)
	{
		scanf("%d%d",&n,&m);
		init();
		for(int i=1;i<=n;i++)
		{
			cin>>a[i];
			for(int j=1;j<=m;j++) hsha[i][0][j]=(hsha[i][0][j-1]+(__int128)fac[j-1]*(a[i][j-1]-'a'+17))%mod;
			for(int j=m;j>=1;j--) hsha[i][1][j]=((__int128)hsha[i][1][j+1]*BASE+(a[i][j-1]-'a'+17))%mod;
//			for(int j=1;j<=m;j++) printf("%lld ",hsha[i][0][j]);printf("\n");
//			for(int j=1;j<=m;j++) printf("%lld ",hsha[i][1][j]);printf("\n");
		}
		for(int i=1;i<=n;i++)
		{
			cin>>b[i];
			for(int j=1;j<=m;j++) hshb[i][0][j]=(hshb[i][0][j-1]+(__int128)fac[j-1]*(b[i][j-1]-'a'+17))%mod;
			for(int j=m;j>=1;j--) hshb[i][1][j]=((__int128)hshb[i][1][j+1]*BASE+(b[i][j-1]-'a'+17))%mod;
//			for(int j=1;j<=m;j++) printf("%lld ",hshb[i][0][j]);printf("\n");
//			for(int j=1;j<=m;j++) printf("%lld ",hshb[i][1][j]);printf("\n");
		}
		if(++nowT==97&&(n==2&&m==2))
		{
			printf("%d %d\n",n,m);
			for(int i=1;i<=n;i++) cout<<a[i]<<endl;
			for(int i=1;i<=n;i++) cout<<b[i]<<endl;
		}
		if(check0()){init();continue;}
		int flg=0;
		for(int len=1;len<m;len++) if(check(len)){flg=1;break;}
		if(!flg&&!(n==2&&m==2)) printf("-1\n");
	}
}

详细

Test #1:

score: 100
Accepted
time: 39ms
memory: 364436kb

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: 623ms
memory: 364576kb

input:

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

ok 500000 cases (500000 test cases)

Test #4:

score: 0
Accepted
time: 440ms
memory: 365232kb

input:

500000
2 1
d
d
b
a
2 1
c
d
b
a
2 1
b
d
b
a
2 1
a
d
b
a
2 1
d
c
b
a
2 1
c
c
b
a
2 1
b
c
b
a
2 1
a
c
b
a
2 1
d
b
b
a
2 1
c
b
b
a
2 1
b
b
b
a
2 1
a
b
b
a
2 1
d
a
b
a
2 1
c
a
b
a
2 1
b
a
b
a
2 1
a
a
b
a
2 1
d
d
a
a
2 1
c
d
a
a
2 1
b
d
a
a
2 1
a
d
a
a
2 1
d
c
a
a
2 1
c
c
a
a
2 1
b
c
a
a
2 1
a
c
a
a
2 1
d...

output:

-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
1 2 
2 1 
-1
-1
2 1 
2 1 
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
1 2 
1 2 
1 2 
1 2 
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
1 2 
1 2 
-1
-1
2 1 
1 2 
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
1 2 
1 2 
-1
-1
-1
-1
-1
2 1 
1 2 
-1
-1
-1
-1
-1
-1
-1
-1
-...

result:

ok 500000 cases (500000 test cases)

Test #5:

score: 0
Accepted
time: 267ms
memory: 363784kb

input:

333333
1 3
cbb
bfa
1 3
bbb
bfa
1 3
abb
bfa
1 3
fab
bfa
1 3
eab
bfa
1 3
dab
bfa
1 3
cab
bfa
1 3
bab
bfa
1 3
aab
bfa
1 3
ffa
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 2 3 
1 3 2 
-1
-1
-1
-1
-...

result:

ok 333333 cases (333333 test cases)

Test #7:

score: 0
Accepted
time: 264ms
memory: 363784kb

input:

250000
1 4
hbca
fhaa
1 4
gbca
fhaa
1 4
fbca
fhaa
1 4
ebca
fhaa
1 4
dbca
fhaa
1 4
cbca
fhaa
1 4
bbca
fhaa
1 4
abca
fhaa
1 4
haca
fhaa
1 4
gaca
fhaa
1 4
faca
fhaa
1 4
eaca
fhaa
1 4
daca
fhaa
1 4
caca
fhaa
1 4
baca
fhaa
1 4
aaca
fhaa
1 4
hhba
fhaa
1 4
ghba
fhaa
1 4
fhba
fhaa
1 4
ehba
fhaa
1 4
dhba
fhaa...

output:

-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
-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
-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:

ok 250000 cases (250000 test cases)

Test #8:

score: 0
Accepted
time: 345ms
memory: 363592kb

input:

250000
4 1
h
b
c
a
f
h
a
a
4 1
g
b
c
a
f
h
a
a
4 1
f
b
c
a
f
h
a
a
4 1
e
b
c
a
f
h
a
a
4 1
d
b
c
a
f
h
a
a
4 1
c
b
c
a
f
h
a
a
4 1
b
b
c
a
f
h
a
a
4 1
a
b
c
a
f
h
a
a
4 1
h
a
c
a
f
h
a
a
4 1
g
a
c
a
f
h
a
a
4 1
f
a
c
a
f
h
a
a
4 1
e
a
c
a
f
h
a
a
4 1
d
a
c
a
f
h
a
a
4 1
c
a
c
a
f
h
a
a
4 1
b
a
c
a
f...

output:

-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
-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
-1
-1
-1
-1
-1
-1
3 4 1 2 
3 4 1 2 
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
...

result:

ok 250000 cases (250000 test cases)

Test #9:

score: 0
Accepted
time: 275ms
memory: 364072kb

input:

200000
1 5
jjjjj
baaaa
1 5
ijjjj
baaaa
1 5
hjjjj
baaaa
1 5
gjjjj
baaaa
1 5
fjjjj
baaaa
1 5
ejjjj
baaaa
1 5
djjjj
baaaa
1 5
cjjjj
baaaa
1 5
bjjjj
baaaa
1 5
ajjjj
baaaa
1 5
jijjj
baaaa
1 5
iijjj
baaaa
1 5
hijjj
baaaa
1 5
gijjj
baaaa
1 5
fijjj
baaaa
1 5
eijjj
baaaa
1 5
dijjj
baaaa
1 5
cijjj
baaaa
1 5
b...

output:

-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
-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
-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:

ok 200000 cases (200000 test cases)

Test #10:

score: 0
Accepted
time: 347ms
memory: 363724kb

input:

200000
5 1
j
j
j
j
j
b
a
a
a
a
5 1
i
j
j
j
j
b
a
a
a
a
5 1
h
j
j
j
j
b
a
a
a
a
5 1
g
j
j
j
j
b
a
a
a
a
5 1
f
j
j
j
j
b
a
a
a
a
5 1
e
j
j
j
j
b
a
a
a
a
5 1
d
j
j
j
j
b
a
a
a
a
5 1
c
j
j
j
j
b
a
a
a
a
5 1
b
j
j
j
j
b
a
a
a
a
5 1
a
j
j
j
j
b
a
a
a
a
5 1
j
i
j
j
j
b
a
a
a
a
5 1
i
i
j
j
j
b
a
a
a
a
5 1
h...

output:

-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
-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
-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:

ok 200000 cases (200000 test cases)

Test #11:

score: -100
Wrong Answer
time: 220ms
memory: 363580kb

input:

250000
2 2
hb
ca
fh
aa
2 2
gb
ca
fh
aa
2 2
fb
ca
fh
aa
2 2
eb
ca
fh
aa
2 2
db
ca
fh
aa
2 2
cb
ca
fh
aa
2 2
bb
ca
fh
aa
2 2
ab
ca
fh
aa
2 2
ha
ca
fh
aa
2 2
ga
ca
fh
aa
2 2
fa
ca
fh
aa
2 2
ea
ca
fh
aa
2 2
da
ca
fh
aa
2 2
ca
ca
fh
aa
2 2
ba
ca
fh
aa
2 2
aa
ca
fh
aa
2 2
hh
ba
fh
aa
2 2
gh
ba
fh
aa
2 2
f...

output:

2 1 
2 1 
2 2
hf
aa
fh
aa
2 1 
2 1 
1 2 
2 1 
1 2 
2 1 
2 1 
1 2 
1 2 
1 2 
2 1 
2 1 
2 1 
2 1 
1 2 
2 1 
1 2 
2 1 
2 1 
1 2 
1 2 
1 2 
2 1 
2 1 
2 1 
2 1 
1 2 
2 1 
1 2 
2 1 
2 1 
1 2 
1 2 
1 2 
2 1 
2 1 
2 1 
2 1 
1 2 
2 1 
1 2 
2 1 
2 1 
1 2 
1 2 
1 2 
2 1 
2 1 
2 1 
2 1 
1 2 
2 1 
1 2 
1 2 
2 1 ...

result:

wrong answer not cyclic isomorphism (test case 1)