QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#27838 | #2617. Browsing the Collection | RobeZH# | WA | 0ms | 4272kb | C++ | 2.1kb | 2022-04-11 01:41:13 | 2022-04-29 07:46:03 |
Judging History
answer
#include<bits/stdc++.h>
#define rep(i,n) for(int i=1;i<=n;++i)
#define pb push_back
#define st first
#define nd second
using namespace std;
typedef pair<int,int> pr;
typedef vector<int> vi;
const int N=500+5,inf=1e9+7;
int n,m,a[6][N];
vi g[N*32];
int d[N*32],q[N*32],l,r;
int ans[N][N];
int main(){
scanf("%d%d",&n,&m);
rep(i,n)rep(j,m)scanf("%d",a[j]+i);
rep(i,n)for(int mk=0;mk<1<<m;++mk){
int now=(i<<m)+mk;
//left
for(int j=i%n+1;j!=i;j=j%n+1){
bool flag=1;
rep(k,m)if((mk&(1<<(k-1)))&&a[k][i]!=a[k][j]){flag=0;break;}
if(flag){
g[(j<<m)+mk].pb(now);
break;
}
}
//right
for(int j=(i+n-2)%n+1;j!=i;j=(j+n-2)%n+1){
bool flag=1;
rep(k,m)if((mk&(1<<(k-1)))&&a[k][i]!=a[k][j]){flag=0;break;}
if(flag){
g[(j<<m)+mk].pb(now);
break;
}
}
//add
rep(k,m)if(mk&(1<<(k-1)))
for(int j=(i+n-2)%n+1;j!=i;j=(j+n-2)%n+1){
bool flag=1;
int mk2=mk-(1<<(k-1));
rep(p,m)if((mk2&(1<<(p-1)))&&a[p][i]!=a[p][j]){flag=0;break;}
if(flag&&a[k][i]==a[k][j]){flag=0;break;}
if(flag){
g[(j<<m)+mk2].pb(now);
}
}
//del
rep(k,m)if(mk&(1<<(k-1)))g[now].pb((i<<m)+mk-(1<<(k-1)));
}
rep(i,n){
rep(j,(n+1)*(1<<m))d[j]=inf;
l=r=0;q[++r]=i<<m;d[i<<m]=0;
while(l<r){
int x=q[++l];
for(int v:g[x]){
//printf("%d %d %d %d\n",x>>m,x&((1<<m)-1),v>>m,v&((1<<m)-1));
if(d[v]==inf)
d[v]=d[x]+1,q[++r]=v;
}
}
rep(j,n) {
ans[i][j] = inf;
for (int mk = 0; mk < 1 << m; ++mk)
ans[i][j] = min(ans[i][j], d[(j << m) + mk]);
}
}
rep(i,n)rep(j,n)printf("%d%c",ans[i][j]," \n"[j==n]);
return 0;
}
/*
9 3
5 3 7
5 3 4
5 3 7
5 3 2
5 3 4
5 3 7
2 3 7
5 3 7
2 3 7
*/
详细
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 4272kb
input:
9 3 5 3 7 5 3 4 5 3 7 5 3 2 5 3 4 5 3 7 2 3 7 5 3 7 2 3 7
output:
0 1 2 1 2 3 1 2 1 1 0 1 1 2 2 1 3 2 2 1 0 1 1 2 1 3 2 3 2 1 0 1 1 1 3 2 3 2 2 1 0 1 1 3 2 3 1 3 1 1 0 1 2 2 2 1 3 1 2 1 0 1 2 2 1 3 1 2 2 1 0 1 1 1 3 1 2 3 2 1 0
result:
wrong answer 48th numbers differ - expected: '2', found: '3'