1 条题解

  • 0
    @ 2025-10-8 16:55:41
    #include<bits/stdc++.h>
    using namespace std;
    const int N=1e5+10;
    typedef long  long  LL;
    LL  srow[N],scol[N],sum[N],ave,c[N],T;
    LL  calc(LL a[],int  n)
    {
        LL avg=T/n;
        c[0]=0;for(int i=1;i<=n;i++)c[i]=c[i-1]+(a[i]-avg);
        sort(c+1,c+n+1);
        LL t=c[(n+1)/2],ans=0;
        for(int i=1;i<=n;i++)ans+=abs(t-c[i]);
        return  ans;
    }
    int  main()
    {
        int n,m;scanf("%d%d%lld",&n,&m,&T);
        memset(srow,0,sizeof(srow));
        memset(scol,0,sizeof(scol));
        for(int i=1,x,y;i<=T;i++)
        {
            scanf("%d%d",&x,&y);
            srow[x]++;scol[y]++;
        }
        if(T%n==0)
        {
            if(T%m==0)printf("both %lld\n",calc(srow,n)+calc(scol,m));
            else      printf("row %lld\n",calc(srow,n));
        }
        else  if(T%m==0) printf("column %lld\n",calc(scol,m));
        else  printf("impossible\n");
        return  0;
    }
    
    • 1

    *【中位数进阶】矩阵行列循环均分[七夕祭]

    信息

    ID
    1130
    时间
    1000ms
    内存
    64MiB
    难度
    4
    标签
    递交数
    102
    已通过
    45
    上传者