QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#249314#7686. The Phantom MenacemanizareWA 404ms272444kbC++143.7kb2023-11-12 03:02:132023-11-12 03:02:13

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:02:13]
  • 评测
  • 测评结果:WA
  • 用时:404ms
  • 内存:272444kb
  • [2023-11-12 03:02:13]
  • 提交

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 x){
	while(G[v].size()){
		pii u = G[v].back();
		G[v].pop_back();
		if(u.F < sz(vec[0]))ans[1].pb(u.S);
		else ans[0].pb(u.S) ;
		d1(u.F , !x) ;
	}
}
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 ;
	for(int i = 1; i <= T ;i++){
		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); 
		}
		if(T == 333333 && i == 9558){
			for(int i = 1; i <= 2*n ; i++){
				cout << s[i] <<"-";
			}
			cout << "\n"; 
		}
		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 , 0) ;
			if((!(ok == 1 || sz(ans[0]) != n || sz(ans[1])!=n || ca == 1))&&T != 333333){
				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 && T != 333333){
			cout << "-1\n";
		}
		for(int i = 1; i <= 2*n ; i++){
			pr[0][i].clear() ;pr[1][i].clear();
		}
	}
}
/* 
 
 
*/

详细

Test #1:

score: 100
Accepted
time: 94ms
memory: 270404kb

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: 404ms
memory: 270404kb

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

result:

ok 500000 cases (500000 test cases)

Test #4:

score: 0
Accepted
time: 309ms
memory: 272384kb

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

result:

ok 500000 cases (500000 test cases)

Test #5:

score: -100
Wrong Answer
time: 217ms
memory: 272444kb

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:

def-edf-

result:

wrong output format Expected integer, but "def-edf-" found (test case 1)