Harry Potter has a difficult homework. Given a rectangular table, consisting of n × m cells. Each cell of the table contains the integer. Harry knows how to use two spells: the first spell change the sign of the integers in the selected row, the second — in the selected column. Harry's task is to make non-negative the sum of the numbers in each row and each column using these spells.

Alone, the boy can not cope. Help the young magician!

Input

The first line contains two integers n and m (1 ≤ n,  m ≤ 100) — the number of rows and the number of columns.

Next n lines follow, each contains m integers: j-th integer in the i-th line is ai, j (|ai, j| ≤ 100), the number in the i-th row and j-th column of the table.

The rows of the table numbered from 1 to n. The columns of the table numbered from 1 to m.

Output

In the first line print the number a — the number of required applications of the first spell. Next print a space-separated integers — the row numbers, you want to apply a spell. These row numbers must be distinct!

In the second line print the number b — the number of required applications of the second spell. Next print b space-separated integers — the column numbers, you want to apply a spell. These column numbers must be distinct!

If there are several solutions are allowed to print any of them.

Examples

Input

Copy
4 1
-1
-1
-1
-1
Output

Copy
4 1 2 3 4 
0
Input

Copy
2 4
-1 -1 -1 2
1 1 1 1
Output

Copy
1 1 
1 4

题目解析

输出有点玄学。

大概意思就是先输出行、列最小交换几次,然后输出交换了哪一行

我的做法是贪心,反复judge每一行、列的和,发现负的就翻转次数++,不停地翻转小于0的行列,总会让每行每列都变得大于0的。

最后,因为翻转两次=不翻转,所以最后要输出次数&1。挺好玩的,神题。

Code

#include<iostream>
#include<cstdio>
using namespace std; int n,m;
int a[][];
int sumx[],sumy[];
int flagx[],flagy[];
int ans1,ans2; inline int judge_x() {
for(int i = ;i <= n;i++) {
if(sumx[i] < ) return i;
}
return ;
} inline int judge_y() {
for(int i = ;i <= m;i++) {
if(sumy[i] < ) return i;
}
return ;
} int main() {
scanf("%d%d",&n,&m);
for(int i = ;i <= n;i++) {
for(int j = ;j <= m;j++) {
scanf("%d",&a[i][j]);
sumx[i] += a[i][j];
sumy[j] += a[i][j];
}
}
while() {
int tmpx = judge_x();
int tmpy = judge_y();
if(!tmpx && !tmpy) break;
if(tmpx) {
flagx[tmpx]++;
sumx[tmpx] = ;
for(int i = ;i <= m;i++) {
int k = -a[tmpx][i];
sumy[i] = sumy[i] - a[tmpx][i] + k;
a[tmpx][i] = k;
sumx[tmpx] += k;
}
} else {
flagy[tmpy]++;
sumy[tmpy] = ;
for(int i = ;i <= n;i++) {
int k = -a[i][tmpy];
sumx[i] = sumx[i] - a[i][tmpy] + k;
a[i][tmpy] = k;
sumy[tmpy] += k;
}
}
}
for(int i = ;i <= n;i++) if(flagx[i] & ) ans1++;
for(int i = ;i <= m;i++) if(flagy[i] & ) ans2++;
printf("%d ",ans1);
for(int i = ;i <= n;i++) {
if(flagx[i] & ) printf("%d ",i);
}
printf("\n%d ",ans2);
for(int i = ;i <= m;i++) {
if(flagy[i] & ) printf("%d ",i);
}
printf("\n");
return ;
}

