-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathout2.txt
263 lines (222 loc) · 6.11 KB
/
out2.txt
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
You are given a matrix of integers $A$ with $N$ rows (numbered $1$ through $N$) and $M$ columns (numbered $1$ through $M$). Each element of this matrix is either $0$ or $1$.
A move consists of the following steps:
- Choose two different rows $r_1$ and $r_2$ or two different columns $c_1$ and $c_2$.
- Apply the bitwise OR operation with the second row/column on the first row/column. Formally, if you chose two rows, this means you should change $A_{r_1, k}$ to $A_{r_1, k} \lor A_{r_2, k}$ for each $1 \le k \le M$; if you chose two columns, then you should change $A_{k, c_1}$ to $A_{k, c_1} \lor A_{k, c_2}$ for each $1 \le k \le N$.
For each element of the matrix, compute the minimum number of moves required to make it equal to $1$ or determine that it is impossible. Note that these answers are independent, i.e. we are starting with the initial matrix for each of them.
-----Input-----
- The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
- The first line of each test case contains two space-separated integers $N$ and $M$.
- $N$ lines follow. For each $i$ ($1 \le i \le N$), the $i$-th of these lines contains $M$ integers $A_{i, 1}, A_{i, 2}, \dots, A_{i, M}$ NOT separated by spaces.
-----Output-----
For each test case, print $N$ lines. For each valid $i$, the $i$-th of these lines should contain $M$ space-separated integers; for each valid $j$, the $j$-th of these integers should be the minimum number of moves required to make $A_{i, j}$ equal to $1$, or $-1$ if it is impossible.
-----Constraints-----
- $1 \le T \le 100$
- $1 \le N, M \le 1,000$
- $A_{i, j} \in \{0, 1\}$ for each valid $i, j$
- the sum of $N \cdot M$ for all test cases does not exceed $1,000,000$
-----Example Input-----
1
3 3
010
000
001
-----Example Output-----
1 0 1
2 1 1
1 1 0
================
def run_code():
t=int(input())
for _ in range(t):
n,m=map(int,input().split())
d={}
e={}
l=[]
for i in range(n):
d[i]=0
for i in range(m):
e[i]=0
for i in range(n):
l.append(input())
for i in range(n):
for j in range(m):
if l[i][j]=='1':
d[i]=1
e[j]=1
#ans=[]
if sum(d.values())+sum(e.values())==0:
k=[-1]*m
for i in range(n):
print(*k)
else:
ans=[]
for i in range(n):
ans.append([0]*m)
for i in range(n):
for j in range(m):
if l[i][j]=='1':
ans[i][j]=0
else:
if (d[i] or e[j]):
ans[i][j]=1
else:
ans[i][j]=2
for i in range(n):
for j in range(m):
print(ans[i][j],end=" ")
print()
run_code()
================
conditional_logic_bug
---------
- from collections import Counter
+ from itertools import groupby
inputs = open(0).readlines()
n = int(inputs[0])
*D, = map(int, inputs[1].split())
+ D.sort()
mod = 998244353
nbs = [0] * (max(D)+1)
- for k, v in Counter(D).items():
- nbs[k] = v
+ for k, g in groupby(D):
+ nbs[k] = len(list(g))
+ if nbs[0] == 1 and 0 not in nbs:
- if D[0] != 0 or nbs[0] != 1:
- print(0)
- else:
ans = 1
for n0, n1 in zip(nbs, nbs[1:]):
ans = ans * pow(n0, n1, mod) % mod
print(ans)
+ else:
+ print(0)
edge_case_handling_issues
---------
A,B = map(int,input().split())
ans = 0
- if B == 1:
- print(0)
- exit()
for i in range(10**100):
if A+(A-1)*i < B:
ans += 1
else:
ans += 1
break
print(ans)
logic_error_in_loops_and_conditions
---------
n,c=map(int,input().split())
+ pos=[list(map(int,input().split())) for _ in range(n)]
+ if c==2:
- xpos=[]
- ypos=[]
- pos=[]
- for _ in range(n):
- x,y=map(int,input().split())
- xpos.append(x)
- ypos.append(y)
- pos.append([x,y])
- xpos=sorted(xpos)
- ypos=sorted(ypos)
- ans=10**20
+ ans=10**20
? ++
- for i in range(n):
+ for i in range(n):
? ++
+ x1,y1=pos[i]
- for j in range(i+1,n):
+ for j in range(i+1,n):
? ++
+ x2,y2=pos[j]
+ w=abs(x1-x2)
+ h=abs(y1-y2)
+ ans=min(ans,w*h)
+ print(ans)
+ else:
+ ans=10**20
- for k in range(n):
? -- ^
+ for i in range(n):
? ^
+ x1,y1=pos[i]
+ for j in range(i+1,n):
+ x2,y2=pos[j]
- for l in range(k+1,n):
? ^ ^
+ for k in range(j+1,n):
? ^ ^
- lx,rx=xpos[i],xpos[j]
- ly,ry=ypos[k],ypos[l]
+ x3,y3=pos[k]
+ rx1,rx2=min(x1,x2,x3),max(x1,x2,x3)
+ ry1,ry2=min(y1,y2,y3),max(y1,y2,y3)
- cnt=0
? ^
+ cnt=3
? ^
- for tx,ty in pos:
- if lx<=tx<=rx and ly<=ty<=ry:
+ for l in range(n):
+ if l==i or l==j or l==k:
+ continue
+ if rx1<=pos[l][0]<=rx2 and ry1<=pos[l][1]<=ry2:
cnt+=1
if cnt>=c:
- ans=min(ans,(rx-lx)*(ry-ly))
+ w=abs(rx1-rx2)
+ h=abs(ry1-ry2)
+ ans=min(ans,w*h)
- print(ans)
+ print(ans)
? ++
if_statement_logic_errors
---------
a, b = map(int,input().split())
ans = int(1)
for i in range(20):
ans += a-1
if ans < b:
continue
- elif i == 0 and 1 == b:
? ^ ^
+ elif i == 0 and ans >= b:
? ^^^ ^
print(0)
break
else:
print(i+1)
break
incorrect_initialization_and_removal_of_calculation_or_bounds
---------
N = int(input())
A = list(map(int, input().split()))
A.append(0)
- ans = [None] * (N+1)
- ans[0] = abs(0 - A[0])
? ---
+ ans = abs(0 - A[0])
for i in range(N):
- ans[i+1] = abs(A[i] - A[i+1])
? ^^ --- -
+ ans += abs(A[i] - A[i+1])
? ^
- ansS = sum(ans)
-
for i in range(N):
if i == 0:
- tmp = abs(A[1])
+ if A[0] * A[1] >= 0: #同符号
+ print(ans)
+ else:
+ print(ans - 2*abs(A[0]))
else:
- tmp = abs(A[i+1] - A[i-1])
- print(ansS - ans[i] - ans[i+1] + tmp)
+ if (A[i] - A[i-1]) * (A[i+1] - A[i]) >= 0:
+ print(ans)
+ else:
+ print(ans - 2*abs(A[i] - A[i-1]))
+