exit(0)
查看原帖
exit(0)
636409
Headofstate1945楼主2024/11/20 08:24
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=1e5+5;
int a[N],b[N];
//  行    列
int ca[N],cb[N];
signed main(){
  exit(0);
	ios::sync_with_stdio(0);
	int n,m,t;
	cin>>n>>m>>t;
	for(int i=1,x,y;i<=t;i++){
		cin>>x>>y;
		a[x]++;
		b[y]++;
	}	 
	if(t%n!=0&&t%m!=0)puts("impossible");
	else if(t%n!=0){
		cout<<"column ";
		int aveb=t/m;
		for(int i=1;i<=m;i++){
			cb[i]=cb[i-1]+aveb-b[i-1];
		}
		sort(cb+1,cb+1+m);
		int cbmid=cb[(m+1)/2],ans=0;
		for(int i=1;i<=m;i++){
			ans+=abs(cbmid-cb[i]);
		}
		cout<<ans;
	}
	else if(t%m!=0){
		cout<<"row ";
		int avea=t/n;
		for(int i=1;i<=n;i++){
			ca[i]=ca[i-1]+avea-a[i-1];
		}
		sort(ca+1,ca+1+n);
		int camid=ca[(n+1)/2],ans=0;
		for(int i=1;i<=n;i++){
			ans+=abs(camid-ca[i]);
		}
		cout<<ans;
	}
	else {
		b[-1];
		cout<<"both ";
		int aveb=t/m;
		for(int i=1;i<=m;i++){
			cb[i]=cb[i-1]+aveb-b[i-1];
		}
		sort(cb+1,cb+1+m);
		int cbmid=cb[(m+1)/2],ans=0;
		for(int i=1;i<=m;i++){
			ans+=abs(cbmid-cb[i]);
		}
		int avea=t/n;
		for(int i=1;i<=n;i++){
			ca[i]=ca[i-1]+avea-a[i-1];
		}
		sort(ca+1,ca+1+n);
		int camid=ca[(n+1)/2];
		for(int i=1;i<=n;i++){
			ans+=abs(camid-ca[i]);
		}
		cout<<ans;
	}
	return 0;
}

玄关

2024/11/20 08:24
加载中...