[CodeForces] CF226D The table的更多相关文章

  1. Codeforces 417E Square Table(随机算法)

    题目链接:Codeforces 417E Square Table 题目大意:给出n和m.要求给出一个矩阵,要求每一列每一行的元素的平方总和是一个平方数. 解题思路:构造.依照 a a a b a a ...

  2. CodeForces 1099E - Nice table - [好题]

    题目链接:https://codeforces.com/problemset/problem/1099/E You are given an $n×m$ table, consisting of ch ...

  3. codeforces 582A. GCD Table 解题报告

    题目链接:http://codeforces.com/problemset/problem/582/A 网上很多题解,就不说了,直接贴代码= = 官方题解: http://codeforces.com ...

  4. codeforces D. Multiplication Table

    http://codeforces.com/contest/448/problem/D 题意:一个n×m的矩阵,a[i][j]=i*j; 然后把a数组排序,找出第k个数. 思路:1-n×m二分枚举,然 ...

  5. Codeforces 22B Bargaining Table

    http://www.codeforces.com/problemset/problem/22/B 题意:求出n*m的方格图中全是0的矩阵的最大周长 思路:枚举 #include<cstdio& ...

  6. Codeforces #662C Binary Table

    听说这是一道$ Tourist$现场没出的题 Codeforces #662C 题意: 给定$n*m的 01$矩阵,可以任意反转一行/列($0$变$1$,$1$变$0$),求最少$ 1$的数量 $ n ...

  7. Codeforces 40E Number Table - 组合数学

    题目传送门 传送门I 传送门II 题目大意 给定一个$n\times m$的网格,每个格子上要么填$1$,要么填$-1$,有$k$个位置上的数是已经填好的,其他位置都是空的.问有多少种填法使得任意一行 ...

  8. Codeforces 233 D - Table

    D - Table 思路:dp 首先,第i列的个数肯定和第i - n列个数一样,假设[i - n + 1, i - 1] 之间的个数之和为x,那么第i列和第i-n列的个数应该是n - x 那么我们可以 ...

  9. 【CODEFORCES】 C. Table Decorations

    C. Table Decorations time limit per test 1 second memory limit per test 256 megabytes input standard ...

随机推荐

  1. automaticallyAdjustsScrollViewInsets 使用

    automaticallyAdjustsScrollViewInsets(个人认为iOS7中略坑爹的属性) @当我们在一个UIViewController中同时创建2个tableView的时候,如果把 ...

  2. LeetCode 249. Group Shifted Strings (群组移位字符串)$

    Given a string, we can "shift" each of its letter to its successive letter, for example: & ...

  3. Android Studio报错:DefaultAndroidProject : Unsupported major.minor version 52.0

    今天使用Android Studio 2.0打开我之前的项目时,编译报了如下错误: Error:Cause: com/android/build/gradle/internal/model/Defau ...

  4. tiny4412学习(三)之移植linux-4.x驱动(1)支持网卡驱动【转】

    本文转载自:http://blog.csdn.net/fengyuwuzu0519/article/details/74160686 一.思路 上一节我们通过DNW将内核.文件系统.设备树文件烧入到内 ...

  5. Linux系统的整体目录结构和文件解析

    Linux系统目录结构 使用 ls / 查看系统的文件目录: /:根目录,根目录下一般只存放子目录,不存放文件.在linux系统中所有的文件都挂载该目录下. /bin:命令目录. 存放系统的可执行的二 ...

  6. [App Store Connect帮助]三、管理 App 和版本(2.4)输入 App 信息:提供加密出口合规证明文稿

    上传至 App Store Connect 的 App 被上传至位于美国的 Apple 服务器.如果您提交 App 的目的是为了在 App Store 上分发您的 App 或通过美国或加拿大的境外 T ...

  7. [App Store Connect帮助]一、 App Store Connect 使用入门(1)App Store Connect 工作流程

    您使用 App Store Connect 提交并管理您在 App Store 中销售的 App,使用 TestFlight 分发您 App 的 Beta 版本,接受法律协议,输入您的税务和银行业务信 ...

  8. 基于ASP.Net Core开发一套通用后台框架记录-(项目的搭建)

    写在前面 本系列博客是本人在学习的过程中搭建学习的记录,如果对你有所帮助那再好不过.如果您有发现错误,请告知我,我会第一时间修改. 前期我不会公开源码,我想是一点点敲代码,不然复制.粘贴那就没意思了. ...

  9. Redis基本属性的使用-详细

    Redis 数据结构简介 Redis 可以存储键与5种不同数据结构类型之间的映射,这5种数据结构类型分别为String(字符串).List(列表).Set(集合).Hash(散列)和 Zset(有序集 ...

  10. ACM_哥德巴赫猜想(素数筛)

    哥德巴赫猜想 Time Limit: 2000/1000ms (Java/Others) Problem Description: 哥德巴赫猜想大概是这么一回事:“偶数(>=4) == 两个质数 ...