QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#258382 | #7686. The Phantom Menace | daydream# | WA | 0ms | 3608kb | C++20 | 2.4kb | 2023-11-19 17:39:41 | 2023-11-19 17:39:42 |
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 17:39:41]
- 提交
answer
#include<bits/stdc++.h>
#define LL long long
#define pb push_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);
for(int i=1;i<=n;++i)
{
string s;cin>>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;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)
{
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]]++;
}
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]]++;
}
if(!flg) continue;
for(int i=1;i<=cnt;++i) flg&=(int)G[i].size()==in[i];
if(!flg) continue;
int u=1;vector<int> ansa,ansb;
while(!G[u].empty())
{
auto [v,id]=G[u].back();G[u].pop_back();
if(id<=n) ansa.pb(id);
else ansb.pb(id-n);
u=v;
}
for(auto x:ansa) cout<<x<<' ';
cout<<'\n';
for(auto x:ansb) cout<<x<<' ';
cout<<'\n';
}
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();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3608kb
input:
2 3 3 abc ghi def bcd efg hia 1 3 abc def
output:
1 3 2 1 2 3 -1 -1
result:
wrong output format Extra information in the output file (test case 2)