QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#564141 | #7686. The Phantom Menace | syxsyx | WA | 628ms | 364280kb | C++14 | 3.7kb | 2024-09-14 20:45:24 | 2024-09-14 20:45:24 |
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-09-14 20:45:24]
- 提交
answer
#include<bits/stdc++.h>
using namespace std;
const int N=2000005,K=26;
const long long mod=1000000000000000003ll,BASE=131;
int T;
int n,m;
string a[N],b[N];
long long fac[N];
vector <long long> hsha[N][2],hshb[N][2];
int srta[N],srtb[N];
bool cmpa(int x,int y){return a[x]<a[y];}
bool cmpb(int x,int y){return b[x]<b[y];}
bool check0()
{
for(int i=1;i<=n;i++) srta[i]=srtb[i]=i;
sort(srta+1,srta+n+1,cmpa);
sort(srtb+1,srtb+n+1,cmpb);
for(int i=1;i<=n;i++) if(a[srta[i]]!=b[srtb[i]]) return false;
for(int i=1;i<=n;i++) printf("%d ",srta[i]);printf("\n");
for(int i=1;i<=n;i++) printf("%d ",srtb[i]);printf("\n");
return true;
}
long long h[N];
int cnth;
int vis[N],deg[N];
struct E{int v,id;};
vector <E> g[N];
int st[N];
void addedge(long long u,long long v,int id)
{
u=lower_bound(h+1,h+cnth+1,u)-h;
v=lower_bound(h+1,h+cnth+1,v)-h;
// printf("%lld %lld %d\n",u,v,id);
swap(u,v);
g[u].push_back((E){v,id});
deg[u]++;deg[v]--;
}
int res[N],cnt,ans[2][N],cnt0,cnt1;
void dfs(int x)
{
vis[x]=1;
while(st[x]<g[x].size())
{
int v=g[x][st[x]].v,id=g[x][st[x]].id;
st[x]++;
dfs(v);
res[++cnt]=id;
}
}
void clr()
{
for(int i=1;i<=cnth;i++)
{
vis[i]=deg[i]=0;
g[i].clear();st[i]=0;
}
cnt=0;
}
bool chk()
{
for(int i=1;i<=cnth;i++) if(deg[i]) return false;
return true;
}
bool check(int len)
{
// printf("%d:::\n",len);
int now=0;
for(int i=1;i<=n;i++) h[++now]=hsha[i][0][len],h[++now]=hsha[i][1][len+1]+mod;
for(int i=1;i<=n;i++) h[++now]=hshb[i][0][m-len]+mod,h[++now]=hshb[i][1][m-len+1];
sort(h+1,h+now+1);cnth=0;
for(int i=1;i<=now;i++) if(h[i]!=h[cnth]) h[++cnth]=h[i];
for(int i=1;i<=n;i++) addedge(hsha[i][0][len],hsha[i][1][len+1]+mod,i);
for(int i=1;i<=n;i++) addedge(hshb[i][0][m-len]+mod,hshb[i][1][m-len+1],i+n);
if(!chk()){clr();return false;}
for(int i=1;i<=cnth;i++) if(!vis[i]) dfs(i);
cnt0=cnt1=0;
for(int i=1;i<=n*2;i++)
{
if(res[i]<=n) ans[0][++cnt0]=res[i];
else ans[1][++cnt1]=res[i]-n;
}
for(int i=1;i<=n;i++) printf("%d ",ans[0][i]);printf("\n");
for(int i=1;i<=n;i++) printf("%d ",ans[1][i]);printf("\n");
clr();
return true;
}
void init()
{
for(int i=1;i<=n;i++) hsha[i][0].clear(),hshb[i][0].clear();
for(int i=1;i<=n;i++) hsha[i][1].clear(),hshb[i][1].clear();
for(int i=1;i<=n;i++) for(int j=0;j<=m+1;j++) hsha[i][0].push_back(0),hshb[i][0].push_back(0);
for(int i=1;i<=n;i++) for(int j=0;j<=m+1;j++) hsha[i][1].push_back(0),hshb[i][1].push_back(0);
fac[0]=1;
for(int i=1;i<=m;i++) fac[i]=(__int128)fac[i-1]*BASE%mod;
}
int nowT=0;
int main()
{
scanf("%d",&T);
while(T--)
{
scanf("%d%d",&n,&m);
init();
for(int i=1;i<=n;i++)
{
cin>>a[i];
for(int j=1;j<=m;j++) hsha[i][0][j]=(hsha[i][0][j-1]+(__int128)fac[j-1]*(a[i][j-1]-'a'+17))%mod;
for(int j=m;j>=1;j--) hsha[i][1][j]=((__int128)hsha[i][1][j+1]*BASE+(a[i][j-1]-'a'+17))%mod;
// for(int j=1;j<=m;j++) printf("%lld ",hsha[i][0][j]);printf("\n");
// for(int j=1;j<=m;j++) printf("%lld ",hsha[i][1][j]);printf("\n");
}
for(int i=1;i<=n;i++)
{
cin>>b[i];
for(int j=1;j<=m;j++) hshb[i][0][j]=(hshb[i][0][j-1]+(__int128)fac[j-1]*(b[i][j-1]-'a'+17))%mod;
for(int j=m;j>=1;j--) hshb[i][1][j]=((__int128)hshb[i][1][j+1]*BASE+(b[i][j-1]-'a'+17))%mod;
// for(int j=1;j<=m;j++) printf("%lld ",hshb[i][0][j]);printf("\n");
// for(int j=1;j<=m;j++) printf("%lld ",hshb[i][1][j]);printf("\n");
}
if(++nowT==97)
{
printf("%d %d\n",n,m);
for(int i=1;i<=n;i++) cout<<a[i]<<endl;
for(int i=1;i<=n;i++) cout<<b[i]<<endl;
}
if(check0()){init();continue;}
int flg=0;
for(int len=1;len<m;len++) if(check(len)){flg=1;break;}
if(!flg&&!(n==2&&m==2)) printf("-1\n");
}
}
详细
Test #1:
score: 100
Accepted
time: 44ms
memory: 363212kb
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: -100
Wrong Answer
time: 628ms
memory: 364280kb
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:
wrong output format Expected integer, but "b" found (test case 98)