QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#487762 | #7686. The Phantom Menace | SATSKY | WA | 1659ms | 3636kb | C++14 | 4.4kb | 2024-07-23 09:51:30 | 2024-07-23 09:51:30 |
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-07-23 09:51:30]
- 提交
answer
#include<bits/stdc++.h>
using namespace std;using ll=long long;using ld=long double;using pii=pair<int,int>;
const int M=998244353;const ll inf=1e17;const double eps=1e-10;
bool tst=1;double sum_T[5];int cc=0,cr;
struct Hsr
{
ll res[2];
bool operator==(Hsr A){return A.res[0]==res[0]&&A.res[1]==res[1];}
};
bool operator<(Hsr A,Hsr B)
{
if(A.res[0]^B.res[0])return A.res[0]<B.res[0];
return A.res[1]<B.res[1];
};
struct Hash{//0->1 bas
string s;int n;vector<vector<ll>>l,r,b;int mod[2]={998244353,int(1e9+9)},fac[2]={9527,3960};
Hsr GhL(int L,int R)
{
clock_t cb=clock();
if(L>R)return Hsr{{0,0}};
Hsr C;for(int e=0;e<2;e++)C.res[e]=
(l[e][R]-l[e][L-1]*b[e][R-L+1]%mod[e]+mod[e])%mod[e];
sum_T[0]+=double(clock()-cb);
return C;
}
int tran(char c){return c-'a'+1;}
void ini(){//cin>>s;
if(!tst)cin>>s;else
//cr++,s=('a'+cr%26)+('a'+cr/26%26);
//cr++,s=('a'+cr%26);
cr++,s="a";
n=s.length();b.resize(2,vector<ll>(n+2));
l.resize(2,vector<ll>(n+2));
for(int e=0;e<2;e++)b[e][0]=1,l[e][0]=0;
for(int e=0;e<2;e++)for(int i=1;i<=n;i++){b[e][i]=b[e][i-1]*fac[e]%mod[e];
l[e][i]=(l[e][i-1]*fac[e]+tran(s[i-1]))%mod[e];
}}
};
struct S2
{
int n,m,siz=0;
vector<int>gd,cov,l,r,ec;
vector<vector<int>>es;
bool ini(int _n,vector<pii>vr)
{
clock_t cb=clock();
n=_n;m=vr.size();
gd.resize(m+1,0);
es.resize(n+1);
ec.resize(n+1,0);cov=l=r=ec;
for(int i=1,u,v;i<=m;i++)
{
u=vr[i-1].first,v=vr[i-1].second;
es[u].push_back(i);ec[u]++;gd[i]=u^v;
}
bool o=solve();
sum_T[1]+=double(clock()-cb);
return o;
}
//void merge(int a,int b){E[a].r=b,E[b].l=a;}
//void sepe(int x){int y=E[x].r;E[x].r=0;E[y].l=0;if(y)tar=y;}
int tar,thd;
void spr2(int p,int x)
{
cov[x]=1;siz++;//cc++;
if(thd==p)
{
r[x]=tar,l[tar]=x;tar=thd=0;
}
while(ec[p])
{
int k=es[p][--ec[p]];
cc++;
if(k==x&&gd[k])continue;
if(!cov[k])
{
int y=r[x];r[x]=k,l[k]=x;
if(y)l[y]=0,tar=y,thd=p;
spr2(gd[k]^p,k);
}
}
}
vector<int>R;
bool solve()
{
int x=es[1][0];tar=x;thd=1;
clock_t cb=clock();
spr2(gd[x]^1,x);
//cout<<siz<<"!!\n";
sum_T[2]+=double(clock()-cb);
if(siz!=m)return 0;
R.push_back(1);int p=1,c=siz;
while(c--){p=gd[x]^p;R.push_back(p);x=r[x];}
return 1;
}
};
struct S
{
int n,m;vector<Hash>A,B;
void ini()
{
clock_t cb=clock();
if(!tst)cin>>n>>m;
else n=1000000,m=1;
A.resize(n+1);B.resize(n+1);
for(int i=1;i<=n;i++)A[i].ini();
for(int i=1;i<=n;i++)B[i].ini();
sum_T[4]+=double(clock()-cb);
}
bool Sol(int p)
{
S2 C;vector<pii>es;vector<int>cnt(n*6+1,0);int cc=n*2;
clock_t cb=clock();
{
map<Hsr,int>mp;
for(int i=1;i<=n;i++)
{
auto a=A[i].GhL(1,p);//cout<<"A"<<a.len<<'.'<<a.res[0]<<'\n';
int id=mp[a];if(!id)mp[a]=id=++cc;es.push_back({i,id});
cnt[id]++;
}
for(int i=1;i<=n;i++)
{
auto a=B[i].GhL(m-p+1,m);//cout<<"B"<<a.len<<'.'<<a.res[0]<<'\n';
int id=mp[a];if(!id)mp[a]=id=++cc;es.push_back({id,i+n});
cnt[id]--;
}
}
{
map<Hsr,int>mp;
for(int i=1;i<=n;i++)
{
auto a=A[i].GhL(p+1,m);//cout<<"C"<<a.len<<'.'<<a.res[0]<<'\n';
int id=mp[a];if(!id)mp[a]=id=++cc;es.push_back({id,i});
cnt[id]++;
}
for(int i=1;i<=n;i++)
{
auto a=B[i].GhL(1,m-p);//cout<<"D"<<a.len<<'.'<<a.res[0]<<'\n';
int id=mp[a];if(!id)mp[a]=id=++cc;es.push_back({i+n,id});
cnt[id]--;
}
}
sum_T[3]+=double(clock()-cb);
for(int i=1;i<=cc;i++)if(cnt[i])return 0;
if(!C.ini(cc,es))return 0;
auto&R=C.R;int siz=R.size()-1;
//if(siz!=n*4)while(1);
vector<int>ra,rb;
for(int i=siz;i;i--)
{
int id=R[i];if(id>n*2)continue;
if(id<=n)ra.push_back(id);else rb.push_back(id);
}
//if(int(ra.size()!=n))while(1);if(int(rb.size()!=n))while(1);
if(!tst)
{
for(int i=0;i<n;i++)cout<<ra[i]<<" \n"[i==n-1];
for(int i=0;i<n;i++)cout<<rb[i]-n<<" \n"[i==n-1];
}
return 1;
}
void solve()
{
for(int i=0;i<m;i++)if(Sol(i))return;
if(!tst)cout<<"-1\n";
}
};
void precal()
{
tst=0;
}
int main()
{
//freopen("1.in","r",stdin);
//cout<<fixed<<setprecision(12);
ios::sync_with_stdio(0);cin.tie(0);precal();
int t=1;cin>>t;
clock_t a=clock();
while(t--){S SS;SS.ini();SS.solve();}
return 0;
cout<<"Time:"<<double(clock()-a)<<'\n';
for(int i=0;i<5;i++)
cout<<"Time:"<<sum_T[i]<<'\n';
cout<<"cc:"<<cc<<'\n';
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 3556kb
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: 1659ms
memory: 3588kb
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: 0
Accepted
time: 1106ms
memory: 3636kb
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...
result:
ok 500000 cases (500000 test cases)
Test #4:
score: -100
Wrong Answer
time: 1067ms
memory: 3556kb
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 1 -1 -1 1 2 1 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 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -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 Jury has the answer but participant has not (test case 32)