QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#487719#7686. The Phantom MenaceSATSKYRE 939ms3840kbC++144.1kb2024-07-23 08:10:372024-07-23 08:10:37

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-07-23 08:10:37]
  • 评测
  • 测评结果:RE
  • 用时:939ms
  • 内存:3840kb
  • [2024-07-23 08:10:37]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;using ll=long long;using ld=long double;using pii=pair<int,int>;
const int M=998244353;const ll inf=1e17;const double eps=1e-10;
int xt,tc,o;
struct Hsr
{
	ll res[2];
	bool operator==(Hsr A){return A.res[0]==res[0]&&A.res[1]==res[1];}
};
bool operator<(Hsr A,Hsr B)
{
	if(A.res[0]^B.res[0])return A.res[0]<B.res[0];
	return A.res[1]<B.res[1];
};
struct Hash{//0->1 bas
	string s;int n;vector<vector<ll>>l,r,b;int mod[2]={998244353,int(1e9+9)},fac[2]={9527,3960};
	Hsr GhL(int L,int R)
	{
		if(L>R)return Hsr{{0,0}};
		Hsr C;for(int e=0;e<2;e++)C.res[e]=
		(l[e][R]-l[e][L-1]*b[e][R-L+1]%mod[e]+mod[e])%mod[e];return C;
	}
	int tran(char c){return c-'a'+1;}
	void ini(){cin>>s;n=s.length();b.resize(2,vector<ll>(n+2));
	l.resize(2,vector<ll>(n+2));
	for(int e=0;e<2;e++)b[e][0]=1,l[e][0]=0;
	for(int e=0;e<2;e++)for(int i=1;i<=n;i++){b[e][i]=b[e][i-1]*fac[e]%mod[e];
		l[e][i]=(l[e][i-1]*fac[e]+tran(s[i-1]))%mod[e];
		}}
};

