QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#249229 | #7686. The Phantom Menace | manizare | WA | 383ms | 269144kb | C++14 | 3.4kb | 2023-11-12 02:11:10 | 2023-11-12 02:11:11 |
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 02:11:10]
- 提交
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;
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){
if(v!=0 && G[v].size() == 0)ok = 1;
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 ;
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 <= 1 ; 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]) ;
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 ;
}
G[x].pb({y , i-n});
}
d1(0 , 0) ;
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" ;
}
for(int i = 1; i <= sz(vec[0]) + sz(vec[1]) ; i++)G[i].clear() ;
}
if(ca==0){
cout << "-1\n";
}
ans[0].clear();ans[1].clear();
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: 100
Accepted
time: 101ms
memory: 269104kb
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: 383ms
memory: 269144kb
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 ...
result:
ok 1000000 cases (1000000 test cases)
Test #3:
score: -100
Wrong Answer
time: 219ms
memory: 269044kb
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 2 cd aa 1 2 bd aa 1 2 ad aa 1 2 dc aa 1 2 cc aa 1 2 bc aa 1 2 ac aa 1 2 db aa 1 2 cb aa 1 2 bb aa 1 2 ab aa 1 2 da aa 1 2...
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:
wrong answer Jury has the answer but participant has not (test case 15)