QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#238120 | #7686. The Phantom Menace | ucup-team055# | WA | 1045ms | 3836kb | C++17 | 3.3kb | 2023-11-04 15:50:07 | 2023-11-04 15:50:07 |
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-09 15:33:42]
- hack成功,自动添加数据
- (//qoj.ac/hack/445)
- [2023-11-04 15:50:07]
- 提交
answer
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=(int)a;i<(int)b;i++)
using ll =long long;
#define all(p) p.begin(),p.end()
using u64=uint64_t;
struct RH{
static inline const u64 mod=0x1FFF'FFFF'FFFF'FFFF,base=mt19937_64 {random_device{}()}()%mod;
ll n;
vector<u64> hash,pow;
static u64 add(u64 a,u64 b){
a+=b;
if(a>=mod) a-=mod;
return a;
}
static u64 mul(u64 a,u64 b){
auto c=__uint128_t(a)*b;
return add(c>>61,c&mod);
}
RH(const string& s):n(s.size()),hash(n+1),pow(n+1,1){
for(ll i=0;i<n;i++){
pow[i+1]=mul(pow[i],base);
hash[i+1]=add(mul(hash[i],base),s[i]);
}
}
u64 get(ll l,ll r)const {
return add(hash[r], mod - mul(hash[l], pow[r - l]));
}
};
vector<int> EW(vector<vector<pair<int,int>>> &gr,int nedges,int src=0){
int n=gr.size();
vector<int> D(n),its(n),eu(nedges),ret,s={src},ed;
D[src]++;
while(!s.empty()){
int x=s.back(),y,e,&it=its[x],end=gr[x].size();
if(it==end){
if(!ed.empty()){
e=ed.back();ed.pop_back();
ret.push_back(e);
}
s.pop_back();
continue;
}
tie(y,e)=gr[x][it++];
if(!eu[e]){
D[x]--,D[y]++;
eu[e]=1;
s.push_back(y);
ed.push_back(e);
}
}
for(int x:D) if(x<0||ret.size()!=nedges) return {};
reverse(all(ret));
return ret;
}
void vec_out(vector<int> v,int add=1){
rep(i,0,v.size()){
if(i) cout<<" ";
cout<<v[i]+add;
}
cout<<"\n";
}
void solve(){
int N,M;
cin>>N>>M;
vector<vector<RH>> A(2);
vector<vector<string>> S(2,vector<string>(N));
rep(i,0,2) rep(j,0,N){
cin>>S[i][j];
RH tmp(S[i][j]);
A[i].push_back(tmp);
}
vector<vector<int>> order(2,vector<int>(N));
rep(i,0,2){
rep(j,0,N) order[i][j]=j;
sort(all(order[i]),[&](int l,int r){
return S[i][l]<S[i][r];
});
}
bool ok=1;
rep(i,0,N) if(S[0][order[0][i]]!=S[1][order[1][i]]) ok=0;
if(ok){
vec_out(order[0]);
vec_out(order[1]);
return;
}
using F=pair<u64,bool>;
rep(x,1,M){
map<F,int> m;
vector<vector<pair<int,int>>> G;
auto f=[&](F val) -> int {
if(!m.count(val)){
m[val]=m.size();
G.push_back({});
}
return m[val];
};
//0
rep(i,0,N){
F X={A[0][i].get(0,M-x),0};
F Y={A[0][i].get(M-x,M),1};
int a=f(X),b=f(Y);
G[a].push_back({b,i});
}
//1
rep(i,0,N){
F X={A[1][i].get(0,x),1};
F Y={A[1][i].get(x,M),0};
int a=f(X),b=f(Y);
G[a].push_back({b,N+i});
}
auto E=EW(G,2*N,0);
if(E.empty()) continue;
vector<vector<int>> ans(2);
rep(i,0,2*N){
ans[i&1].push_back(E[i]%N);
}
vec_out(ans[0]), vec_out(ans[1]);
return;
}
cout<<"-1\n";
}
/*
2 3 3 abc ghi def bcd efg hia 1 3 abc def
*/
int main(){
int T;
cin>>T;
while(T--) solve();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3612kb
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: 0
Accepted
time: 1045ms
memory: 3836kb
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 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:
ok 1000000 cases (1000000 test cases)
Test #3:
score: -100
Wrong Answer
time: 728ms
memory: 3764kb
input:
500000 1 2 dd ba 1 2 cd ba 1 2 bd ba 1 2 ad ba 1 2 dc ba 1 2 cc ba 1 2 bc ba 1 2 ac ba 1 2 db ba 1 2 cb ba 1 2 bb ba 1 2 ab ba 1 2 da ba 1 2 ca ba 1 2 ba ba 1 2 aa ba 1 2 dd aa 1 2 cd aa 1 2 bd aa 1 2 ad aa 1 2 dc aa 1 2 cc aa 1 2 bc aa 1 2 ac aa 1 2 db aa 1 2 cb aa 1 2 bb aa 1 2 ab aa 1 2 da aa 1 2...
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 -1 -1 -1 -1 -1 -1 1 1 -1 -1 -1 -1 -1 -1 -1 -1 ...
result:
wrong answer not cyclic isomorphism (test case 9)