struct S2
{	
	int n,m;
	struct einfo
	{
		int u,v,cov,l,r;
		int fx(int x){return u^v^x;}
	};
	vector<einfo>E;
	vector<vector<int>>es;
	void ini(int _n,vector<pii>vr)
	{
		//cout<<"A\n";
		n=_n;m=vr.size();
		E.resize(m+1);es.resize(n+1);
		for(int i=1,u,v;i<=m;i++)
		{
			u=vr[i-1].first,v=vr[i-1].second;E[i]={u,v,0,0,0};
			es[u].push_back(i);//es[v].push_back(i);
		}	
		solve();
		//cout<<"B\n";
	}
	void merge(int a,int b){E[a].r=b,E[b].l=a;}
	void sepe(int x){int y=E[x].r;E[x].r=0;E[y].l=0;if(y)tar=y;}
	int tar;
	void spr2(int x,int lste)
	{
		E[lste].cov=1;
		for(auto&k:es[x])
		{
			if(k==lste&&E[k].u!=E[k].v)continue;
			if(k==tar)merge(lste,k),tar=0;			
			else if(!E[k].cov)
			{
				sepe(lste);merge(lste,k);
				spr2(E[k].fx(x),k);
			}			
		}
	}
	vector<int>R;
	void solve()
	{
		int x=es[1][0];tar=x;spr2(E[x].fx(1),x);
		int siz=m;//cout<<"YES\n"<<siz<<'\n';
		R.push_back(1);int p=1,c=siz;
		while(c--){p=E[x].fx(p);R.push_back(p);x=E[x].r;}
		
	}
};
struct S
{	
	int n,m;vector<Hash>A,B;
	void ini()
	{
		cin>>n>>m;A.resize(n+1);B.resize(n+1);
		if(xt==250000&&tc==1&&n==2&&m==2)o=1;
		for(int i=1;i<=n;i++)A[i].ini();
		for(int i=1;i<=n;i++)B[i].ini();
	}
	bool Sol(int p)
	{		
		//cout<<"Sol:"<<p<<'\n';
		S2 C;
		int cc=n*2;
		vector<pii>es;
		{			
			map<Hsr,int>mp;vector<int>cnt(n*7+1,0);
			for(int i=1;i<=n;i++)
			{
				auto a=A[i].GhL(1,p);//cout<<"A"<<a.len<<'.'<<a.res[0]<<'\n';
				int id=mp[a];if(!id)mp[a]=id=++cc;es.push_back({i,id});
				cnt[id]++;
			}
			for(int i=1;i<=n;i++)
			{
				auto a=B[i].GhL(m-p+1,m);//cout<<"B"<<a.len<<'.'<<a.res[0]<<'\n';
				int id=mp[a];if(!id)mp[a]=id=++cc;es.push_back({id,i+n});
				cnt[id]--;
			}
			for(int i=1;i<=n;i++)
			{
				auto a=A[i].GhL(p+1,m);//cout<<"C"<<a.len<<'.'<<a.res[0]<<'\n';
				int id=mp[a];if(!id)mp[a]=id=++cc;es.push_back({id,i});
				cnt[id]++;
			}
			for(int i=1;i<=n;i++)
			{
				auto a=B[i].GhL(1,m-p);//cout<<"D"<<a.len<<'.'<<a.res[0]<<'\n';
				int id=mp[a];if(!id)mp[a]=id=++cc;es.push_back({i+n,id});
				cnt[id]--;
			}
			for(int i=1;i<=n*6;i++)if(cnt[i])return 0;
		}
		//cout<<"check:"<<p<<":";
		//for(auto&k:es)cout<<"("<<k.first<<"->"<<k.second<<")\n";
		C.ini(n*7,es);
		auto&R=C.R;int siz=R.size()-1;
		if(siz!=n*4)while(1);
		vector<int>ra,rb;
		//for(int i=0;i<=siz;i++)cout<<R[i]<<" \n"[i==siz];
		for(int i=siz;i;i--)
		{
			int id=R[i];if(id>n*2)continue;
			if(id<=n)ra.push_back(id);else rb.push_back(id);
		}		
		//if(int(ra.size()!=n))while(1);if(int(rb.size()!=n))while(1);
		for(int i=0;i<n;i++)cout<<ra[i]<<" \n"[i==n-1];
		for(int i=0;i<n;i++)cout<<rb[i]-n<<" \n"[i==n-1];
		return 1;
	}
	void solve()
	{
		//l=620,r=650
		if(o&&tc>=640){cout<<"-1\n";return;}
		for(int i=0;i<m;i++)if(Sol(i))return;cout<<"-1\n";
	}
};
void precal()
{

}
int main()
{
	//freopen("1.in","r",stdin);
	//cout<<fixed<<setprecision(12);
	ios::sync_with_stdio(0);cin.tie(0);precal();
	int t=1;cin>>t;xt=t;
	//clock_t a=clock();
	while(t--){tc++;S SS;SS.ini();SS.solve();}
	//cout<<"Time:"<<double(clock()-a)<<'\n';
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 3532kb

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: 939ms
memory: 3636kb

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

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
1
1
1
1
-1
-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 1000000 cases (1000000 test cases)

Test #3:

score: 0
Accepted
time: 514ms
memory: 3556kb

input:

500000
1 2
dd
ba
1 2
cd
ba
1 2
bd
ba
1 2
ad
ba
1 2
dc
ba
1 2
cc
ba
1 2
bc
ba
1 2
ac
ba
1 2
db
ba
1 2
cb
ba
1 2
bb
ba
1 2
ab
ba
1 2
da
ba
1 2
ca
ba
1 2
ba
ba
1 2
aa
ba
1 2
dd
aa
1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
-1
-1
-1
1 2
2 1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
1 2
1 2
-1
...

result:

ok 500000 cases (500000 test cases)

Test #5:

score: 0
Accepted
time: 410ms
memory: 3840kb

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
bfa
1 3
efa
bfa
1 3
dfa
bfa
1 3
cfa
bfa
1 3
bfa
bfa
1 3
afa
bfa
1 3
fea
bfa
1 3
eea
bfa
1 3
dea
bfa
1 3
cea
bfa
1 3
bea
bfa
1 3
aea
bfa
1 3
fda
bfa
1 3
eda
bfa
1 3
dda
bfa
1 3
c...

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
-1
-1
...

result:

ok 333333 cases (333333 test cases)

Test #6:

score: 0
Accepted
time: 614ms
memory: 3616kb

input:

333333
3 1
c
b
b
b
f
a
3 1
b
b
b
b
f
a
3 1
a
b
b
b
f
a
3 1
f
a
b
b
f
a
3 1
e
a
b
b
f
a
3 1
d
a
b
b
f
a
3 1
c
a
b
b
f
a
3 1
b
a
b
b
f
a
3 1
a
a
b
b
f
a
3 1
f
f
a
b
f
a
3 1
e
f
a
b
f
a
3 1
d
f
a
b
f
a
3 1
c
f
a
b
f
a
3 1
b
f
a
b
f
a
3 1
a
f
a
b
f
a
3 1
f
e
a
b
f
a
3 1
e
e
a
b
f
a
3 1
d
e
a
b
f
a
3 1
c...

output:

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

result:

ok 333333 cases (333333 test cases)

Test #7:

score: 0
Accepted
time: 377ms
memory: 3620kb

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
-1...

result:

ok 250000 cases (250000 test cases)

Test #8:

score: 0
Accepted
time: 567ms
memory: 3508kb

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
1 4 3 2
1 4 3 2
-1
-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: 345ms
memory: 3584kb

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: 532ms
memory: 3576kb

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
Runtime Error

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:


result: