QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#358961 | #7686. The Phantom Menace | wsc2008 | WA | 305ms | 193204kb | C++14 | 2.8kb | 2024-03-20 09:56:08 | 2024-03-20 09:56:08 |
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-03-20 09:56:08]
- 提交
answer
#pragma GCC optimize("2,3,Ofast,inline,unroll-loops")
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define pii pair<ll,ll>
#define rep(i,a,b) for(ll i=(a);i<=(b);++i)
#define per(i,a,b) for(ll i=(a);i>=(b);--i)
using namespace std;
bool Mbe;
inline ll read(){
ll x=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-f;ch=getchar();}
while(ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();
return x*f;
}
inline void write(ll x){
if(x<0)putchar('-'),x=-x;
if(x>9)write(x/10);
putchar(x%10+'0');
}
const ll N=2e6+9;
const ull B=47383,Mod=998244353;
ll T,n,m,hd[N],pw[N],tote,tot,in[N],out[N],cur[N];
vector<ll>hsha[N],hshb[N];
vector<char>a[N],b[N];
map<ll,ll>pt;
ll Ha(ll id,ll l,ll r){
if(l>r)return 0;
return (hsha[id][r]-hsha[id][l-1]*pw[r-l+1]%Mod+Mod)%Mod;
}
ll Hb(ll id,ll l,ll r){
if(l>r)return 0;
return (hshb[id][r]-hshb[id][l-1]*pw[r-l+1]%Mod+Mod)%Mod;
}
struct Edg{
ll to,nxt,id,tp;
}es[N];
vector<pii>res;
void adde(ll x,ll y,ll z,ll w){
out[x]++,in[y]++;
es[++tote]=(Edg){y,hd[x],z,w};
hd[x]=tote;
}
void dfs(ll x){
for(ll&i=cur[x];i;){
ll y=es[i].to;
res.push_back(make_pair(es[i].id,es[i].tp));
i=es[i].nxt;
dfs(y);
}
}
char s[N];
void solve(){
n=read(),m=read();
pw[0]=1;
rep(i,1,m)pw[i]=pw[i-1]*B%Mod;
rep(i,1,n)hsha[i].clear(),hsha[i].resize(m+2);
rep(i,1,n)hshb[i].clear(),hshb[i].resize(m+2);
rep(i,1,n){
scanf("%s",s+1);
a[i].clear(),a[i].resize(m+2);
rep(j,1,m){
a[i][j]=s[j];
hsha[i][j]=(hsha[i][j-1]*B+a[i][j])%Mod;
}
}
rep(i,1,n){
scanf("%s",s+1);
b[i].clear(),b[i].resize(m+2);
rep(j,1,m){
b[i][j]=s[j];
hshb[i][j]=(hshb[i][j-1]*B+b[i][j])%Mod;
}
}
vector<ll>resa,resb;
rep(i,0,m-1){
tot=0,tote=0;
pt.clear();
rep(j,0,n*2)hd[j]=0,in[j]=out[j]=0;
rep(j,1,n){
ll pre=Ha(j,1,i),suf=Ha(j,i+1,m);
if(pt.find(pre)==pt.end())pt[pre]=++tot;
if(pt.find(suf)==pt.end())pt[suf]=++tot;
adde(pt[pre],pt[suf],j,0);
}
rep(j,1,n){
ll pre=Hb(j,1,m-i),suf=Hb(j,m-i+1,m);
if(pt.find(pre)==pt.end())pt[pre]=++tot;
if(pt.find(suf)==pt.end())pt[suf]=++tot;
adde(pt[pre],pt[suf],j,1);
}
ll fl=1;
rep(j,1,tot){
if(abs(in[j]-out[j])>=1){
fl=0;
break;
}
}
if(!fl)continue;
rep(j,1,tot)cur[j]=hd[j];
res.clear();
dfs(1);
for(pii p:res){
if(!p.second)resa.push_back(p.first);
else resb.push_back(p.first);
}
for(ll x:resa)write(x),putchar(' ');
putchar('\n');
for(ll x:resb)write(x),putchar(' ');
putchar('\n');
return ;
}
puts("-1");
}
bool Med;
int main(){
cerr<<fabs(&Med-&Mbe)/1048576.0<<"MB\n";
T=read();
while(T--)solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 20ms
memory: 191620kb
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: 305ms
memory: 192948kb
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: -100
Wrong Answer
time: 246ms
memory: 193204kb
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 ...
result:
wrong answer q is not permutation (test case 17)