QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#257106 | #7686. The Phantom Menace | ucup-team1321 | TL | 11ms | 122648kb | C++20 | 2.8kb | 2023-11-19 00:12:41 | 2023-11-19 00:12:41 |
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 00:12:41]
- 提交
answer
#include <bits/stdc++.h>
using namespace std;
int n,m,t;
string a[1000010],b[1000010];
vector<unsigned long long> ha[1000010],hb[1000010];
unsigned long long p[1000010];
int Link[4000010],in[4000010],ou[4000010];
struct dsa
{
int v,nex,w;
}e[2000010];
vector<int> ans;
unordered_map <unsigned long long,int> mp;
bool vis[2000010];
void Init()
{
for (int i=1;i<=n;i++) {
ha[i].resize(m);
ha[i][0]=a[i][0]-'a'+1;
for (int j=1;j<m;j++) ha[i][j]=ha[i][j-1]*131+a[i][j]-'a'+1;
hb[i].resize(m);
hb[i][0]=b[i][0]-'a'+1;
for (int j=1;j<m;j++) hb[i][j]=hb[i][j-1]*131+b[i][j]-'a'+1;
}
p[0]=1;
for (int i=1;i<=m;i++) p[i]=p[i-1]*131;
return ;
}
unsigned long long Hash_A(int i,int l,int r)
{
if (l>r) return 0;
unsigned long long val=ha[i][r];
if (l==0) return val;
val-=ha[i][l-1]*p[r-l+1];
return val;
}
unsigned long long Hash_B(int i,int l,int r)
{
if (l>r) return 0;
unsigned long long val=hb[i][r];
if (l==0) return val;
val-=hb[i][l-1]*p[r-l+1];
return val;
}
void Insert(int x,int y,int z)
{
ou[x]++;in[y]++;
e[++t].nex=Link[x];e[t].v=y;e[t].w=z;Link[x]=t;
vis[t]=false;
return;
}
void dfs(int now)
{
for (int i=Link[now];i;i=e[i].nex) {
if (vis[e[i].w]) continue;
vis[e[i].w]=true;
Link[now]=e[i].nex;
dfs(e[i].v);
ans.push_back(e[i].w);
}
return ;
}
void Solve()
{
cin>>n>>m;
for (int i=1;i<=n;i++) cin>>a[i];
for (int i=1;i<=n;i++) cin>>b[i];
Init();
int tot=0;
for (int len=0;len<m;len++) {
mp.clear();
t=0;
for (int i=1;i<=tot;i++) Link[i]=0;
tot=0;
for (int i=1;i<=n;i++) {
unsigned long long pre=Hash_A(i,0,len-1),suf=Hash_A(i,len,m-1);
if (mp.find(pre)==mp.end()) mp[pre]=++tot,ou[tot]=in[tot]=0;
if (mp.find(suf)==mp.end()) mp[suf]=++tot,ou[tot]=in[tot]=0;
Insert(mp[pre],mp[suf],i);
// cout<<mp[pre]<<' '<<mp[suf]<<endl;
}
for (int i=1;i<=n;i++) {
unsigned long long pre=Hash_B(i,0,m-1-len),suf=Hash_B(i,m-len,m-1);
if (mp.find(pre)==mp.end()) mp[pre]=++tot,ou[tot]=0,in[tot]=0;
if (mp.find(suf)==mp.end()) mp[suf]=++tot,ou[tot]=0,in[tot]=0;
Insert(mp[pre],mp[suf],i+n);
// cout<<mp[pre]<<' '<<mp[suf]<<endl;
}
bool fla=true;
for (int i=1;i<=tot;i++)
if (in[i]!=ou[i]) {
fla=false;
break;
}
if (!fla) continue;
ans.clear();
dfs(1);
if (ans.size()<2*n) continue;
for (int i=(int)ans.size()-1;i>=0;i--)
if (ans[i]<=n) cout<<ans[i]<<' ';
cout<<'\n';
for (int i=(int)ans.size()-1;i>=0;i--)
if (ans[i]>n) cout<<ans[i]-n<<' ';
cout<<'\n';
return ;
}
cout<<-1<<'\n';
return ;
}
int main()
{
// freopen("data.in","r",stdin);
// freopen("j.out","w",stdout);
ios::sync_with_stdio(false);
cin.tie(nullptr),cout.tie(nullptr);
int T;
cin>>T;
while (T) {
Solve();
T--;
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 11ms
memory: 122648kb
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: -100
Time Limit Exceeded
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 ...