QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#617908 | #7686. The Phantom Menace | wyhao | WA | 51ms | 414988kb | C++14 | 4.5kb | 2024-10-06 17:38:43 | 2024-10-06 17:38:44 |
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-10-06 17:38:43]
- 提交
answer
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
const int N=2000005,P1=1000000007,P2=1000000009;
int n,m;
struct Hash{
int v1,v2;
Hash(int v=0):v1(v),v2(v){}
Hash(int v1,int v2):v1(v1),v2(v2){}
Hash& operator+=(const Hash & o){
(v1+=o.v1)%=P1;
(v2+=o.v2)%=P2;
return *this;
}
Hash& operator-=(const Hash & o){
(v1+=P1-o.v1)%=P1;
(v2+=P2-o.v2)%=P2;
return *this;
}
Hash& operator*=(const Hash &o){
v1=1ll*v1*o.v1%P1;
v2=1ll*v2*o.v2%P2;
return *this;
}
friend Hash operator+(Hash a,Hash b){
return a+=b;
}
friend Hash operator-(Hash a,Hash b){
return a-=b;
}
friend Hash operator*(Hash a,Hash b){
return a*=b;
}
friend bool operator==(Hash a,Hash b){
return a.v1==b.v1 and a.v2==b.v2;
}
friend bool operator!=(Hash a,Hash b){
return a.v1!=b.v1 or a.v2!=b.v2;
}
friend bool operator<(Hash a,Hash b){
return a.v1<b.v1 or (a.v1==b.v1 and a.v2<b.v2);
}
ull Hasher(){
ull res = v1;
res <<=16;res<<=16;
res += v2;
return res;
}
}base(131,137);
string a[N],b[N];
vector<Hash> pa[N],pb[N],sa[N],sb[N];
vector<pair<int,int> > vec[N];
unordered_map<ull,int>Ma,Mb;
int deg[N],vis[N];
int stk[N],tot;
void dfs(int x){
for(int i=vis[x];i<vec[x].size();i++){
vis[x]++;
dfs(vec[x][i].first);
stk[++tot] = vec[x][i].second;
if(vis[x]==vec[x].size()) break;
}
}
pair<Hash,int>ap[N],bp[N];
void solve(){
cin>>n>>m;
for(int i=1;i<=n;i++){
cin>>a[i];
pa[i].clear();
sa[i].clear();
}
for(int i=1;i<=n;i++){
cin>>b[i];
pb[i].clear();
sb[i].clear();
}
for(int i=1;i<=n;i++){
Hash s(0);
for(int j=0;j<m;j++){
s=s*base+a[i][j];
pa[i].push_back(s);
sa[i].push_back(0);
}
sa[i][0]=pa[i][m-1];
s=1;
for(int j=m-1;j>0;j--){
s=s*base;
sa[i][j]=pa[i][m-1]-s*pa[i][j-1];
}
}
for(int i=1;i<=n;i++){
Hash s(0);
for(int j=0;j<m;j++){
s=s*base+b[i][j];
pb[i].push_back(s);
sb[i].push_back(0);
}
sb[i][0]=pb[i][m-1];
s=1;
for(int j=m-1;j>0;j--){
s=s*base;
sb[i][j]=pb[i][m-1]-s*pb[i][j-1];
}
}
for(int j=1;j<m;j++){
Ma.clear();
Mb.clear();
int num=0;
for(int i=1;i<=n;i++){
if(!Ma[pa[i][j-1].Hasher()]){
Ma[pa[i][j-1].Hasher()]=++num;
}
if(!Mb[sa[i][j].Hasher()]){
Mb[sa[i][j].Hasher()]=++num;
}
}
bool f=true;
for(int i=1;i<=num;i++) vec[i].clear(),deg[i]=0;
for(int i=1;i<=n;i++){
int x = Ma[sb[i][m-j].Hasher()],y=Mb[pb[i][m-j-1].Hasher()];
if(!x){
f=false;
break;
}
if(!y){
f=false;
break;
}
vec[y].push_back(make_pair(x,i));
deg[y]++;deg[x]--;
}
if(!f) continue;
for(int i=1;i<=n;i++){
int x = Ma[pa[i][j-1].Hasher()],y=Mb[sa[i][j].Hasher()];
vec[x].push_back(make_pair(y,i));
deg[x]++;deg[y]--;
}
for(int i=1;i<=num;i++){
if(deg[i]) f=false;
vis[i]=0;
}
if(!f) continue;
tot=0;
dfs(1);
if(tot!=2*num) continue;
for(int i=tot;i>0;i-=2){
cout<<stk[i]<<" ";
}
puts("");
for(int i=tot-1;i>0;i-=2){
cout<<stk[i]<<" ";
}
puts("");
return ;
}
for(int i=1;i<=n;i++){
ap[i]=make_pair(pa[i][m-1],i);
bp[i]=make_pair(pb[i][m-1],i);
}
sort(ap+1,ap+n+1);
sort(bp+1,bp+n+1);
bool f=true;
for(int i=1;i<=n;i++){
if(ap[i].first != bp[i].first) f=false;
}
if(f){
for(int i=1;i<=n;i++) cout<<ap[i].second<<" ";
puts("");
for(int i=1;i<=n;i++) cout<<bp[i].second<<" ";
puts("");
return;
}
puts("-1");
return ;
}
int main(){
int tests;
cin>>tests;
while(tests--){
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 51ms
memory: 414988kb
input:
2 3 3 abc ghi def bcd efg hia 1 3 abc def
output:
-1 -1
result:
wrong answer Jury has the answer but participant has not (test case 1)