QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#555823 | #7686. The Phantom Menace | rotcar07 | WA | 947ms | 191824kb | C++14 | 2.1kb | 2024-09-10 10:32:56 | 2024-09-10 10:32:57 |
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-09-10 10:32:56]
- 提交
answer
#include<bits/stdc++.h>
using namespace std;
constexpr int maxn=2e6+5;
int n,m;
vector<pair<int,int>> e[maxn];
typedef unsigned long long ull;
constexpr ull mod=1e9+9,base=233;
ull bs[maxn];
vector<ull> hs[maxn][2];
vector<int> ans;
void dfs(int p){
while(!e[p].empty()){
auto x=e[p].back();e[p].pop_back();
dfs(x.first);
ans.push_back(x.second);
}
}
int deg[maxn];
inline void solve(){
ans.clear();
cin>>n>>m;for(int _:{0,1}){
for(int i=1;i<=n;i++){
string s;cin>>s;
ull cur=0;hs[i][_].push_back(cur);
for(auto x:s) hs[i][_].push_back(cur=(cur*base+x)%mod);
}
}
for(int t=0;t<m;t++){
ans.clear();
// cout<<"1233 "<<t<<'\n';
unordered_map<ull,int> p[2];
int tot=0;
auto get=[&](int op,ull x){
// cout<<op<<' '<<x<<'\n';
if(p[op].count(x)) return p[op][x];
else return p[op][x]=++tot;
};
for(int i=1;i<=n;i++){
ull x=hs[i][0][t],y=(hs[i][0][m]+mod-hs[i][0][t]*bs[m-t]%mod)%mod;
int xx=get(0,x),yy=get(1,y);
// cout<<i<<' '<<xx<<' '<<yy<<'\n';
e[xx].push_back(make_pair(yy,i));deg[yy]++;
}
for(int i=1;i<=n;i++){
ull x=hs[i][1][m-t],y=(hs[i][1][m]+mod-hs[i][1][m-t]*bs[t]%mod)%mod;
int xx=get(1,x),yy=get(0,y);
e[xx].push_back(make_pair(yy,-i));deg[yy]++;
}
bool f=1;
for(int i=1;i<=tot;i++) {if(e[i].size()!=deg[i]) f=0;deg[i]=0;}
dfs(1);
// for(auto x:ans) cout<<x<<' ';cout<<'\n';
for(int i=1;i<=tot;i++)e[i].clear();
if(!f) continue;
if(ans.size()==2*n){
reverse(ans.begin(),ans.end());
vector<int> u,v;
for(auto x:ans) (x>0?u:v).push_back(abs(x));
for(auto x:u) cout<<x<<' ';cout<<'\n';
for(auto y:v) cout<<y<<' ';cout<<'\n';
return;
}
}
cout<<"-1\n";
}
int main(){
int T;cin>>T;
for(int i=bs[0]=1;i<=maxn-5;i++) bs[i]=bs[i-1]*base%mod;
while(T--) solve();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 27ms
memory: 160688kb
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
Wrong Answer
time: 947ms
memory: 191824kb
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:
wrong answer not cyclic isomorphism (test case 2)