记录编号 |
444873 |
评测结果 |
AAAAAAAAAA |
题目名称 |
凯伦和游戏 |
最终得分 |
100 |
用户昵称 |
胡嘉兴 |
是否通过 |
通过 |
代码语言 |
C++ |
运行时间 |
0.020 s |
提交时间 |
2017-09-04 15:26:55 |
内存使用 |
0.34 MiB |
显示代码纯文本
#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;
}