-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathD.py
41 lines (41 loc) · 1013 Bytes
/
D.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import math
import sys
input = sys.stdin.readline
n, m = map(int, input().split())
a = [[] for _ in range(n)]
for i in range(n):
a[i] = [int(_) for _ in input().split()]
row = []
col = []
rowStat = [1] * n
colStat = [1] * m
while True:
bad = False
for i in range(n):
total = 0
for j in range(m):
total += a[i][j]
if total < 0:
bad = True
rowStat[i] *= -1
for j in range(m):
a[i][j] *= -1
for i in range(m):
total = 0
for j in range(n):
total += a[j][i]
if total < 0:
bad = True
colStat[i] *= -1
for j in range(n):
a[j][i] *= -1
if not bad:
break
for i in range(n):
if rowStat[i] == -1:
row.append(i + 1)
for i in range(m):
if colStat[i] == -1:
col.append(i + 1)
print(len(row), ' '.join(map(str, row)))
print(len(col), ' '.join(map(str, col)))