QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#238841 | #7686. The Phantom Menace | ucup-team1448# | WA | 268ms | 163348kb | C++17 | 4.8kb | 2023-11-04 17:41:30 | 2023-11-04 17:41: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)
- [2023-11-09 15:33:42]
- hack成功,自动添加数据
- (//qoj.ac/hack/445)
- [2023-11-04 17:41:30]
- 提交
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<bits/extc++.h>
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){
for(int i=1;i<=N;++i) if(ind[i]!=oud[i]) return 0;
ans.clear();
dfs(1,0);
return 1;
}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;
const int bas=2347;
__gnu_pbds::gp_hash_table<ll,int> mp;
std::set<std::pair<ll,int> > hshmst;
std::vector<ll> ha[1000006],hb[1000006];
ll bpw[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;
}void gethash(std::vector<ll>&hsh){
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);
//for(ll x:hsh) printf("%lld ",x);
//putchar(10);
}ll getrange(std::vector<ll>&hsh,int l,int r){
--l;
--r;
//printf("[%d %d]\n",l,r);
return l?(hsh[r]-(__int128)hsh[l-1]*bpw[r-l+1]%mod+mod)%mod:
hsh[r];
}void _(){
int N,M;
scanf("%d%d",&N,&M);
for(int i=1;i<=N;++i){
scanf("%s",tsz+1);
gethash(ha[i]);
}
for(int i=1;i<=N;++i){
scanf("%s",tsz+1);
gethash(hb[i]);
}
for(int d=1;d<M;++d){
int vcnt=0;
mp.clear();
for(int i=1;i<=N;++i){
ll pref,suff;
pref=getrange(ha[i],1,d);
suff=getrange(ha[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){
ll pref,suff;
pref=getrange(hb[i],1,M-d);
suff=getrange(hb[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)){
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(ha[i].back(),i);
for(int i=1;i<=N;++i){
auto it=hshmst.lower_bound(std::make_pair(hb[i].back(),0));
if(it!=hshmst.end()&&it->first==hb[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: 22ms
memory: 160828kb
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: 268ms
memory: 157416kb
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: 219ms
memory: 163348kb
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)