QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#239776 | #7686. The Phantom Menace | ucup-team197# | WA | 271ms | 168356kb | C++14 | 2.8kb | 2023-11-04 23:14:56 | 2023-11-04 23:14:58 |
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 23:14:56]
- 提交
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fi first
#define se second
ll n,m;
string a[1000005],b[1000005];
const ll b1=2977,m1=1e9+7,b2=9277,m2=998244353;
void add(pair<ll,ll>&x,char c){
x.fi=(x.fi*b1+c)%m1;
x.se=(x.se*b2+c)%m2;
}
pair<int,int>g[1000005],h[1000005];
unordered_map<ll,ll>mp,mp1,mp2;
bool check0(){
mp.clear();
int sz=0;
for(int i=1; i<=n ;i++){
pair<ll,ll>hsh={0LL,0LL};
for(auto c:a[i]) add(hsh,c);
if(mp[hsh.fi*m2+hsh.se]==0) mp[hsh.fi*m2+hsh.se]=++sz;
g[i]={mp[hsh.fi*m2+hsh.se],sz};
}
for(int i=1; i<=n ;i++){
pair<ll,ll>hsh={0LL,0LL};
for(auto c:b[i]) add(hsh,c);
if(mp[hsh.fi*m2+hsh.se]==0) mp[hsh.fi*m2+hsh.se]=++sz;
h[i]={mp[hsh.fi*m2+hsh.se],sz};
}
sort(g+1,g+n+1);sort(h+1,h+n+1);
for(int i=1; i<=n ;i++) if(g[i].fi!=h[i].fi) return false;
for(int i=1; i<=n ;i++) cout << g[i].se << ' ';
cout << '\n';
for(int i=1; i<=n ;i++) cout << h[i].se << ' ';
cout << '\n';
return true;
}
const int N=4e6+5;
vector<pair<int,int> >adj[N];
int in[N],out[N];
vector<int>ans;
void dfs(int id){
if(adj[id].empty()) return;
auto c=adj[id].back();adj[id].pop_back();
ans.push_back(c.fi);
dfs(c.se);
}
void adde(int u,int v,int w){
//cout << "Adde " << u << ' ' << v << ' ' << w << endl;
adj[u].push_back({w,v});
out[u]++;in[v]++;
}
bool check(int p){
//cout << "Check " << p << endl;
mp1.clear();mp2.clear();
int sz=0;
for(int i=1; i<=4*n ;i++){
adj[i].clear();
in[i]=0;out[i]=0;
}
for(int i=1; i<=n ;i++){
pair<ll,ll>hsh={0LL,0LL};
for(int j=0; j<p ;j++) add(hsh,a[i][j]);
if(mp1[hsh.fi*m2+hsh.se]==0) mp1[hsh.fi*m2+hsh.se]=++sz;
int v1=mp1[hsh.fi*m2+hsh.se];
hsh={0LL,0LL};
for(int j=p; j<m ;j++) add(hsh,a[i][j]);
if(mp2[hsh.fi*m2+hsh.se]==0) mp2[hsh.fi*m2+hsh.se]=++sz;
int v2=mp2[hsh.fi*m2+hsh.se];
adde(v1,v2,i);
}
for(int i=1; i<=n ;i++){
pair<ll,ll>hsh={0LL,0LL};
for(int j=m-p; j<m ;j++) add(hsh,b[i][j]);
if(mp1[hsh.fi*m2+hsh.se]==0) mp1[hsh.fi*m2+hsh.se]=++sz;
int v1=mp1[hsh.fi*m2+hsh.se];
hsh={0LL,0LL};
for(int j=0; j<m-p ;j++) add(hsh,b[i][j]);
if(mp2[hsh.fi*m2+hsh.se]==0) mp2[hsh.fi*m2+hsh.se]=++sz;
int v2=mp2[hsh.fi*m2+hsh.se];
adde(v2,v1,i+n);
}
for(int i=1; i<=sz ;i++) if(in[i]!=out[i]) return false;
ans.clear();
dfs(1);
for(int i=0; i<2*n ;i+=2) cout << ans[i] << ' ';
cout << '\n';
for(int i=1; i<2*n ;i+=2) cout << ans[i]-n << ' ';
cout << '\n';
return true;
}
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];
if(check0()) return;
for(int j=1; j<m ;j++){
if(check(j)) return;
}
cout << "-1\n";
}
int main(){
ios::sync_with_stdio(false);cin.tie(0);
int t;cin >> t;while(t--) solve();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 16ms
memory: 167876kb
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: 271ms
memory: 165068kb
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:
ok 1000000 cases (1000000 test cases)
Test #3:
score: 0
Accepted
time: 194ms
memory: 168356kb
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 ...
result:
ok 500000 cases (500000 test cases)
Test #4:
score: -100
Wrong Answer
time: 186ms
memory: 163492kb
input:
500000 2 1 d d b a 2 1 c d b a 2 1 b d b a 2 1 a d b a 2 1 d c b a 2 1 c c b a 2 1 b c b a 2 1 a c b a 2 1 d b b a 2 1 c b b a 2 1 b b b a 2 1 a b b a 2 1 d a b a 2 1 c a b a 2 1 b a b a 2 1 a a b a 2 1 d d a a 2 1 c d a a 2 1 b d a a 2 1 a d a a 2 1 d c a a 2 1 c c a a 2 1 b c a a 2 1 a c a a 2 1 d...
output:
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 1 2 2 2 -1 -1 1 2 2 2 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 1 1 1 1 1 1 1 1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 1 2 2 2 -1 -1 1 2 2 2 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 1 2 2 2 -1 -1 -1 -1 -1 1 2 2 2 -1 -1 -1 -1 -1 -1 -1 -1 -...
result:
wrong answer q is not permutation (test case 12)