QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#358988#7686. The Phantom Menacewsc2008WA 79ms380404kbC++142.8kb2024-03-20 10:19:342024-03-20 10:19:35

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-03-20 10:19:35]
  • 评测
  • 测评结果:WA
  • 用时:79ms
  • 内存:380404kb
  • [2024-03-20 10:19:34]
  • 提交

answer

#pragma GCC optimize("2,3,Ofast,inline,unroll-loops")
#include<bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define pii pair<ll,ll>
#define rep(i,a,b) for(ll i=(a);i<=(b);++i)
#define per(i,a,b) for(ll i=(a);i>=(b);--i)
using namespace std;
bool Mbe;
inline ll read(){
	ll x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-f;ch=getchar();}
	while(ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();
	return x*f;
}
inline void write(ll x){
	if(x<0)putchar('-'),x=-x;
	if(x>9)write(x/10);
	putchar(x%10+'0');
}
const ll N=4e6+9,B=4398523,Mod=248572467;
int T,n,m,hd[N],tote,tot,in[N],out[N],cur[N];
ll pw[N];
vector<ll>hsha[N],hshb[N];
vector<char>a[N],b[N];
map<ll,ll>pt;
ll Ha(ll id,ll l,ll r){
	if(l>r)return 0;
	return (hsha[id][r]-hsha[id][l-1]*pw[r-l+1]%Mod+Mod)%Mod;
}
ll Hb(ll id,ll l,ll r){
	if(l>r)return 0;
	return (hshb[id][r]-hshb[id][l-1]*pw[r-l+1]%Mod+Mod)%Mod;
}
struct Edg{
	int to,nxt,id,tp;
}es[N];
vector<pii>res;
void adde(ll x,ll y,ll z,ll w){
	out[x]++,in[y]++;
	es[++tote]=(Edg){y,hd[x],z,w};
	hd[x]=tote;
}
void dfs(ll x){
	for(int&i=cur[x];i;){
		ll y=es[i].to;
		res.push_back(make_pair(es[i].id,es[i].tp));
		i=es[i].nxt;
		dfs(y);
	}
}
char s[N];
void solve(ll tst){
	n=read(),m=read();
	pw[0]=1;
	rep(i,1,m)pw[i]=pw[i-1]*B%Mod;
	rep(i,1,n)hsha[i].clear(),hsha[i].resize(m+2);
	rep(i,1,n)hshb[i].clear(),hshb[i].resize(m+2);
	rep(i,1,n){
		scanf("%s",s+1);
		a[i].clear(),a[i].resize(m+2);
		rep(j,1,m){
			a[i][j]=s[j];
			hsha[i][j]=(hsha[i][j-1]*B+a[i][j])%Mod;
		}
	}
	rep(i,1,n){
		scanf("%s",s+1);
		b[i].clear(),b[i].resize(m+2);
		rep(j,1,m){
			b[i][j]=s[j];
			hshb[i][j]=(hshb[i][j-1]*B+b[i][j])%Mod;
		}
	}
	vector<ll>resa,resb;
	rep(i,0,m-1){
		tot=0,tote=0;
		pt.clear();
		rep(j,0,n*4)hd[j]=0,in[j]=out[j]=0;
		rep(j,1,n){
			ll pre=Ha(j,1,i),suf=(Ha(j,i+1,m)*2304872%Mod+3248274)%Mod;
			if(pt.find(pre)==pt.end())pt[pre]=++tot;
			if(pt.find(suf)==pt.end())pt[suf]=++tot;
			adde(pt[pre],pt[suf],j,0);
		}
		rep(j,1,n){
			ll pre=(Hb(j,1,m-i)*2304872%Mod+3248274)%Mod,suf=Hb(j,m-i+1,m);
			if(pt.find(pre)==pt.end())pt[pre]=++tot;
			if(pt.find(suf)==pt.end())pt[suf]=++tot;
			adde(pt[pre],pt[suf],j,1);
		}
		ll fl=1;
		rep(j,1,tot){
			if(abs(in[j]-out[j])>=1){
				fl=0;
				break;
			}
		}
		if(!fl)continue;
		rep(j,1,tot)cur[j]=hd[j];
		res.clear();
		dfs(1);
		if((int)res.size()!=2*n)continue;
		reverse(res.begin(),res.end());
		for(pii p:res){
			if(!p.second)resa.push_back(p.first);
			else resb.push_back(p.first);
		}
		for(ll x:resa)write(x),putchar(' ');
		putchar('\n');
		for(ll x:resb)write(x),putchar(' ');
		putchar('\n');
		return ;
	}
	puts("-1");
}
bool Med;
int main(){
	cerr<<fabs(&Med-&Mbe)/1048576.0<<"MB\n";
	T=read();
	rep(i,1,T)solve(i);
	return 0;
}

详细

Test #1:

score: 0
Wrong Answer
time: 79ms
memory: 380404kb

input:

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

output:

2 3 1 
3 2 1 
-1

result:

wrong answer not cyclic isomorphism (test case 1)