QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#852156 | #7686. The Phantom Menace | Ooj_bai | WA | 330ms | 359724kb | C++14 | 4.1kb | 2025-01-11 10:22:58 | 2025-01-11 10:23:00 |
Judging History
answer
#include<bits/stdc++.h>
#pragma GCC optimize(2)
#ifndef _WINDOWS_
#define gc() getchar_unlocked()
#define pc(ch) putchar_unlocked(ch)
#endif
#define maxn 2000005
#define mod 998244353
#define BASE 131
using namespace std;
typedef long long ll;
namespace FASTIO{
int read(){
int x=0,w=0;
char ch=' ';
while(!isdigit(ch)){
if(ch=='-')
w=1;
ch=gc();
}
while(isdigit(ch)){
x=x*10+ch-'0';
ch=gc();
}
return (w?-x:x);
}
int __fastwrite_stack[45],__fastwrite_top;
inline void write(int x){
__fastwrite_top=0;
do{
__fastwrite_stack[__fastwrite_top++]=x%10;
x/=10;
}while(x);
while(__fastwrite_top--)pc(__fastwrite_stack[__fastwrite_top]+'0');
}
char readc(){
char ch=' ';
while(ch<'a'||ch>'z')ch=gc();
return ch;
}
}
using namespace FASTIO;
struct edge{
int next;
pair<int,int>to;
}e[maxn<<2];
int h[maxn<<2],cnt;
void add(int x,const pair<int,int> &y){
e[++cnt]={h[x],y};
h[x]=cnt;
}
int t,n,m;
int base[maxn];
char f[maxn];
int ls[maxn],lss[maxn];
int *D[maxn],*_D[maxn];
pair<int,bool> lsh[maxn<<2];
int vis[maxn<<2];
void dfs(int x,int *ans,int &n){
vis[x]=1;
for(int i=h[x];i;i=h[x]){
pair<int,int> itt=e[i].to;
h[x]=e[i].next;
dfs(itt.first,ans,n);
ans[++n]=itt.second;
}
}
int rd[maxn<<2],cd[maxn<<2];
int x[maxn],y[maxn];
int ans[maxn<<2];
signed main(){
base[0]=1;
for(int i=1;i<=1e6;i++)base[i]=base[i-1]*BASE%mod;
cin>>t;
while(t--){
n=read();m=read();
for(int i=0;i<2*n;i++){
D[i]=ls+i*m;
_D[i]=lss+((i+1)*m-1);
for(int j=0;j<m;j++){
f[j]=readc();
D[i][j]=(j?D[i][j-1]+(ll)base[j]*f[j]:f[j])%mod;
}
for(int j=m-1;j>=0;j--)
_D[i][j]=(j==m-1?f[j]:(ll)BASE*_D[i][j+1]+f[j])%mod;
}
int ok=0;
for(int i=0;i<m;i++){
int cnt=-1;
lsh[++cnt]={0,0};
for(int j=0;j<n;j++){
if(i)lsh[++cnt]={D[j][i-1],0};
lsh[++cnt]={_D[j][i],1};
}
for(int j=n;j<2*n;j++){
lsh[++cnt]={D[j][m-i-1],1};
if(i)lsh[++cnt]={_D[j][m-i],0};
}
sort(lsh,lsh+cnt+1);
cnt=unique(lsh,lsh+cnt+1)-lsh;
::cnt=0;
for(int j=0;j<=cnt;j++)
vis[j]=h[j]=rd[j]=cd[j]=0;
for(int j=0;j<n;j++){
int x=lower_bound(lsh,lsh+cnt+1,pair<int,bool>{(i?D[j][i-1]:0),0})-lsh;
int y=lower_bound(lsh,lsh+cnt+1,pair<int,bool>{_D[j][i],1})-lsh;
add(y,{x,j});
cd[x]++;rd[y]++;
}
for(int j=n;j<2*n;j++){
int x=lower_bound(lsh,lsh+cnt+1,pair<int,bool>{D[j][m-i-1],1})-lsh;
int y=lower_bound(lsh,lsh+cnt+1,pair<int,bool>{(i?_D[j][m-i]:0),0})-lsh;
add(y,{x,j});
cd[x]++;rd[y]++;
}
int bj=1;
for(int j=0;j<=cnt;j++)
if(rd[j]!=cd[j]){
bj=0;break;
}
if(bj){
int ccnt=0;
for(int j=0;j<=cnt;j++)
if(!vis[j])
dfs(j,ans,ccnt);
int cnt1=0,cnt2=0;
for(int j=1;j<=ccnt;j++){
int num=ans[j];
if(num<n){
x[++cnt1]=num+1;
}else{
y[++cnt2]=num-n+1;
}
}
for(int j=1;j<=n;j++)write(x[j]),pc(' ');pc('\n');
for(int j=1;j<=n;j++)write(y[j]),pc(' ');pc('\n');
ok=1;
break;
}
}
if(!ok){
pc('-');pc('1');pc('\n');
}
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 12ms
memory: 126304kb
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: 70ms
memory: 129880kb
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: 76ms
memory: 128800kb
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: 59ms
memory: 128848kb
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 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 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 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 2 1 1 2 -1 -1 -1 -1 -1 -1 -1 -1 -...
result:
ok 500000 cases (500000 test cases)
Test #5:
score: 0
Accepted
time: 73ms
memory: 129600kb
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: -100
Wrong Answer
time: 330ms
memory: 359724kb
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 3 1 2 1 2 3 -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 2 1 3 1 2 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 3 2 1 2 3 -1 -1 -1 -1 -...
result:
wrong answer p is not permutation (test case 448)