QOJ.ac

QOJ

ID提交记录ID题目HackerOwner结果提交时间测评时间
#940#249330#7686. The Phantom MenaceN_z_manizareSuccess!2024-10-08 10:04:532024-10-08 10:04:53

详细

Extra Test:

Wrong Answer
time: 99ms
memory: 270340kb

input:

35
1 70
larkaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaacodhmaapa
apaamhdocaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaakral
1 70
asmmuahagajaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabklabaoawaaaak
kaaaawaoabalkbaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaajagahaummsa
1 7...

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

result:

wrong answer not cyclic isomorphism (test case 11)

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#249330#7686. The Phantom MenacemanizareWA 826ms615280kbC++143.7kb2023-11-12 03:22:142024-10-13 19:43:24

answer

#include <bits/stdc++.h>
#define pb push_back
#define F first
#define S second 
#define all(a) a.begin(),a.end()
#define pii pair <int,int>
#define PII pair<pii , pii>
#define int long long
#define sz(v) (int)v.size()
using namespace std ;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int maxn = 2e6 + 10 , inf  = 1e18 , lg = 21 ;  
int mod[2] , p[2] , z[2][maxn] , iz[2][maxn] , n , m , ok = 0 , ca = 0 , de[maxn];
vector <int> ans[2];vector <pii> vec[2] , G[maxn]; 
vector <int> pr[2][maxn] ;
string s[maxn] ;
int po(int a , int b , int x){
	if(b==0)return 1 ;
	int v = po(a, b/2 , x); 	
	v= v* v % mod[x] ;
	if(b&1)v = v*a % mod[x] ;
	return v; 
}

int bz(int l , int r , int id , int x){
	return (pr[x][id][r] - pr[x][id][l-1] + mod[x]) * iz[x][l-1] % mod[x] ;
}

void bui(int id){
	for(int j =0 ; j <= 1 ; j++){
		pr[j][id].pb(0); 
		for(int i = 1 ; i <= m ; i++){
			pr[j][id].pb((pr[j][id].back() + z[j][i] * (s[id][i-1] - 'a' + 1) % mod[j])%mod[j]) ;
		}
	}
}

void d1(int v , int e){
	while(G[v].size()){
		pii u = G[v].back();
		G[v].pop_back();
		if(u.F < sz(vec[0]))u.S *= -1 ;
		d1(u.F , u.S);
	}
	if(e == inf)return  ;
	if(e < 0)ans[1].pb(-e);
	else ans[0].pb(e) ;
}
int ch(pii a , int t){
	int x = lower_bound(all(vec[t]) , a) - vec[t].begin() ;
	if(x==sz(vec[t]) || vec[t][x] != a)return -1 ;
	return x; 
}

signed main(){ 
  	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0) ;
	vector <int> pri ;
	for(int i =1e9  ; i <= 1e9 + 200 ; i++){
		bool ok = 1; 
		for(int j = 2 ; j*j <= i ; j++)if(i%j==0)ok = 0;
		if(ok == 1)pri.pb(i);
	}
	mod[0] = pri[rng()%(int)pri.size()];
	mod[1] = pri[rng()%(int)pri.size()];
	p[0] = 23 , p[1] = 53 ; 
	for(int j = 0 ; j <= 1 ; j++){
		z[j][0] = 1;
		for(int i = 1 ;i  < maxn ; i++){
			z[j][i] = z[j][i-1] * p[j] % mod[j] ;
		}
		iz[j][maxn-1] = po(z[j][maxn-1] , mod[j]-2 , j) ;
		for(int i = maxn-2 ; i >= 0; i--){
			iz[j][i] = iz[j][i+1] * p[j] % mod[j] ;
		}
	}
	int T ;
	cin >> T ;
	while(T--){
		cin >> n >> m ;
		ca = 0 ;
		for(int i = 1; i <= n ; i++){
			cin >> s[i] ;
		}
		for(int i = n+1 ; i <= 2*n ; i++){
			cin >> s[i] ;
		}
		for(int i = 1; i <= 2*n ; i++){
			bui(i); 
		}
		for(int d = 1; d <= m  ; d++){
			ok = 0 ;
			vec[0].clear();vec[1].clear();
			for(int i = 1; i <= n ; i++){
				vec[0].pb({bz(1 , d , i , 0) , bz(1, d , i , 1)}) ;
				vec[1].pb({bz(d+1 ,m , i , 0) , bz(d+1 , m , i , 1)}) ;
			}
			sort(all(vec[0]));vec[0].resize(unique(all(vec[0])) - vec[0].begin()) ;
			sort(all(vec[1]));vec[1].resize(unique(all(vec[1])) - vec[1].begin()) ;
			for(int i = 1; i <= n ;i++){
				int x = ch({bz(1,d,i,0),bz(1,d,i,1)} , 0) , y = ch({bz(d+1,m,i,0),bz(d+1,m,i,1)} , 1)+sz(vec[0]) ;
				de[y]++;
				G[x].pb({y , i});
			}
			for(int i = n+1; i <= 2*n; i++){
				int x = ch({bz(1,m-d,i,0),bz(1,m-d,i,1)} , 1)+sz(vec[0]) , y = ch({bz(m-d+1,m,i,0),bz(m-d+1,m,i,1)} , 0) ;
				if(x==-1 || y == -1){
					ok = 1 ;
					continue ;
				}
				de[y]++;
				G[x].pb({y , i-n});
			}
			for(int i =0 ; i < sz(vec[0])+sz(vec[1]) ; i++){
				if(de[i] != sz(G[i]))ok = 1; 
			}
			d1(0 , inf) ;
			if(!(ok == 1 || sz(ans[0]) != n || sz(ans[1])!=n || ca == 1)){
				ca = 1 ; 
				reverse(all(ans[0]));reverse(all(ans[1])); 
				for(int x : ans[0])cout << x << " ";
				cout << "\n";
				for(int y : ans[1])cout << y << " ";
				cout << "\n" ; 
			}
		ans[0].clear();ans[1].clear();
			for(int i = 0; i <= sz(vec[0]) + sz(vec[1]) ; i++){
				G[i].clear() ;
				de[i] =0 ;
			}
		}
		if(ca==0){
			cout << "-1\n";
		}
		for(int i = 1; i <= 2*n ; i++){
			pr[0][i].clear() ;pr[1][i].clear();
		}
	}
}
/* 
 
 
*/