QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#258445 | #7686. The Phantom Menace | daydream | WA | 0ms | 3564kb | C++20 | 2.8kb | 2023-11-19 18:11:19 | 2023-11-19 18:11:20 |
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-19 18:11:19]
- 提交
answer
#include<bits/stdc++.h>
#define LL long long
#define pb push_back
#define ppb pop_back
#define eb emplace_back
#define pii pair<int,int>
#define fr first
#define sc second
#define mp make_pair
using namespace std;
const int infi=1e9,mod=998244353;
const int v1=29,v2=37,M1=19491001,M2=19260817;
void upd(int &x,const int y) {if((x+=y)>=mod) x-=mod;}
struct Hash
{
int x,y;
Hash() {x=y=0;}
Hash(int _x,int _y)
{
x=_x;
y=_y;
}
Hash operator +(int v)
{
Hash res=Hash((x+v)%M1,(y+v)%M2);
return res;
}
Hash operator *(Hash v)
{
Hash res=Hash(1ll*x*v.x%M1,1ll*y*v.y%M2);
return res;
}
Hash operator +(Hash v)
{
Hash res=Hash((x+v.x)%M1,(y+v.y)%M2);
return res;
}
Hash operator -(Hash v)
{
Hash res=Hash((x+M1-v.x)%M1,(y+M2-v.y)%M2);
return res;
}
bool operator <(const Hash &v)const
{
if(x!=v.x) return x<v.x;
else if(y!=v.y) return y<v.y;
return 0;
}
};
int n,m;
void solve()
{
cin>>n>>m;vector<vector<Hash>> a(n+1,vector<Hash>(m+1)),b(n+1,vector<Hash>(m+1));
vector<Hash> pw(m+1);pw[0]=Hash(1,1);
for(int i=1;i<=m;++i) pw[i]=pw[i-1]*Hash(v1,v2);
vector<string> sa,sb;
for(int i=1;i<=n;++i)
{
string s;cin>>s;sa.eb(s);s=" "+s;
for(int j=1;j<=m;++j) a[i][j]=a[i][j-1]*pw[1]+(s[j]-'a'+1);
}
for(int i=1;i<=n;++i)
{
string s;cin>>s;sb.eb(s);s=" "+s;
for(int j=1;j<=m;++j) b[i][j]=b[i][j-1]*pw[1]+(s[j]-'a'+1);
}
for(int p=0;p<m;++p)
{
// cout<<p<<":\n";
map<Hash,int> id1,id2;
int cnt=0;
vector<int> in(1);
vector<vector<pii>> G(1);
for(int i=1;i<=n;++i)
{
Hash x=a[i][p];
if(!id1[x]) id1[x]=++cnt,G.eb(),in.eb(0);
Hash y=a[i][m]-a[i][p]*pw[m-p];
if(!id2[y]) id2[y]=++cnt,G.eb(),in.eb(0);
G[id1[x]].eb(id2[y],i);
in[id2[y]]++;
// cout<<id1[x]<<' '<<id2[y]<<'\n';
}
int flg=1;
for(int i=1;i<=n;++i)
{
Hash x=b[i][m-p];
if(!id2[x])
{
flg=0;
break;
}
Hash y=b[i][m]-b[i][m-p]*pw[p];
if(!id1[y])
{
flg=0;
break;
}
G[id2[x]].eb(id1[y],i+n);
in[id1[y]]++;
// cout<<id2[x]<<' '<<id1[y]<<'\n';
}
if(!flg) continue;
for(int i=1;i<=cnt;++i) flg&=(int)G[i].size()==in[i];
if(!flg) continue;
vector<int> ansa,ansb;
vector<pii> stk;stk.eb(1,0);
while(!stk.empty())
{
auto [u,id]=stk.back();
if(G[u].empty())
{
if(id)
{
if(id<=n) ansa.pb(id);
else ansb.pb(id-n);
}
stk.ppb();
continue;
}
auto nxt=G[u].back();G[u].ppb();
stk.eb(nxt);
}
if((int)ansa.size()<n) continue;
if((int)ansb.size()<n) continue;
for(auto x:ansa) cout<<x<<' ';
cout<<'\n';
for(auto x:ansb) cout<<x<<' ';
cout<<'\n';
return ;
}
cout<<"-1\n";
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
int TT=1;
cin>>TT;
for(;TT;--TT) solve();
}
詳細信息
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3564kb
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)