QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#527280 | #7686. The Phantom Menace | hansiyuan | WA | 661ms | 274220kb | C++14 | 2.4kb | 2024-08-22 13:22:57 | 2024-08-22 13:22:58 |
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-08-22 13:22:57]
- 提交
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long lol;
const int N=4e6+5;
const lol p1=131,p2=1e9+9,nip=526717562;
int T,n,m,tot,cnt[3],ok;
int p[N];
int res[N][3];
lol pw[N];
string A[N],B[N];
lol Alh[N],Blh[N],Arh[N],Brh[N];
map<string,vector<int> > mp;
map<int,int> mpl,mpr;
int h[N],to[N],ne[N],we[N],idx;
void add(int u,int v,int w){
to[++idx]=v; we[idx]=w; ne[idx]=h[u]; h[u]=idx;
}
void add_front(lol &hsh,int x){
hsh = (hsh*p1+x)%p2;
}
void add_back(lol &hsh,int x,int p){
hsh = (hsh+pw[p]*x%p2)%p2;
}
void del_front(lol &hsh,int x){
hsh = (hsh-x+p2)%p2*nip%p2;
}
void del_back(lol &hsh,int x,int p){
hsh = (hsh-pw[p]*x%p2+p2)%p2;
}
void init(){
ok=0;
mp.clear();
for(int i=1;i<=n;i++)
Alh[i] = Blh[i] = Arh[i] = Brh[i] = 0;
}
void dfs(int u,int op){
for(int i=h[u];i;i=ne[i]){
h[u] = ne[i];
int v = to[i];
res[++cnt[op]][op]=we[i];
dfs(v,3-op);
}
}
int main(){
//int a = clock();
pw[0] = 1;
for(int i=1;i<=1e6;i++) pw[i]=(pw[i-1]*p1)%p2;
scanf("%d",&T);
while(T--){
init();
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++) cin>>A[i];
for(int i=1;i<=n;i++) cin>>B[i];
bool flag=1;
for(int i=1;i<=n;i++) mp[A[i]].push_back(i);
for(int i=1;i<=n;i++){
if(!mp[B[i]].size()){flag=0; break;}
p[mp[B[i]].back()] = i;
mp[B[i]].pop_back();
}
if(flag){
for(int i=1;i<=n;i++) printf("%d ",i); puts("");
for(int i=1;i<=n;i++) printf("%d ",p[i]); puts("");
continue;
}
for(int i=1;i<=n;i++)
for(int j=0;j<m;j++){
add_back(Arh[i],A[i][j]-'a'+1,j);
add_back(Brh[i],B[i][j]-'a'+1,j);
}
for(int p=0;p<m-1;p++){
for(int i=1;i<=tot;i++) h[i]=0; idx=0;
mpl.clear(); mpr.clear(); tot=0;
cnt[1]=cnt[2]=0;
for(int i=1;i<=n;i++){
int ca=A[i][p]-'a'+1,cb=B[i][m-p-1]-'a'+1;
del_front(Arh[i],ca);
del_back(Brh[i],cb,m-p-1);
add_back(Alh[i],ca,p);
add_front(Blh[i],cb);
}
for(int i=1;i<=n;i++){
if(!mpl[Alh[i]]) mpl[Alh[i]]=++tot;
if(!mpr[Arh[i]]) mpr[Arh[i]]=++tot;
add(mpl[Alh[i]],mpr[Arh[i]],i);
}
for(int i=1;i<=n;i++){
if(!mpl[Blh[i]]) mpl[Blh[i]]=++tot;
if(!mpr[Brh[i]]) mpr[Brh[i]]=++tot;
add(mpr[Brh[i]],mpl[Blh[i]],i);
}
dfs(1,1);
if(cnt[1]==n && cnt[2]==n){
ok=1;
for(int i=1;i<=n;i++) printf("%d ",res[i][1]); puts("");
for(int i=1;i<=n;i++) printf("%d ",res[i][2]); puts("");
break;
}
}
if(!ok) puts("-1");
}
//cerr<<clock()-a<<"ms"<<endl;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 28ms
memory: 272080kb
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: 661ms
memory: 274116kb
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: 415ms
memory: 274220kb
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 not cyclic isomorphism (test case 9)