QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#248659 | #7686. The Phantom Menace | pengpeng_fudan | WA | 357ms | 249384kb | C++14 | 3.0kb | 2023-11-11 20:45:34 | 2023-11-11 20:45:35 |
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-11 20:45:34]
- 提交
answer
#include <bits/stdc++.h>
using namespace std;
using ull=unsigned long long;
using ll=long long;
using PII=pair<ull,ull>;
const ull p=1331;
ull h[1000010];
vector<ull> hs[2000010];
void intt(){
h[0]=1;
for(int i=1;i<=1000000;i++) h[i]=h[i-1]*p;
}
ll get(int num,int l,int r){
if(r<l) return 0;
return hs[num][r]-hs[num][l-1]*h[r-l+1];
}
int n,m;
string s;
void add(int x){
hs[x].clear();
hs[x].resize(m+1);
for(int i=1;i<=m;i++){
hs[x][i]=(hs[x][i-1]*p+s[i-1]-'a'+1);
}
}
vector<pair<int,int>> ve[8000010];
int tot=0;
int du[8000010];
vector<int> ans;
vector<int> a1,b1;
bool fg[2000010];
void dfs(int u){
int sz=ve[u].size();
for(int i=sz-1;i>=0;i--){
int v=ve[u][i].first,num=ve[u][i].second;
ve[u].pop_back();
dfs(v);
fg[num]=1;
ans.push_back(num);
}
}
vector<ull> vk;
int get_pz(ull x){
return lower_bound(vk.begin(),vk.end(),x)-vk.begin()+1;
}
void solve() {
cin>>n>>m;
for(int i=1;i<=2*n;i++){
cin>>s;
add(i);
}
ull u=(1331<<20);
ans.clear(),a1.clear(),b1.clear();
for(int i=0;i<m;i++){
vk.clear();
for(int j=1;j<=tot;j++){
ve[j].clear();
du[j]=0;
}
tot=0;
for(int j=1;j<=n;j++){
ull a=get(j,1,i),b=get(j,i+1,m)+u;
vk.push_back(a),vk.push_back(b);
}
for(int j=n+1;j<=2*n;j++){
ull a=get(j,1,m-i)+u,b=get(j,m-i+1,m);
vk.push_back(a),vk.push_back(b);
}
sort(vk.begin(),vk.end());
vk.erase(unique(vk.begin(),vk.end()),vk.end());
tot=vk.size();
int st=0;
for(int j=1;j<=n;j++){
ull a=get(j,1,i),b=get(j,i+1,m)+u;
int a1=get_pz(a),b1=get_pz(b);
st=a1;
du[a1]++,du[b1]--;
ve[a1].push_back({b1,j});
}
for(int j=n+1;j<=2*n;j++){
ull a=get(j,1,m-i)+u,b=get(j,m-i+1,m);
int a1=get_pz(a),b1=get_pz(b);
du[a1]++,du[b1]--;
ve[a1].push_back({b1,j});
}
bool flag=false;
for(int j=1;j<=tot;j++){
if(du[j]){
flag=true;
break;
}
}
if(flag) continue;
ans.clear();
fill(fg+1,fg+2*n+1,0);
dfs(st);
for(int j=1;j<=2*n;j++){
if(!fg[j]){
flag=true;
break;
}
}
if(flag) continue;
int sz=ans.size();
for(int j=sz-1;j>=0;j--){
if(ans[j]>n) b1.push_back(ans[j]-n);
else a1.push_back(ans[j]);
}
for(auto j:a1) cout<<j<<' ';
cout<<'\n';
for(auto j:b1) cout<<j<<' ';
cout<<'\n';
return ;
}
cout<<-1<<'\n';
return ;
}
int main() {
ios::sync_with_stdio(0),cin.tie(0);
cout.tie(0);
int _ = 1;
intt();
cin >> _;
while(_--) solve();
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 35ms
memory: 246256kb
input:
2 3 3 abc ghi def bcd efg hia 1 3 abc def
output:
3 2 1 2 3 1 -1
result:
ok 2 cases (2 test cases)
Test #2:
score: 0
Accepted
time: 357ms
memory: 249272kb
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: 191ms
memory: 249384kb
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: 236ms
memory: 248080kb
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 1 1 2 -1 -1 1 2 1 2 1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 1 2 1 1 2 1 1 2 1 1 2 1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 1 2 1 2 1 -1 -1 1 2 1 1 2 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 1 2 1 2 1 -1 -1 -1 -1 -1 1 2 1 1 2 -1 -1...
result:
wrong answer q is not permutation (test case 12)