QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#27838#2617. Browsing the CollectionRobeZH#WA 0ms4272kbC++2.1kb2022-04-11 01:41:132022-04-29 07:46:03

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-04-29 07:46:03]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:4272kb
  • [2022-04-11 01:41:13]
  • 提交

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'