QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#238940 | #7686. The Phantom Menace | ucup-team1448# | WA | 291ms | 217388kb | C++17 | 5.4kb | 2023-11-04 17:56:59 | 2023-11-04 17:56:59 |
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 17:56:59]
- 提交
answer
//#define dxx
#ifdef dxx
#define dbg(...) fprintf(stderr,__VA_ARGS__)
#define dex(a) dbg(#a"=%lld onL%d infun %s\n",a,__LINE__,__FUNCTION__)
#include<cstdlib>
#define pause sys##tem("pause")
#define _GLIBCXX_DEBUG
#endif
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#include<set>
#include<map>
using ll=long long;
using std::max;
using std::min;
using std::abs;
template<class T> void cmax(T&a,T b){a=max(a,b);}
template<class T> void cmin(T&a,T b){a=min(a,b);}
template<class T> T sqr(T a){return a*a;}
namespace gph{
struct edge{
int t,id;
};
std::vector<edge> G[4000006];
int st[4000006],ind[4000006],oud[4000006];
void ade(int s,int t,int id){
G[s].push_back({t,id});
++ind[t];
++oud[s];
//printf("%d %d %d\n",s,t,id);
}
std::vector<int> ans;
bool evis[4000006];
void dfs(int x,int eid){
for(int e=st[x];e<(int)G[x].size();e=max(e+1,st[x])){
int t=G[x][e].t;
if(!evis[G[x][e].id]){
evis[G[x][e].id]=1;
st[x]=e+1;
dfs(t,G[x][e].id);
}
}
if(eid) ans.push_back(eid);
}bool geteuler(int N,int ecnt){
for(int i=1;i<=N;++i) if(ind[i]!=oud[i]) return 0;
ans.clear();
dfs(1,0);
if((int)ans.size()==ecnt) return 1;
return 0;
}void clear(int N,int ecnt){
for(int i=1;i<=N;++i) G[i].clear();
memset(evis+1,0,sizeof*evis*ecnt);
memset(st+1,0,sizeof*st*N);
memset(ind+1,0,sizeof*ind*N);
memset(oud+1,0,sizeof*oud*N);
}
}
namespace xm{
const ll mod=(ll)1e17+13,mod2=(ll)1e16+13;
const int bas=2347,bas2=127;
std::map<std::pair<ll,ll>,int> mp;
std::set<std::pair<std::pair<ll,ll>,int> > hshmst;
std::vector<ll> ha[1000006],hb[1000006];
std::vector<ll> ha2[1000006],hb2[1000006];
ll bpw[1000006],bpw2[1000006];
int oneans[1000006];
char tsz[1000006];
void getbpw(){
bpw[0]=1;
for(int i=1;i<1000006;++i) bpw[i]=(__int128)bpw[i-1]*bas%mod;
bpw2[0]=1;
for(int i=1;i<1000006;++i) bpw2[i]=(__int128)bpw2[i-1]*bas2%mod;
}void gethash(std::vector<ll>&hsh,std::vector<ll>&hsh2){
hsh.clear();
for(int i=1;tsz[i];++i)
hsh.push_back(i==1?tsz[i]-'a'+1:
((__int128)hsh.back()*bas%mod+tsz[i]-'a'+1)%mod);
hsh2.clear();
for(int i=1;tsz[i];++i)
hsh2.push_back(i==1?tsz[i]-'a'+1:
((__int128)hsh2.back()*bas2%mod2+tsz[i]-'a'+1)%mod2);
//for(ll x:hsh) printf("%lld ",x);
//putchar(10);
}std::pair<ll,ll> getrange(std::vector<ll>&hsh,std::vector<ll>&hsh2,int l,int r){
--l;
--r;
//printf("[%d %d]\n",l,r);
return std::make_pair(ll(l?(hsh[r]-(__int128)hsh[l-1]*bpw[r-l+1]%mod+mod)%mod:
hsh[r]),ll(l?(hsh2[r]-(__int128)hsh2[l-1]*bpw2[r-l+1]%mod2+mod2)%mod2:
hsh2[r]));
}void _(){
int N,M;
scanf("%d%d",&N,&M);
for(int i=1;i<=N;++i){
scanf("%s",tsz+1);
gethash(ha[i],ha2[i]);
}
for(int i=1;i<=N;++i){
scanf("%s",tsz+1);
gethash(hb[i],hb2[i]);
}
for(int d=1;d<M;++d){
int vcnt=0;
mp.clear();
for(int i=1;i<=N;++i){
auto pref=getrange(ha[i],ha2[i],1,d),suff=getrange(ha[i],ha2[i],d+1,M);
if(!mp[pref]) mp[pref]=++vcnt;
if(!mp[suff]) mp[suff]=++vcnt;
gph::ade(mp[pref],mp[suff],i);
//printf("%d %d\n",pref,suff);
}
for(int i=1;i<=N;++i){
auto pref=getrange(hb[i],hb2[i],1,M-d),suff=getrange(hb[i],hb2[i],M-d+1,M);
if(!mp[pref]) mp[pref]=++vcnt;
if(!mp[suff]) mp[suff]=++vcnt;
gph::ade(mp[pref],mp[suff],i+N);
//printf("%d %d\n",pref,suff);
}
if(gph::geteuler(vcnt,N*2)){
std::vector<int> ans1,ans2;
for(int x:gph::ans)
if(x<=N) ans1.push_back(x);
else ans2.push_back(x-N);
for(auto it=ans1.rbegin();it!=ans1.rend();++it)
printf("%d ",*it);
putchar(10);
for(auto it=ans2.rbegin();it!=ans2.rend();++it)
printf("%d ",*it);
putchar(10);
gph::clear(vcnt,N*2);
return;
}
gph::clear(vcnt,N*2);
}
hshmst.clear();
for(int i=1;i<=N;++i)
hshmst.emplace(std::make_pair(ha[i].back(),ha2[i].back()),i);
for(int i=1;i<=N;++i){
auto it=hshmst.lower_bound(std::make_pair(std::make_pair(hb[i].back(),hb2[i].back()),0));
if(it!=hshmst.end()&&it->first==std::make_pair(hb[i].back(),hb2[i].back())){
oneans[i]=it->second;
hshmst.erase(it);
}else{
puts("-1");
return;
}
}
for(int i=1;i<=N;++i) printf("%d ",i);
putchar(10);
for(int i=1;i<=N;++i) printf("%d ",oneans[i]);
putchar(10);
}
}
int main(){
int t;
xm::getbpw();
scanf("%d",&t);
while(t--) xm::_();
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 32ms
memory: 214432kb
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: 291ms
memory: 214040kb
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: 264ms
memory: 217388kb
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: 0
Accepted
time: 193ms
memory: 211904kb
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 2 1 2 1 2 1 2 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 1 2 1 2 -1 -1 1 2 2 1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 1 2 1 2 -1 -1 -1 -1 -1 1 2 2 1 -1 -1 -1 -1 -1 -1 -1 -1 -...
result:
ok 500000 cases (500000 test cases)
Test #5:
score: 0
Accepted
time: 258ms
memory: 216764kb
input:
333333 1 3 cbb bfa 1 3 bbb bfa 1 3 abb bfa 1 3 fab bfa 1 3 eab bfa 1 3 dab bfa 1 3 cab bfa 1 3 bab bfa 1 3 aab bfa 1 3 ffa bfa 1 3 efa bfa 1 3 dfa bfa 1 3 cfa bfa 1 3 bfa bfa 1 3 afa bfa 1 3 fea bfa 1 3 eea bfa 1 3 dea bfa 1 3 cea bfa 1 3 bea bfa 1 3 aea bfa 1 3 fda bfa 1 3 eda bfa 1 3 dda bfa 1 3 c...
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 333333 cases (333333 test cases)
Test #6:
score: 0
Accepted
time: 155ms
memory: 212740kb
input:
333333 3 1 c b b b f a 3 1 b b b b f a 3 1 a b b b f a 3 1 f a b b f a 3 1 e a b b f a 3 1 d a b b f a 3 1 c a b b f a 3 1 b a b b f a 3 1 a a b b f a 3 1 f f a b f a 3 1 e f a b f a 3 1 d f a b f a 3 1 c f a b f a 3 1 b f a b f a 3 1 a f a b f a 3 1 f e a b f a 3 1 e e a b f a 3 1 d e a b f a 3 1 c...
output:
-1 -1 -1 1 2 3 3 1 2 -1 -1 -1 -1 -1 -1 -1 -1 -1 1 2 3 1 2 3 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 1 2 3 2 1 3 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -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 3 1 3 2 -1 -1 -1 -1 -...
result:
ok 333333 cases (333333 test cases)
Test #7:
score: 0
Accepted
time: 268ms
memory: 217256kb
input:
250000 1 4 hbca fhaa 1 4 gbca fhaa 1 4 fbca fhaa 1 4 ebca fhaa 1 4 dbca fhaa 1 4 cbca fhaa 1 4 bbca fhaa 1 4 abca fhaa 1 4 haca fhaa 1 4 gaca fhaa 1 4 faca fhaa 1 4 eaca fhaa 1 4 daca fhaa 1 4 caca fhaa 1 4 baca fhaa 1 4 aaca fhaa 1 4 hhba fhaa 1 4 ghba fhaa 1 4 fhba fhaa 1 4 ehba fhaa 1 4 dhba fhaa...
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 250000 cases (250000 test cases)
Test #8:
score: -100
Wrong Answer
time: 151ms
memory: 213944kb
input:
250000 4 1 h b c a f h a a 4 1 g b c a f h a a 4 1 f b c a f h a a 4 1 e b c a f h a a 4 1 d b c a f h a a 4 1 c b c a f h a a 4 1 b b c a f h a a 4 1 a b c a f h a a 4 1 h a c a f h a a 4 1 g a c a f h a a 4 1 f a c a f h a a 4 1 e a c a f h a a 4 1 d a c a f h a a 4 1 c a c a f h a a 4 1 b a c a f...
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 2 3 4 1 2 3 4 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 ...
result:
wrong answer not cyclic isomorphism (test case 652)