比赛 树立信心的模拟赛 评测结果 AAAAAAAAAA
题目名称 凯伦和游戏 最终得分 100
用户昵称 胡嘉兴 运行时间 0.010 s
代码语言 C++ 内存使用 0.34 MiB
提交时间 2017-09-01 19:43:15
显示代码纯文本
#include <cstdio>

using namespace std;

#define M 99999999
#define N 117

int map[N][N] = {0}, minr[N] = {0}, minc[N] = {0}, ans = 0, row[N] = {0}, col[N] = {0}, n, m;

int min(int a, int b)
{
	if(a < b)
	{
		return a;
	}
	return b;
}
void F_min()
{
	for(int i = 1; i < N; i++)
	{
		minr[i] = minc[i] = M;
	}
	for(int i = 1; i <= n; i++)
	{
		for(int j = 1; j <= m; j++)
		{
			minr[i] = min(minr[i], map[i][j]);
			minc[j] = min(minc[j], map[i][j]);
		}
	}
	return;
}
void F_row()
{
	for(int i = 1; i <= n; i++)
	{
		for(int j = 1; j <= m; j++)
		{
			map[i][j] -= minr[i];
		}
		row[i] = minr[i];
		ans += minr[i];
	}
	return;
}
void F_col()
{
	for(int j = 1; j <= m; j++)
	{
		for(int i = 1; i <= n; i++)
		{
			map[i][j] -= minc[j];
		}
		col[j] = minc[j];
		ans += minc[j];
	}
	return;
}
int main()
{	
	int flag = 0;
	freopen("games.in", "r", stdin);
	freopen("games.out", "w", stdout);
	
	scanf("%d %d", &n, &m);
	
	for(int i = 1; i <= n; i++)
	{
		for(int j = 1; j <= m; j++)
		{
			
			scanf("%d", &map[i][j]);
			
		}
	}
	if(n <= m)
	{
		F_min();
		F_row();
		F_min();
		F_col();
	}
	else
	{
		F_min();
		F_col();
		F_min();
		F_row();
	}
	for(int i = 1; i <= n; i++)
	{
		for(int j = 1; j <= m; j++)
		{
			if(map[i][j] > 0)
			{
				flag = 1;
			}
		}
	}
	if(flag)
	{
		
		printf("-1\n");
		
	}
	else
	{
	
		printf("%d\n", ans);
		
		for(int i = 1; i <= n; i++)
		{
			for(int j = 1; j <= row[i]; j++)
			{
				
				printf("row %d\n", i);
				
			}
		}
		for(int j = 1; j <= m; j++)
		{
			for(int i = 1; i <= col[j]; i++)
			{
				
				printf("col %d\n", j);
				
			}
		}
	}
	fclose(stdin);
	fclose(stdout);
	return 0;
}