QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#249327 | #7686. The Phantom Menace | manizare | WA | 103ms | 270396kb | C++14 | 3.6kb | 2023-11-12 03:19:51 | 2023-11-12 03:19:51 |
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-11-12 03:19:51]
- 提交
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 ;
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();
}
}
}
/*
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 103ms
memory: 270396kb
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)