比赛 进阶指南第0章测试 评测结果 WWWAWWWEEE
题目名称 七夕祭 最终得分 10
用户昵称 张雨晴 运行时间 0.606 s
代码语言 C++ 内存使用 5.06 MiB
提交时间 2026-03-14 11:24:36
显示代码纯文本
#include<bits/stdc++.h>
using namespace std;
int n,m,t;
int a[1005][1005];
int s1[1005],s2[1005];
int main(){
    freopen("tanabata.in","r",stdin);
    freopen("tanabata.out","w",stdout);
    cin>>n>>m>>t;
    for(int i=1;i<=t;i++){
        int x,y;
        cin>>x>>y;
        a[x][y]++;
    }
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            s1[i]+=a[i][j];
        }
    }
    for(int j=1;j<=m;j++){
        for(int i=1;i<=n;i++){
            s2[j]+=a[i][j];
        }
    }
    int hang=0,lie=0;
    int hangans=0,lieans=0;
    if(t%n==0){
        hang=1;
        int sum=0;
        for(int i=1;i<=n;i++){
            sum+=abs(s1[i]-t/n);
        }
        hangans=sum/2;
    }
    if(t%m==0){
        lie=1;
        int sum=0;
        for(int j=1;j<=m;j++){
            sum+=abs(s2[j]-t/m);
        }
        lieans=sum/2;
    }
    if(hang==1&&lie==1){
        cout<<"both "<<(hangans+lieans);
    }else if(hang==1&&lie==0){
        cout<<"row "<<hangans;
    }else if(hang==0&&lie==1){
        cout<<"column "<<lieans;
    }else{
        cout<<"impossible";
    }
    return 0;
} 
/*
4 4 8
1 2
1 4
2 1
2 3
3 2
3 4
4 2
4 3


*/