message stringlengths 2 19.9k | message_type stringclasses 2 values | message_id int64 0 1 | conversation_id int64 322 108k | cluster float64 15 15 | __index_level_0__ int64 644 217k |
|---|---|---|---|---|---|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vitya loves programming and problem solving, but sometimes, to distract himself a little, he plays computer games. Once he found a new interesting game about tanks, and he liked it so much that he went through almost all levels in one day. Remained only the last level, which was too tricky. Then Vitya remembered that he is a programmer, and wrote a program that helped him to pass this difficult level. Try do the same.
The game is organized as follows. There is a long road, two cells wide and n cells long. Some cells have obstacles. You control a tank that occupies one cell. Initially, the tank is located before the start of the road, in a cell with coordinates (0, 1). Your task is to move the tank to the end of the road, to the cell (n + 1, 1) or (n + 1, 2).
<image>
Every second the tank moves one cell to the right: the coordinate x is increased by one. When you press the up or down arrow keys, the tank instantly changes the lane, that is, the y coordinate. When you press the spacebar, the tank shoots, and the nearest obstacle along the lane in which the tank rides is instantly destroyed. In order to load a gun, the tank needs t seconds. Initially, the gun is not loaded, that means, the first shot can be made only after t seconds after the tank starts to move.
If at some point the tank is in the same cell with an obstacle not yet destroyed, it burns out. If you press the arrow exactly at the moment when the tank moves forward, the tank will first move forward, and then change the lane, so it will not be possible to move diagonally.
Your task is to find out whether it is possible to pass the level, and if possible, to find the order of actions the player need to make.
Input
The first line contains four integers n, m1, m2 and t, the length of the field, the number of obstacles in the first lane, the number of obstacles in the second lane and the number of tank steps before reloading, respectively (1 ≤ n ≤ 109; 0 ≤ m1, m2 ≤ n; 0 ≤ m1 + m2 ≤ 106; 1 ≤ t ≤ n).
The next two lines contain a description of the obstacles. The first of these lines contains m1 numbers xi — the obstacle coordinates in the first lane (1 ≤ xi ≤ n; xi < xi + 1). The y coordinate for all these obstacles will be 1.
The second line contains m2 numbers describing the obstacles of the second lane in the same format. The y coordinate of all these obstacles will be 2.
Output
In the first line print «Yes», if it is possible to pass the level, or «No», otherwise.
If it is possible, then in the second line print the number of times the tank moves from one lane to another, and in the next line print the coordinates of the transitions, one number per transition: the coordinate x (0 ≤ x ≤ n + 1). All transition coordinates coordinates must be distinct and should be output in strictly increasing order.The number of transitions should not exceed 2·106. If the tank can pass the level, then it can do it using no more than 2·106 transitions.
In the fourth line print the number of shots that the tank makes during the movement, in the following lines print two numbers, x and y coordinates of the point (1 ≤ x ≤ n, 1 ≤ y ≤ 2), from which the tank fired a shot, the number of shots must not exceed m1 + m2. Shots must be output in the order in which they are fired.
If there are several solutions, output any one.
Examples
Input
6 2 3 2
2 6
3 5 6
Output
Yes
2
0 3
2
2 2
4 1
Input
1 1 1 1
1
1
Output
No
Input
9 5 2 5
1 2 7 8 9
4 6
Output
Yes
4
0 3 5 10
1
5 2
Note
Picture for the first sample test.
<image>
Submitted Solution:
```
def solve():
n, m1, m2, shotSecond = map(int, input().split(" "))
block = []
block.append(input().split(" "))
block.append(input().split(" "))
for i in range(m1):
block[0][i] = int(block[0][i])
for i in range(m2):
block[1][i] = int(block[1][i])
posStatus = 0 # 位置
shotStatus = 0 # 射击
change = []
shot = []
line = 0
win = True
while posStatus < n:
temp = checkStatus(block, posStatus, line)
if temp == 1:
line = (line + 1) % 2
change.append(str(posStatus))
elif temp == 2:
if checkShot(shotSecond, shotStatus):
shotStatus = 0
shot.append("{} {}".format(posStatus, line + 1))
# shot(block[line], posStatus)
for i in range(len(block[line])):
if block[line][i] > posStatus:
block[line].pop(i)
break
else:
win = False
elif temp == 3:
line = (line + 1) % 2
if checkShot(shotSecond, shotStatus):
shotStatus = 0
shot.append("{} {}".format(posStatus, line + 1))
# shot(block[line], posStatus)
for i in range(len(block[line])):
if block[line][i] > posStatus:
block[line].pop(i)
break
else:
win = False
change.append(str(posStatus))
elif temp == 4:
win = False
elif temp == 5:
if checkShot(shotSecond, shotStatus):
shotStatus = 0
shot.append("{} {}".format(posStatus, line + 1))
# shot(block[line], posStatus)
for i in range(len(block[line])):
if block[line][i] > posStatus:
block[line].pop(i)
break
elif temp==6:
line = (line + 1) % 2
if checkShot(shotSecond, shotStatus):
shotStatus = 0
shot.append("{} {}".format(posStatus, line + 1))
# shot(block[line], posStatus)
for i in range(len(block[line])):
if block[line][i] > posStatus:
block[line].pop(i)
break
change.append(str(posStatus))
posStatus += 1
shotStatus += 1
if win:
print("Yes")
print(len(change))
print(" ".join(change))
print(len(shot))
for i in range(len(shot)):
print(shot[i])
else:
print("No")
# 0 不动 1 换行 2 打 3 换行且打 4 die 5 可容错打 6 可容错打
def checkStatus(block, posStatus, line):
another = (line + 1) % 2
if (posStatus + 1) in block[line]:
if posStatus in block[another]:
return 2
elif (posStatus + 1) in block[another]:
if not (posStatus + 2) in block[line]:
return 2
elif not (posStatus + 2) in block[another]:
return 3
else:
return 4
elif not (posStatus + 1) in block[another]:
if (posStatus+2) in block[another]:
return 6
else:
return 1
elif (posStatus + 2) in block[line]:
if not (posStatus + 1) in block[another] and not (posStatus + 2) in block[another]:
if posStatus in block[another]:
return 0
else:
return 1
elif (posStatus + 1) in block[another]:
return 5
else:
return 0
def checkShot(shotSecond, shotStatus):
return shotStatus >= shotSecond
solve()
``` | instruction | 0 | 2,202 | 15 | 4,404 |
No | output | 1 | 2,202 | 15 | 4,405 |
Provide a correct Python 3 solution for this coding contest problem.
A rabbit who came to the fair found that the prize for a game at a store was a carrot cake. The rules for this game are as follows.
There is a grid-like field of vertical h squares x horizontal w squares, and each block has at most one block. Each block is a color represented by one of the uppercase letters ('A'-'Z'). When n or more blocks of the same color are lined up in a straight line vertically or horizontally, those blocks disappear.
Participants can select two adjacent cells next to each other and switch their states to each other. When blocks are exchanged, disappeared, or dropped and there are no blocks in the cell below the cell with the block, this block At this time, it disappears when n or more blocks of the same color are lined up again. However, the disappearance of the blocks does not occur while the falling blocks exist, and occurs at the same time when all the blocks have finished falling.
If you eliminate all the blocks on the field with one operation, this game will be successful and you will get a free gift cake. Rabbit wants to get the cake with one entry fee, can not do it If you don't want to participate. From the state of the field at the beginning of the game, answer if the rabbit should participate in this game.
Input
The first line of input is given h, w, n separated by spaces.
2 ≤ h, w, n ≤ 30
In the following h lines, the state of the field is given in order from the top. Uppercase letters represent blocks, and'.' Represents an empty space. The state of the given field is n or more consecutive blocks of the same color in the vertical or horizontal direction. No, no blocks are in a falling state. There is one or more blocks.
Output
Output "YES" if the rabbit should participate in this game, otherwise output "NO" on one line.
Examples
Input
4 6 3
......
...Y..
...Y..
RRYRYY
Output
YES
Input
4 6 3
......
...Y..
...Y..
RRYRY.
Output
NO | instruction | 0 | 2,422 | 15 | 4,844 |
"Correct Solution:
```
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 998244353
dd = [(0,-1),(1,0),(0,1),(-1,0)]
ddn = [(0,-1),(1,-1),(1,0),(1,1),(0,1),(-1,-1),(-1,0),(-1,1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def main():
rr = []
while True:
h,w,n = LI()
a = [S() for _ in range(h)]
def f(i,j):
if a[i][j] == a[i][j+1]:
return False
b = [[c for c in s] for s in a]
b[i][j],b[i][j+1] = b[i][j+1],b[i][j]
ff = True
while ff:
ff = False
for i in range(h-2,-1,-1):
for j in range(w):
if b[i][j] == '.':
continue
for k in range(i,h-1):
if b[k+1][j] == '.':
b[k+1][j],b[k][j] = b[k][j],b[k+1][j]
else:
break
t = [[None]*w for _ in range(h)]
for i in range(h):
for j in range(w):
if b[i][j] == '.':
continue
tf = True
for k in range(1,n):
if i+k >= h or b[i+k][j] != b[i][j]:
tf = False
break
if tf:
for k in range(n):
t[i+k][j] = 1
tf = True
for k in range(1,n):
if j+k >= w or b[i][j+k] != b[i][j]:
tf = False
break
if tf:
for k in range(n):
t[i][j+k] = 1
for i in range(h):
for j in range(w):
if t[i][j] is None:
continue
b[i][j] = '.'
ff = True
for i in range(h):
for j in range(w):
if b[i][j] != '.':
return False
return True
r = 'NO'
for i in range(h):
for j in range(w-1):
if f(i,j):
r = 'YES'
break
rr.append(r)
break
return '\n'.join(map(str, rr))
print(main())
``` | output | 1 | 2,422 | 15 | 4,845 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given n chips on a number line. The i-th chip is placed at the integer coordinate x_i. Some chips can have equal coordinates.
You can perform each of the two following types of moves any (possibly, zero) number of times on any chip:
* Move the chip i by 2 to the left or 2 to the right for free (i.e. replace the current coordinate x_i with x_i - 2 or with x_i + 2);
* move the chip i by 1 to the left or 1 to the right and pay one coin for this move (i.e. replace the current coordinate x_i with x_i - 1 or with x_i + 1).
Note that it's allowed to move chips to any integer coordinate, including negative and zero.
Your task is to find the minimum total number of coins required to move all n chips to the same coordinate (i.e. all x_i should be equal after some sequence of moves).
Input
The first line of the input contains one integer n (1 ≤ n ≤ 100) — the number of chips.
The second line of the input contains n integers x_1, x_2, ..., x_n (1 ≤ x_i ≤ 10^9), where x_i is the coordinate of the i-th chip.
Output
Print one integer — the minimum total number of coins required to move all n chips to the same coordinate.
Examples
Input
3
1 2 3
Output
1
Input
5
2 2 2 3 3
Output
2
Note
In the first example you need to move the first chip by 2 to the right and the second chip by 1 to the right or move the third chip by 2 to the left and the second chip by 1 to the left so the answer is 1.
In the second example you need to move two chips with coordinate 3 by 1 to the left so the answer is 2. | instruction | 0 | 2,544 | 15 | 5,088 |
Tags: math
Correct Solution:
```
n = int(input())
xs = [int(elem) for elem in input().split()]
even = 0
odd = 0
for i in range(n):
if xs[i] % 2 == 1:
odd += 1
else:
even += 1
ans = min(even, odd)
print(ans)
``` | output | 1 | 2,544 | 15 | 5,089 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given n chips on a number line. The i-th chip is placed at the integer coordinate x_i. Some chips can have equal coordinates.
You can perform each of the two following types of moves any (possibly, zero) number of times on any chip:
* Move the chip i by 2 to the left or 2 to the right for free (i.e. replace the current coordinate x_i with x_i - 2 or with x_i + 2);
* move the chip i by 1 to the left or 1 to the right and pay one coin for this move (i.e. replace the current coordinate x_i with x_i - 1 or with x_i + 1).
Note that it's allowed to move chips to any integer coordinate, including negative and zero.
Your task is to find the minimum total number of coins required to move all n chips to the same coordinate (i.e. all x_i should be equal after some sequence of moves).
Input
The first line of the input contains one integer n (1 ≤ n ≤ 100) — the number of chips.
The second line of the input contains n integers x_1, x_2, ..., x_n (1 ≤ x_i ≤ 10^9), where x_i is the coordinate of the i-th chip.
Output
Print one integer — the minimum total number of coins required to move all n chips to the same coordinate.
Examples
Input
3
1 2 3
Output
1
Input
5
2 2 2 3 3
Output
2
Note
In the first example you need to move the first chip by 2 to the right and the second chip by 1 to the right or move the third chip by 2 to the left and the second chip by 1 to the left so the answer is 1.
In the second example you need to move two chips with coordinate 3 by 1 to the left so the answer is 2. | instruction | 0 | 2,545 | 15 | 5,090 |
Tags: math
Correct Solution:
```
print([min(sum(a), n - sum(a)) for n, a in [[int(input()), [int(q) % 2 for q in input().split()]]]][0])
``` | output | 1 | 2,545 | 15 | 5,091 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given n chips on a number line. The i-th chip is placed at the integer coordinate x_i. Some chips can have equal coordinates.
You can perform each of the two following types of moves any (possibly, zero) number of times on any chip:
* Move the chip i by 2 to the left or 2 to the right for free (i.e. replace the current coordinate x_i with x_i - 2 or with x_i + 2);
* move the chip i by 1 to the left or 1 to the right and pay one coin for this move (i.e. replace the current coordinate x_i with x_i - 1 or with x_i + 1).
Note that it's allowed to move chips to any integer coordinate, including negative and zero.
Your task is to find the minimum total number of coins required to move all n chips to the same coordinate (i.e. all x_i should be equal after some sequence of moves).
Input
The first line of the input contains one integer n (1 ≤ n ≤ 100) — the number of chips.
The second line of the input contains n integers x_1, x_2, ..., x_n (1 ≤ x_i ≤ 10^9), where x_i is the coordinate of the i-th chip.
Output
Print one integer — the minimum total number of coins required to move all n chips to the same coordinate.
Examples
Input
3
1 2 3
Output
1
Input
5
2 2 2 3 3
Output
2
Note
In the first example you need to move the first chip by 2 to the right and the second chip by 1 to the right or move the third chip by 2 to the left and the second chip by 1 to the left so the answer is 1.
In the second example you need to move two chips with coordinate 3 by 1 to the left so the answer is 2. | instruction | 0 | 2,546 | 15 | 5,092 |
Tags: math
Correct Solution:
```
n=int(input())
l=list(map(int,input().split()))
coev=0
for i in range(n):
if l[i]%2==0:
coev+=1
print(min(coev,n-coev))
``` | output | 1 | 2,546 | 15 | 5,093 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given n chips on a number line. The i-th chip is placed at the integer coordinate x_i. Some chips can have equal coordinates.
You can perform each of the two following types of moves any (possibly, zero) number of times on any chip:
* Move the chip i by 2 to the left or 2 to the right for free (i.e. replace the current coordinate x_i with x_i - 2 or with x_i + 2);
* move the chip i by 1 to the left or 1 to the right and pay one coin for this move (i.e. replace the current coordinate x_i with x_i - 1 or with x_i + 1).
Note that it's allowed to move chips to any integer coordinate, including negative and zero.
Your task is to find the minimum total number of coins required to move all n chips to the same coordinate (i.e. all x_i should be equal after some sequence of moves).
Input
The first line of the input contains one integer n (1 ≤ n ≤ 100) — the number of chips.
The second line of the input contains n integers x_1, x_2, ..., x_n (1 ≤ x_i ≤ 10^9), where x_i is the coordinate of the i-th chip.
Output
Print one integer — the minimum total number of coins required to move all n chips to the same coordinate.
Examples
Input
3
1 2 3
Output
1
Input
5
2 2 2 3 3
Output
2
Note
In the first example you need to move the first chip by 2 to the right and the second chip by 1 to the right or move the third chip by 2 to the left and the second chip by 1 to the left so the answer is 1.
In the second example you need to move two chips with coordinate 3 by 1 to the left so the answer is 2. | instruction | 0 | 2,547 | 15 | 5,094 |
Tags: math
Correct Solution:
```
def readInts():
return [int(x) for x in input().split()]
N = int(input())
xs = readInts()
num_odd = 0
num_even = 0
for x in xs:
if x % 2 == 0:
num_even += 1
else:
num_odd += 1
print(min(num_odd, num_even))
``` | output | 1 | 2,547 | 15 | 5,095 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given n chips on a number line. The i-th chip is placed at the integer coordinate x_i. Some chips can have equal coordinates.
You can perform each of the two following types of moves any (possibly, zero) number of times on any chip:
* Move the chip i by 2 to the left or 2 to the right for free (i.e. replace the current coordinate x_i with x_i - 2 or with x_i + 2);
* move the chip i by 1 to the left or 1 to the right and pay one coin for this move (i.e. replace the current coordinate x_i with x_i - 1 or with x_i + 1).
Note that it's allowed to move chips to any integer coordinate, including negative and zero.
Your task is to find the minimum total number of coins required to move all n chips to the same coordinate (i.e. all x_i should be equal after some sequence of moves).
Input
The first line of the input contains one integer n (1 ≤ n ≤ 100) — the number of chips.
The second line of the input contains n integers x_1, x_2, ..., x_n (1 ≤ x_i ≤ 10^9), where x_i is the coordinate of the i-th chip.
Output
Print one integer — the minimum total number of coins required to move all n chips to the same coordinate.
Examples
Input
3
1 2 3
Output
1
Input
5
2 2 2 3 3
Output
2
Note
In the first example you need to move the first chip by 2 to the right and the second chip by 1 to the right or move the third chip by 2 to the left and the second chip by 1 to the left so the answer is 1.
In the second example you need to move two chips with coordinate 3 by 1 to the left so the answer is 2. | instruction | 0 | 2,548 | 15 | 5,096 |
Tags: math
Correct Solution:
```
n = int(input())
cordinate = input().split()
odd = 0
even = 0
for i in cordinate:
a = int(i)
if (a%2==1):
odd+=1
else:
even+=1
if (odd<even):
print(odd)
else:
print(even)
``` | output | 1 | 2,548 | 15 | 5,097 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given n chips on a number line. The i-th chip is placed at the integer coordinate x_i. Some chips can have equal coordinates.
You can perform each of the two following types of moves any (possibly, zero) number of times on any chip:
* Move the chip i by 2 to the left or 2 to the right for free (i.e. replace the current coordinate x_i with x_i - 2 or with x_i + 2);
* move the chip i by 1 to the left or 1 to the right and pay one coin for this move (i.e. replace the current coordinate x_i with x_i - 1 or with x_i + 1).
Note that it's allowed to move chips to any integer coordinate, including negative and zero.
Your task is to find the minimum total number of coins required to move all n chips to the same coordinate (i.e. all x_i should be equal after some sequence of moves).
Input
The first line of the input contains one integer n (1 ≤ n ≤ 100) — the number of chips.
The second line of the input contains n integers x_1, x_2, ..., x_n (1 ≤ x_i ≤ 10^9), where x_i is the coordinate of the i-th chip.
Output
Print one integer — the minimum total number of coins required to move all n chips to the same coordinate.
Examples
Input
3
1 2 3
Output
1
Input
5
2 2 2 3 3
Output
2
Note
In the first example you need to move the first chip by 2 to the right and the second chip by 1 to the right or move the third chip by 2 to the left and the second chip by 1 to the left so the answer is 1.
In the second example you need to move two chips with coordinate 3 by 1 to the left so the answer is 2. | instruction | 0 | 2,549 | 15 | 5,098 |
Tags: math
Correct Solution:
```
n = int( input())
l = list(map(int, input().split()))
f = 9e9
for i in set(l):
c = 0
for j in l:
c += (j-i)%2
f = min(c,f)
print(f)
``` | output | 1 | 2,549 | 15 | 5,099 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given n chips on a number line. The i-th chip is placed at the integer coordinate x_i. Some chips can have equal coordinates.
You can perform each of the two following types of moves any (possibly, zero) number of times on any chip:
* Move the chip i by 2 to the left or 2 to the right for free (i.e. replace the current coordinate x_i with x_i - 2 or with x_i + 2);
* move the chip i by 1 to the left or 1 to the right and pay one coin for this move (i.e. replace the current coordinate x_i with x_i - 1 or with x_i + 1).
Note that it's allowed to move chips to any integer coordinate, including negative and zero.
Your task is to find the minimum total number of coins required to move all n chips to the same coordinate (i.e. all x_i should be equal after some sequence of moves).
Input
The first line of the input contains one integer n (1 ≤ n ≤ 100) — the number of chips.
The second line of the input contains n integers x_1, x_2, ..., x_n (1 ≤ x_i ≤ 10^9), where x_i is the coordinate of the i-th chip.
Output
Print one integer — the minimum total number of coins required to move all n chips to the same coordinate.
Examples
Input
3
1 2 3
Output
1
Input
5
2 2 2 3 3
Output
2
Note
In the first example you need to move the first chip by 2 to the right and the second chip by 1 to the right or move the third chip by 2 to the left and the second chip by 1 to the left so the answer is 1.
In the second example you need to move two chips with coordinate 3 by 1 to the left so the answer is 2. | instruction | 0 | 2,550 | 15 | 5,100 |
Tags: math
Correct Solution:
```
n = int(input())
a = [int(x) for x in input().split()]
noch = 0
for i in a:
noch += i % 2
if noch < n - noch:
print(noch)
else:
print(n - noch)
``` | output | 1 | 2,550 | 15 | 5,101 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given n chips on a number line. The i-th chip is placed at the integer coordinate x_i. Some chips can have equal coordinates.
You can perform each of the two following types of moves any (possibly, zero) number of times on any chip:
* Move the chip i by 2 to the left or 2 to the right for free (i.e. replace the current coordinate x_i with x_i - 2 or with x_i + 2);
* move the chip i by 1 to the left or 1 to the right and pay one coin for this move (i.e. replace the current coordinate x_i with x_i - 1 or with x_i + 1).
Note that it's allowed to move chips to any integer coordinate, including negative and zero.
Your task is to find the minimum total number of coins required to move all n chips to the same coordinate (i.e. all x_i should be equal after some sequence of moves).
Input
The first line of the input contains one integer n (1 ≤ n ≤ 100) — the number of chips.
The second line of the input contains n integers x_1, x_2, ..., x_n (1 ≤ x_i ≤ 10^9), where x_i is the coordinate of the i-th chip.
Output
Print one integer — the minimum total number of coins required to move all n chips to the same coordinate.
Examples
Input
3
1 2 3
Output
1
Input
5
2 2 2 3 3
Output
2
Note
In the first example you need to move the first chip by 2 to the right and the second chip by 1 to the right or move the third chip by 2 to the left and the second chip by 1 to the left so the answer is 1.
In the second example you need to move two chips with coordinate 3 by 1 to the left so the answer is 2. | instruction | 0 | 2,551 | 15 | 5,102 |
Tags: math
Correct Solution:
```
n=int(input())
a=[int(x) for x in input().split()]
c=0
for i in a:
if(i%2!=0):
c+=1
print(min(c,n-c))
``` | output | 1 | 2,551 | 15 | 5,103 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given n chips on a number line. The i-th chip is placed at the integer coordinate x_i. Some chips can have equal coordinates.
You can perform each of the two following types of moves any (possibly, zero) number of times on any chip:
* Move the chip i by 2 to the left or 2 to the right for free (i.e. replace the current coordinate x_i with x_i - 2 or with x_i + 2);
* move the chip i by 1 to the left or 1 to the right and pay one coin for this move (i.e. replace the current coordinate x_i with x_i - 1 or with x_i + 1).
Note that it's allowed to move chips to any integer coordinate, including negative and zero.
Your task is to find the minimum total number of coins required to move all n chips to the same coordinate (i.e. all x_i should be equal after some sequence of moves).
Input
The first line of the input contains one integer n (1 ≤ n ≤ 100) — the number of chips.
The second line of the input contains n integers x_1, x_2, ..., x_n (1 ≤ x_i ≤ 10^9), where x_i is the coordinate of the i-th chip.
Output
Print one integer — the minimum total number of coins required to move all n chips to the same coordinate.
Examples
Input
3
1 2 3
Output
1
Input
5
2 2 2 3 3
Output
2
Note
In the first example you need to move the first chip by 2 to the right and the second chip by 1 to the right or move the third chip by 2 to the left and the second chip by 1 to the left so the answer is 1.
In the second example you need to move two chips with coordinate 3 by 1 to the left so the answer is 2.
Submitted Solution:
```
#!/usr/bin/env python3.7
n = int(input())
vals = [0, 0]
for num in map(int, input().split()):
vals[num % 2] += 1
print(min(vals))
``` | instruction | 0 | 2,552 | 15 | 5,104 |
Yes | output | 1 | 2,552 | 15 | 5,105 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given n chips on a number line. The i-th chip is placed at the integer coordinate x_i. Some chips can have equal coordinates.
You can perform each of the two following types of moves any (possibly, zero) number of times on any chip:
* Move the chip i by 2 to the left or 2 to the right for free (i.e. replace the current coordinate x_i with x_i - 2 or with x_i + 2);
* move the chip i by 1 to the left or 1 to the right and pay one coin for this move (i.e. replace the current coordinate x_i with x_i - 1 or with x_i + 1).
Note that it's allowed to move chips to any integer coordinate, including negative and zero.
Your task is to find the minimum total number of coins required to move all n chips to the same coordinate (i.e. all x_i should be equal after some sequence of moves).
Input
The first line of the input contains one integer n (1 ≤ n ≤ 100) — the number of chips.
The second line of the input contains n integers x_1, x_2, ..., x_n (1 ≤ x_i ≤ 10^9), where x_i is the coordinate of the i-th chip.
Output
Print one integer — the minimum total number of coins required to move all n chips to the same coordinate.
Examples
Input
3
1 2 3
Output
1
Input
5
2 2 2 3 3
Output
2
Note
In the first example you need to move the first chip by 2 to the right and the second chip by 1 to the right or move the third chip by 2 to the left and the second chip by 1 to the left so the answer is 1.
In the second example you need to move two chips with coordinate 3 by 1 to the left so the answer is 2.
Submitted Solution:
```
n = int(input())
l = list(map(int,input().split()))
e,o = 0,0
for i in l:
if i%2==0:
e+=1
else:
o+=1
if e>=o:
print(o)
else:
print(e)
``` | instruction | 0 | 2,553 | 15 | 5,106 |
Yes | output | 1 | 2,553 | 15 | 5,107 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given n chips on a number line. The i-th chip is placed at the integer coordinate x_i. Some chips can have equal coordinates.
You can perform each of the two following types of moves any (possibly, zero) number of times on any chip:
* Move the chip i by 2 to the left or 2 to the right for free (i.e. replace the current coordinate x_i with x_i - 2 or with x_i + 2);
* move the chip i by 1 to the left or 1 to the right and pay one coin for this move (i.e. replace the current coordinate x_i with x_i - 1 or with x_i + 1).
Note that it's allowed to move chips to any integer coordinate, including negative and zero.
Your task is to find the minimum total number of coins required to move all n chips to the same coordinate (i.e. all x_i should be equal after some sequence of moves).
Input
The first line of the input contains one integer n (1 ≤ n ≤ 100) — the number of chips.
The second line of the input contains n integers x_1, x_2, ..., x_n (1 ≤ x_i ≤ 10^9), where x_i is the coordinate of the i-th chip.
Output
Print one integer — the minimum total number of coins required to move all n chips to the same coordinate.
Examples
Input
3
1 2 3
Output
1
Input
5
2 2 2 3 3
Output
2
Note
In the first example you need to move the first chip by 2 to the right and the second chip by 1 to the right or move the third chip by 2 to the left and the second chip by 1 to the left so the answer is 1.
In the second example you need to move two chips with coordinate 3 by 1 to the left so the answer is 2.
Submitted Solution:
```
n = int(input())
l = list([int(x) for x in input().split()])
o = 0
e = 0
for i in range(n):
if(l[i] % 2 == 0):
e += 1
else:
o += 1
print(min(o, e))
``` | instruction | 0 | 2,554 | 15 | 5,108 |
Yes | output | 1 | 2,554 | 15 | 5,109 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given n chips on a number line. The i-th chip is placed at the integer coordinate x_i. Some chips can have equal coordinates.
You can perform each of the two following types of moves any (possibly, zero) number of times on any chip:
* Move the chip i by 2 to the left or 2 to the right for free (i.e. replace the current coordinate x_i with x_i - 2 or with x_i + 2);
* move the chip i by 1 to the left or 1 to the right and pay one coin for this move (i.e. replace the current coordinate x_i with x_i - 1 or with x_i + 1).
Note that it's allowed to move chips to any integer coordinate, including negative and zero.
Your task is to find the minimum total number of coins required to move all n chips to the same coordinate (i.e. all x_i should be equal after some sequence of moves).
Input
The first line of the input contains one integer n (1 ≤ n ≤ 100) — the number of chips.
The second line of the input contains n integers x_1, x_2, ..., x_n (1 ≤ x_i ≤ 10^9), where x_i is the coordinate of the i-th chip.
Output
Print one integer — the minimum total number of coins required to move all n chips to the same coordinate.
Examples
Input
3
1 2 3
Output
1
Input
5
2 2 2 3 3
Output
2
Note
In the first example you need to move the first chip by 2 to the right and the second chip by 1 to the right or move the third chip by 2 to the left and the second chip by 1 to the left so the answer is 1.
In the second example you need to move two chips with coordinate 3 by 1 to the left so the answer is 2.
Submitted Solution:
```
# import sys
# sys.stdin = open("test.in","r")
# sys.stdout = open("test.out","w")
n=int(input())
a=list(map(int,input().split()))
b=min(a)
c=0
for i in range(n):
if abs(a[i]-b)%2!=0:
c+=1
print(min(c,n-c))
``` | instruction | 0 | 2,555 | 15 | 5,110 |
Yes | output | 1 | 2,555 | 15 | 5,111 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given n chips on a number line. The i-th chip is placed at the integer coordinate x_i. Some chips can have equal coordinates.
You can perform each of the two following types of moves any (possibly, zero) number of times on any chip:
* Move the chip i by 2 to the left or 2 to the right for free (i.e. replace the current coordinate x_i with x_i - 2 or with x_i + 2);
* move the chip i by 1 to the left or 1 to the right and pay one coin for this move (i.e. replace the current coordinate x_i with x_i - 1 or with x_i + 1).
Note that it's allowed to move chips to any integer coordinate, including negative and zero.
Your task is to find the minimum total number of coins required to move all n chips to the same coordinate (i.e. all x_i should be equal after some sequence of moves).
Input
The first line of the input contains one integer n (1 ≤ n ≤ 100) — the number of chips.
The second line of the input contains n integers x_1, x_2, ..., x_n (1 ≤ x_i ≤ 10^9), where x_i is the coordinate of the i-th chip.
Output
Print one integer — the minimum total number of coins required to move all n chips to the same coordinate.
Examples
Input
3
1 2 3
Output
1
Input
5
2 2 2 3 3
Output
2
Note
In the first example you need to move the first chip by 2 to the right and the second chip by 1 to the right or move the third chip by 2 to the left and the second chip by 1 to the left so the answer is 1.
In the second example you need to move two chips with coordinate 3 by 1 to the left so the answer is 2.
Submitted Solution:
```
#l = [2,2,2,3,3]
n=int(input())
l=list(map(int,input().split()))
c=0
def most_frequent(l):
return max(set(l), key = l.count)
x=most_frequent(l)
#print(x)
for i in l :
if i != x :
#print(i)
if abs(i-x)>=2 :
i=i-2
else :
i=i-1
c+=1
print(c)
``` | instruction | 0 | 2,556 | 15 | 5,112 |
No | output | 1 | 2,556 | 15 | 5,113 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given n chips on a number line. The i-th chip is placed at the integer coordinate x_i. Some chips can have equal coordinates.
You can perform each of the two following types of moves any (possibly, zero) number of times on any chip:
* Move the chip i by 2 to the left or 2 to the right for free (i.e. replace the current coordinate x_i with x_i - 2 or with x_i + 2);
* move the chip i by 1 to the left or 1 to the right and pay one coin for this move (i.e. replace the current coordinate x_i with x_i - 1 or with x_i + 1).
Note that it's allowed to move chips to any integer coordinate, including negative and zero.
Your task is to find the minimum total number of coins required to move all n chips to the same coordinate (i.e. all x_i should be equal after some sequence of moves).
Input
The first line of the input contains one integer n (1 ≤ n ≤ 100) — the number of chips.
The second line of the input contains n integers x_1, x_2, ..., x_n (1 ≤ x_i ≤ 10^9), where x_i is the coordinate of the i-th chip.
Output
Print one integer — the minimum total number of coins required to move all n chips to the same coordinate.
Examples
Input
3
1 2 3
Output
1
Input
5
2 2 2 3 3
Output
2
Note
In the first example you need to move the first chip by 2 to the right and the second chip by 1 to the right or move the third chip by 2 to the left and the second chip by 1 to the left so the answer is 1.
In the second example you need to move two chips with coordinate 3 by 1 to the left so the answer is 2.
Submitted Solution:
```
n=int(input())
m=list(map(int,input().split()))
m.sort()
avg=(m[0]+m[-1])//2
z=0
if m==[1,2,3]:
print(1)
exit()
for i in m:
if (abs(i-avg))%2==1:
z=z+1;
print(z)
``` | instruction | 0 | 2,557 | 15 | 5,114 |
No | output | 1 | 2,557 | 15 | 5,115 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given n chips on a number line. The i-th chip is placed at the integer coordinate x_i. Some chips can have equal coordinates.
You can perform each of the two following types of moves any (possibly, zero) number of times on any chip:
* Move the chip i by 2 to the left or 2 to the right for free (i.e. replace the current coordinate x_i with x_i - 2 or with x_i + 2);
* move the chip i by 1 to the left or 1 to the right and pay one coin for this move (i.e. replace the current coordinate x_i with x_i - 1 or with x_i + 1).
Note that it's allowed to move chips to any integer coordinate, including negative and zero.
Your task is to find the minimum total number of coins required to move all n chips to the same coordinate (i.e. all x_i should be equal after some sequence of moves).
Input
The first line of the input contains one integer n (1 ≤ n ≤ 100) — the number of chips.
The second line of the input contains n integers x_1, x_2, ..., x_n (1 ≤ x_i ≤ 10^9), where x_i is the coordinate of the i-th chip.
Output
Print one integer — the minimum total number of coins required to move all n chips to the same coordinate.
Examples
Input
3
1 2 3
Output
1
Input
5
2 2 2 3 3
Output
2
Note
In the first example you need to move the first chip by 2 to the right and the second chip by 1 to the right or move the third chip by 2 to the left and the second chip by 1 to the left so the answer is 1.
In the second example you need to move two chips with coordinate 3 by 1 to the left so the answer is 2.
Submitted Solution:
```
n=int(input())
a=list(map(int,input().split()))
c=[]
for i in range(n):
z=a[i]
y=[]
for j in range(n):
x=abs(z-a[j])
y.append(x)
c.append(y)
d=[]
for i in range(len(c)):
d.append(c[i].count(1))
print(min(d))
``` | instruction | 0 | 2,558 | 15 | 5,116 |
No | output | 1 | 2,558 | 15 | 5,117 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given n chips on a number line. The i-th chip is placed at the integer coordinate x_i. Some chips can have equal coordinates.
You can perform each of the two following types of moves any (possibly, zero) number of times on any chip:
* Move the chip i by 2 to the left or 2 to the right for free (i.e. replace the current coordinate x_i with x_i - 2 or with x_i + 2);
* move the chip i by 1 to the left or 1 to the right and pay one coin for this move (i.e. replace the current coordinate x_i with x_i - 1 or with x_i + 1).
Note that it's allowed to move chips to any integer coordinate, including negative and zero.
Your task is to find the minimum total number of coins required to move all n chips to the same coordinate (i.e. all x_i should be equal after some sequence of moves).
Input
The first line of the input contains one integer n (1 ≤ n ≤ 100) — the number of chips.
The second line of the input contains n integers x_1, x_2, ..., x_n (1 ≤ x_i ≤ 10^9), where x_i is the coordinate of the i-th chip.
Output
Print one integer — the minimum total number of coins required to move all n chips to the same coordinate.
Examples
Input
3
1 2 3
Output
1
Input
5
2 2 2 3 3
Output
2
Note
In the first example you need to move the first chip by 2 to the right and the second chip by 1 to the right or move the third chip by 2 to the left and the second chip by 1 to the left so the answer is 1.
In the second example you need to move two chips with coordinate 3 by 1 to the left so the answer is 2.
Submitted Solution:
```
import math
n = int(input())
arr = [int(x) for x in input().split()]
coins = 0
counter = 0
curr_frequency = 0
highest = arr[0]
arr.sort()
for i in arr:
curr_frequency = arr.count(i)
if(curr_frequency> counter):
counter = curr_frequency
highest = i
for i in arr:
if highest % 2 == 0:
if i == highest:
continue
if i%2 != 0:
coins += 1
else:
if i == highest:
continue
if i%2 == 0:
coins += 1
if n == 99:
coins+=1
print (coins)
``` | instruction | 0 | 2,559 | 15 | 5,118 |
No | output | 1 | 2,559 | 15 | 5,119 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Long is a huge fan of CFC (Codeforces Fried Chicken). But the price of CFC is increasing, so he decides to breed the chicken on his own farm.
His farm is presented by a rectangle grid with r rows and c columns. Some of these cells contain rice, others are empty. k chickens are living on his farm. The number of chickens is not greater than the number of cells with rice on the farm.
Long wants to give his chicken playgrounds by assigning these farm cells to his chickens. He would like to satisfy the following requirements:
* Each cell of the farm is assigned to exactly one chicken.
* Each chicken is assigned at least one cell.
* The set of cells assigned to every chicken forms a connected area. More precisely, if two cells (x, y) and (u, v) are assigned to the same chicken, this chicken is able to walk from (x, y) to (u, v) by passing only its cells and moving from each cell to another cell sharing a side.
Long also wants to prevent his chickens from fighting for food. Hence he wants the difference between the maximum and the minimum number of cells with rice assigned to a chicken to be as small as possible. Please help him.
Input
Each test contains multiple test cases. The first line contains the number of test cases T (1 ≤ T ≤ 2 ⋅ 10^4). Description of the test cases follows.
The first line of each test case contains three integers r, c and k (1 ≤ r, c ≤ 100, 1 ≤ k ≤ 62), representing the size of Long's farm and the number of chickens Long has.
Each of the next r lines contains c characters, each is either "." or "R", representing an empty cell or a cell with rice. It is guaranteed that the number of chickens is not greater than the number of cells with rice on the farm.
It is guaranteed that the sum of r ⋅ c over all test cases does not exceed 2 ⋅ 10^4.
Output
For each test case, print r lines with c characters on each line. Each character should be either a lowercase English character, an uppercase English character, or a digit. Two characters should be equal if and only if the two corresponding cells are assigned to the same chicken. Uppercase and lowercase characters are considered different, so "A" and "a" belong to two different chickens.
If there are multiple optimal answers, print any.
Example
Input
4
3 5 3
..R..
...R.
....R
6 4 6
R..R
R..R
RRRR
RRRR
R..R
R..R
5 5 4
RRR..
R.R..
RRR..
R..R.
R...R
2 31 62
RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR
RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR
Output
11122
22223
33333
aacc
aBBc
aBBc
CbbA
CbbA
CCAA
11114
22244
32444
33344
33334
abcdefghijklmnopqrstuvwxyzABCDE
FGHIJKLMNOPQRSTUVWXYZ0123456789
Note
These pictures explain the sample output. Each color represents one chicken. Cells filled with patterns (not solid colors) contain rice.
In the first test case, each chicken has one cell with rice. Hence, the difference between the maximum and the minimum number of cells with rice assigned to a chicken is 0.
<image>
In the second test case, there are 4 chickens with 3 cells of rice, and 2 chickens with 2 cells of rice. Hence, the difference between the maximum and the minimum number of cells with rice assigned to a chicken is 3 - 2 = 1.
<image>
In the third test case, each chicken has 3 cells with rice. <image>
In the last test case, since there are 62 chicken with exactly 62 cells of rice, each chicken must be assigned to exactly one cell. The sample output is one of the possible way. | instruction | 0 | 2,576 | 15 | 5,152 |
Tags: constructive algorithms, greedy, implementation
Correct Solution:
```
mod = 1000000007
eps = 10**-9
def main():
import sys
from string import ascii_letters, digits
input = sys.stdin.readline
SS = ascii_letters + digits
for _ in range(int(input())):
H, W, K = map(int, input().split())
S = SS[:K]
grid = []
for _ in range(H):
grid.append(input().rstrip('\n'))
num_rice = 0
for h in range(H):
for w in range(W):
if grid[h][w] == "R":
num_rice += 1
minor = num_rice // K
major = minor + 1
num_major = num_rice % K
i = 0
cnt = 0
ans = [[""] * W for _ in range(H)]
for h in range(H):
if h&1:
for w in range(W-1, -1, -1):
if grid[h][w] == "R":
cnt += 1
ans[h][w] = S[i]
if i < num_major:
if cnt == major:
cnt = 0
if i != K-1:
i += 1
else:
if cnt == minor:
cnt = 0
if i != K-1:
i += 1
else:
ans[h][w] = S[i]
else:
for w in range(W):
if grid[h][w] == "R":
cnt += 1
ans[h][w] = S[i]
if i < num_major:
if cnt == major:
cnt = 0
if i != K - 1:
i += 1
else:
if cnt == minor:
cnt = 0
if i != K - 1:
i += 1
else:
ans[h][w] = S[i]
for h in range(H):
print("".join(ans[h]))
if __name__ == '__main__':
main()
``` | output | 1 | 2,576 | 15 | 5,153 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Long is a huge fan of CFC (Codeforces Fried Chicken). But the price of CFC is increasing, so he decides to breed the chicken on his own farm.
His farm is presented by a rectangle grid with r rows and c columns. Some of these cells contain rice, others are empty. k chickens are living on his farm. The number of chickens is not greater than the number of cells with rice on the farm.
Long wants to give his chicken playgrounds by assigning these farm cells to his chickens. He would like to satisfy the following requirements:
* Each cell of the farm is assigned to exactly one chicken.
* Each chicken is assigned at least one cell.
* The set of cells assigned to every chicken forms a connected area. More precisely, if two cells (x, y) and (u, v) are assigned to the same chicken, this chicken is able to walk from (x, y) to (u, v) by passing only its cells and moving from each cell to another cell sharing a side.
Long also wants to prevent his chickens from fighting for food. Hence he wants the difference between the maximum and the minimum number of cells with rice assigned to a chicken to be as small as possible. Please help him.
Input
Each test contains multiple test cases. The first line contains the number of test cases T (1 ≤ T ≤ 2 ⋅ 10^4). Description of the test cases follows.
The first line of each test case contains three integers r, c and k (1 ≤ r, c ≤ 100, 1 ≤ k ≤ 62), representing the size of Long's farm and the number of chickens Long has.
Each of the next r lines contains c characters, each is either "." or "R", representing an empty cell or a cell with rice. It is guaranteed that the number of chickens is not greater than the number of cells with rice on the farm.
It is guaranteed that the sum of r ⋅ c over all test cases does not exceed 2 ⋅ 10^4.
Output
For each test case, print r lines with c characters on each line. Each character should be either a lowercase English character, an uppercase English character, or a digit. Two characters should be equal if and only if the two corresponding cells are assigned to the same chicken. Uppercase and lowercase characters are considered different, so "A" and "a" belong to two different chickens.
If there are multiple optimal answers, print any.
Example
Input
4
3 5 3
..R..
...R.
....R
6 4 6
R..R
R..R
RRRR
RRRR
R..R
R..R
5 5 4
RRR..
R.R..
RRR..
R..R.
R...R
2 31 62
RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR
RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR
Output
11122
22223
33333
aacc
aBBc
aBBc
CbbA
CbbA
CCAA
11114
22244
32444
33344
33334
abcdefghijklmnopqrstuvwxyzABCDE
FGHIJKLMNOPQRSTUVWXYZ0123456789
Note
These pictures explain the sample output. Each color represents one chicken. Cells filled with patterns (not solid colors) contain rice.
In the first test case, each chicken has one cell with rice. Hence, the difference between the maximum and the minimum number of cells with rice assigned to a chicken is 0.
<image>
In the second test case, there are 4 chickens with 3 cells of rice, and 2 chickens with 2 cells of rice. Hence, the difference between the maximum and the minimum number of cells with rice assigned to a chicken is 3 - 2 = 1.
<image>
In the third test case, each chicken has 3 cells with rice. <image>
In the last test case, since there are 62 chicken with exactly 62 cells of rice, each chicken must be assigned to exactly one cell. The sample output is one of the possible way. | instruction | 0 | 2,577 | 15 | 5,154 |
Tags: constructive algorithms, greedy, implementation
Correct Solution:
```
#!/usr/bin/python3
import os
import sys
def main():
T = read_int()
for _ in range(T):
R, C, K = read_ints()
A = [inp() for _ in range(R)]
print(*solve(R, C, K, A), sep='\n')
def itoc(i):
if i < 10:
return chr(ord('0') + i)
i -= 10
if i < 26:
return chr(ord('a') + i)
i -= 26
return chr(ord('A') + i)
def solve(R, C, K, A):
ans = [[None] * C for _ in range(R)]
rice = sum([s.count('R') for s in A])
c = rice // K
i = 0
for y in range(R):
for x in range(C) if y % 2 == 0 else range(C - 1, -1, -1):
ans[y][x] = i
if A[y][x] == 'R':
c -= 1
rice -= 1
if c == 0:
K -= 1
if K > 0:
c = rice // K
i += 1
return [''.join([itoc(c) for c in r]) for r in ans]
###############################################################################
DEBUG = 'DEBUG' in os.environ
def inp():
return sys.stdin.readline().rstrip()
def read_int():
return int(inp())
def read_ints():
return [int(e) for e in inp().split()]
def dprint(*value, sep=' ', end='\n'):
if DEBUG:
print(*value, sep=sep, end=end)
if __name__ == '__main__':
main()
``` | output | 1 | 2,577 | 15 | 5,155 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Long is a huge fan of CFC (Codeforces Fried Chicken). But the price of CFC is increasing, so he decides to breed the chicken on his own farm.
His farm is presented by a rectangle grid with r rows and c columns. Some of these cells contain rice, others are empty. k chickens are living on his farm. The number of chickens is not greater than the number of cells with rice on the farm.
Long wants to give his chicken playgrounds by assigning these farm cells to his chickens. He would like to satisfy the following requirements:
* Each cell of the farm is assigned to exactly one chicken.
* Each chicken is assigned at least one cell.
* The set of cells assigned to every chicken forms a connected area. More precisely, if two cells (x, y) and (u, v) are assigned to the same chicken, this chicken is able to walk from (x, y) to (u, v) by passing only its cells and moving from each cell to another cell sharing a side.
Long also wants to prevent his chickens from fighting for food. Hence he wants the difference between the maximum and the minimum number of cells with rice assigned to a chicken to be as small as possible. Please help him.
Input
Each test contains multiple test cases. The first line contains the number of test cases T (1 ≤ T ≤ 2 ⋅ 10^4). Description of the test cases follows.
The first line of each test case contains three integers r, c and k (1 ≤ r, c ≤ 100, 1 ≤ k ≤ 62), representing the size of Long's farm and the number of chickens Long has.
Each of the next r lines contains c characters, each is either "." or "R", representing an empty cell or a cell with rice. It is guaranteed that the number of chickens is not greater than the number of cells with rice on the farm.
It is guaranteed that the sum of r ⋅ c over all test cases does not exceed 2 ⋅ 10^4.
Output
For each test case, print r lines with c characters on each line. Each character should be either a lowercase English character, an uppercase English character, or a digit. Two characters should be equal if and only if the two corresponding cells are assigned to the same chicken. Uppercase and lowercase characters are considered different, so "A" and "a" belong to two different chickens.
If there are multiple optimal answers, print any.
Example
Input
4
3 5 3
..R..
...R.
....R
6 4 6
R..R
R..R
RRRR
RRRR
R..R
R..R
5 5 4
RRR..
R.R..
RRR..
R..R.
R...R
2 31 62
RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR
RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR
Output
11122
22223
33333
aacc
aBBc
aBBc
CbbA
CbbA
CCAA
11114
22244
32444
33344
33334
abcdefghijklmnopqrstuvwxyzABCDE
FGHIJKLMNOPQRSTUVWXYZ0123456789
Note
These pictures explain the sample output. Each color represents one chicken. Cells filled with patterns (not solid colors) contain rice.
In the first test case, each chicken has one cell with rice. Hence, the difference between the maximum and the minimum number of cells with rice assigned to a chicken is 0.
<image>
In the second test case, there are 4 chickens with 3 cells of rice, and 2 chickens with 2 cells of rice. Hence, the difference between the maximum and the minimum number of cells with rice assigned to a chicken is 3 - 2 = 1.
<image>
In the third test case, each chicken has 3 cells with rice. <image>
In the last test case, since there are 62 chicken with exactly 62 cells of rice, each chicken must be assigned to exactly one cell. The sample output is one of the possible way. | instruction | 0 | 2,578 | 15 | 5,156 |
Tags: constructive algorithms, greedy, implementation
Correct Solution:
```
# Legends Always Come Up with Solution
# Author: Manvir Singh
import os
from io import BytesIO, IOBase
import sys
from string import ascii_letters
def solve(a,x,y,ch,ty):
if ty==0:
for j in range(y,len(a[0]),1):
a[x][j]=ch
else:
for j in range(y,-1,-1):
a[x][j]=ch
x+=1
for i in range(x,len(a),1):
for j in range(0,len(a[0]),1):
a[i][j]=ch
def main():
al=list(ascii_letters)+[chr(i+48) for i in range(10)]
for _ in range(int(input())):
r,c,k=map(int,input().split())
a=[list(input().rstrip()) for _ in range(r)]
u,v=divmod(sum(i.count("R") for i in a),k)
z,v,k=u+(v>0),v-1,k-1
for i in range(r):
if i&1:
for j in range(c-1,-1,-1):
a[i][j],z=al[k],z-(a[i][j]=="R")
if z==0:
z,v,k=u+(v>0),v-1,k-1
if k==-1:
solve(a,i,j,al[0],1)
break
else:
for j in range(c):
a[i][j],z=al[k],z-(a[i][j]=="R")
if z==0:
z,v,k=u+(v>0),v-1,k-1
if k==-1:
solve(a,i,j,al[0],0)
break
if k==-1:
break
for i in a:
print("".join(i))
# FAST INPUT OUTPUT REGION
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
if __name__ == "__main__":
main()
``` | output | 1 | 2,578 | 15 | 5,157 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Long is a huge fan of CFC (Codeforces Fried Chicken). But the price of CFC is increasing, so he decides to breed the chicken on his own farm.
His farm is presented by a rectangle grid with r rows and c columns. Some of these cells contain rice, others are empty. k chickens are living on his farm. The number of chickens is not greater than the number of cells with rice on the farm.
Long wants to give his chicken playgrounds by assigning these farm cells to his chickens. He would like to satisfy the following requirements:
* Each cell of the farm is assigned to exactly one chicken.
* Each chicken is assigned at least one cell.
* The set of cells assigned to every chicken forms a connected area. More precisely, if two cells (x, y) and (u, v) are assigned to the same chicken, this chicken is able to walk from (x, y) to (u, v) by passing only its cells and moving from each cell to another cell sharing a side.
Long also wants to prevent his chickens from fighting for food. Hence he wants the difference between the maximum and the minimum number of cells with rice assigned to a chicken to be as small as possible. Please help him.
Input
Each test contains multiple test cases. The first line contains the number of test cases T (1 ≤ T ≤ 2 ⋅ 10^4). Description of the test cases follows.
The first line of each test case contains three integers r, c and k (1 ≤ r, c ≤ 100, 1 ≤ k ≤ 62), representing the size of Long's farm and the number of chickens Long has.
Each of the next r lines contains c characters, each is either "." or "R", representing an empty cell or a cell with rice. It is guaranteed that the number of chickens is not greater than the number of cells with rice on the farm.
It is guaranteed that the sum of r ⋅ c over all test cases does not exceed 2 ⋅ 10^4.
Output
For each test case, print r lines with c characters on each line. Each character should be either a lowercase English character, an uppercase English character, or a digit. Two characters should be equal if and only if the two corresponding cells are assigned to the same chicken. Uppercase and lowercase characters are considered different, so "A" and "a" belong to two different chickens.
If there are multiple optimal answers, print any.
Example
Input
4
3 5 3
..R..
...R.
....R
6 4 6
R..R
R..R
RRRR
RRRR
R..R
R..R
5 5 4
RRR..
R.R..
RRR..
R..R.
R...R
2 31 62
RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR
RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR
Output
11122
22223
33333
aacc
aBBc
aBBc
CbbA
CbbA
CCAA
11114
22244
32444
33344
33334
abcdefghijklmnopqrstuvwxyzABCDE
FGHIJKLMNOPQRSTUVWXYZ0123456789
Note
These pictures explain the sample output. Each color represents one chicken. Cells filled with patterns (not solid colors) contain rice.
In the first test case, each chicken has one cell with rice. Hence, the difference between the maximum and the minimum number of cells with rice assigned to a chicken is 0.
<image>
In the second test case, there are 4 chickens with 3 cells of rice, and 2 chickens with 2 cells of rice. Hence, the difference between the maximum and the minimum number of cells with rice assigned to a chicken is 3 - 2 = 1.
<image>
In the third test case, each chicken has 3 cells with rice. <image>
In the last test case, since there are 62 chicken with exactly 62 cells of rice, each chicken must be assigned to exactly one cell. The sample output is one of the possible way. | instruction | 0 | 2,579 | 15 | 5,158 |
Tags: constructive algorithms, greedy, implementation
Correct Solution:
```
import sys
input = sys.stdin.readline
from collections import deque
t = int(input())
ls = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
def proceed(x,y):
if x%2 == 0 and 0 <= y < c-1:
return(x,y+1)
elif x%2 == 0:
return(x+1,y)
elif 0 < y <= c-1:
return(x,y-1)
else:
return(x+1,y)
for _ in range(t):
r,c,k = map(int,input().split())
cell = [input() for i in range(r)]
nr = 0
pr = []
for i in range(r):
for j in range(c):
if cell[i][j] == "R":
pr.append((i,j))
nr += 1
Q,R = divmod(nr,k)
cnt = 0
cntr = 0
ans = [["" for i in range(c)] for j in range(r)]
x,y = 0,0
for cntr in range(k):
cnt = 0
while (cnt < Q+(cntr<R) or cntr == k-1):
ans[x][y] = ls[cntr]
if cell[x][y] == "R":
cnt += 1
x,y = proceed(x,y)
if x == r:
break
for arr in ans:
print(*arr,sep="")
``` | output | 1 | 2,579 | 15 | 5,159 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Long is a huge fan of CFC (Codeforces Fried Chicken). But the price of CFC is increasing, so he decides to breed the chicken on his own farm.
His farm is presented by a rectangle grid with r rows and c columns. Some of these cells contain rice, others are empty. k chickens are living on his farm. The number of chickens is not greater than the number of cells with rice on the farm.
Long wants to give his chicken playgrounds by assigning these farm cells to his chickens. He would like to satisfy the following requirements:
* Each cell of the farm is assigned to exactly one chicken.
* Each chicken is assigned at least one cell.
* The set of cells assigned to every chicken forms a connected area. More precisely, if two cells (x, y) and (u, v) are assigned to the same chicken, this chicken is able to walk from (x, y) to (u, v) by passing only its cells and moving from each cell to another cell sharing a side.
Long also wants to prevent his chickens from fighting for food. Hence he wants the difference between the maximum and the minimum number of cells with rice assigned to a chicken to be as small as possible. Please help him.
Input
Each test contains multiple test cases. The first line contains the number of test cases T (1 ≤ T ≤ 2 ⋅ 10^4). Description of the test cases follows.
The first line of each test case contains three integers r, c and k (1 ≤ r, c ≤ 100, 1 ≤ k ≤ 62), representing the size of Long's farm and the number of chickens Long has.
Each of the next r lines contains c characters, each is either "." or "R", representing an empty cell or a cell with rice. It is guaranteed that the number of chickens is not greater than the number of cells with rice on the farm.
It is guaranteed that the sum of r ⋅ c over all test cases does not exceed 2 ⋅ 10^4.
Output
For each test case, print r lines with c characters on each line. Each character should be either a lowercase English character, an uppercase English character, or a digit. Two characters should be equal if and only if the two corresponding cells are assigned to the same chicken. Uppercase and lowercase characters are considered different, so "A" and "a" belong to two different chickens.
If there are multiple optimal answers, print any.
Example
Input
4
3 5 3
..R..
...R.
....R
6 4 6
R..R
R..R
RRRR
RRRR
R..R
R..R
5 5 4
RRR..
R.R..
RRR..
R..R.
R...R
2 31 62
RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR
RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR
Output
11122
22223
33333
aacc
aBBc
aBBc
CbbA
CbbA
CCAA
11114
22244
32444
33344
33334
abcdefghijklmnopqrstuvwxyzABCDE
FGHIJKLMNOPQRSTUVWXYZ0123456789
Note
These pictures explain the sample output. Each color represents one chicken. Cells filled with patterns (not solid colors) contain rice.
In the first test case, each chicken has one cell with rice. Hence, the difference between the maximum and the minimum number of cells with rice assigned to a chicken is 0.
<image>
In the second test case, there are 4 chickens with 3 cells of rice, and 2 chickens with 2 cells of rice. Hence, the difference between the maximum and the minimum number of cells with rice assigned to a chicken is 3 - 2 = 1.
<image>
In the third test case, each chicken has 3 cells with rice. <image>
In the last test case, since there are 62 chicken with exactly 62 cells of rice, each chicken must be assigned to exactly one cell. The sample output is one of the possible way. | instruction | 0 | 2,580 | 15 | 5,160 |
Tags: constructive algorithms, greedy, implementation
Correct Solution:
```
import math
n=int(input())
res=[chr(x) for x in range(ord('a'), ord('z') + 1)]
res1=[chr(x) for x in range(ord('A'), ord('Z') + 1)]
res+=res1
res2=[0,1,2,3,4,5,6,7,8,9]
res+=res2
for i in range(n):
r,c,f=map(int,input().split())
s=[]
e=0
for j in range(r):
k=input()
e+=k.count('R')
s.append(k)
w=e%f
e=math.ceil(e/f)
e=int(e)
cou=f
cou1=1
ans=[[-1 for i in range(c)]for j in range(r)]
rw=0
co=0
inc=1
while(cou>1):
#print(cou)
if w!=0 and cou1==w+1:
e-=1
cur=0
while(cur<e):
ans[rw][co]=res[cou1-1]
#print(rw,co)
if s[rw][co]=='R':
cur+=1
co+=inc
if inc==1 and co==c:
rw+=1
co=c-1
inc=-1
elif inc==-1 and co==-1:
rw+=1
co=0
inc=1
cou-=1
cou1+=1
#print(ans)
for jk in range(r):
for ik in range(c):
if ans[jk][ik]==-1:
ans[jk][ik]=res[f-1]
for jk in range(r):
print(*ans[jk],sep="")
``` | output | 1 | 2,580 | 15 | 5,161 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Long is a huge fan of CFC (Codeforces Fried Chicken). But the price of CFC is increasing, so he decides to breed the chicken on his own farm.
His farm is presented by a rectangle grid with r rows and c columns. Some of these cells contain rice, others are empty. k chickens are living on his farm. The number of chickens is not greater than the number of cells with rice on the farm.
Long wants to give his chicken playgrounds by assigning these farm cells to his chickens. He would like to satisfy the following requirements:
* Each cell of the farm is assigned to exactly one chicken.
* Each chicken is assigned at least one cell.
* The set of cells assigned to every chicken forms a connected area. More precisely, if two cells (x, y) and (u, v) are assigned to the same chicken, this chicken is able to walk from (x, y) to (u, v) by passing only its cells and moving from each cell to another cell sharing a side.
Long also wants to prevent his chickens from fighting for food. Hence he wants the difference between the maximum and the minimum number of cells with rice assigned to a chicken to be as small as possible. Please help him.
Input
Each test contains multiple test cases. The first line contains the number of test cases T (1 ≤ T ≤ 2 ⋅ 10^4). Description of the test cases follows.
The first line of each test case contains three integers r, c and k (1 ≤ r, c ≤ 100, 1 ≤ k ≤ 62), representing the size of Long's farm and the number of chickens Long has.
Each of the next r lines contains c characters, each is either "." or "R", representing an empty cell or a cell with rice. It is guaranteed that the number of chickens is not greater than the number of cells with rice on the farm.
It is guaranteed that the sum of r ⋅ c over all test cases does not exceed 2 ⋅ 10^4.
Output
For each test case, print r lines with c characters on each line. Each character should be either a lowercase English character, an uppercase English character, or a digit. Two characters should be equal if and only if the two corresponding cells are assigned to the same chicken. Uppercase and lowercase characters are considered different, so "A" and "a" belong to two different chickens.
If there are multiple optimal answers, print any.
Example
Input
4
3 5 3
..R..
...R.
....R
6 4 6
R..R
R..R
RRRR
RRRR
R..R
R..R
5 5 4
RRR..
R.R..
RRR..
R..R.
R...R
2 31 62
RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR
RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR
Output
11122
22223
33333
aacc
aBBc
aBBc
CbbA
CbbA
CCAA
11114
22244
32444
33344
33334
abcdefghijklmnopqrstuvwxyzABCDE
FGHIJKLMNOPQRSTUVWXYZ0123456789
Note
These pictures explain the sample output. Each color represents one chicken. Cells filled with patterns (not solid colors) contain rice.
In the first test case, each chicken has one cell with rice. Hence, the difference between the maximum and the minimum number of cells with rice assigned to a chicken is 0.
<image>
In the second test case, there are 4 chickens with 3 cells of rice, and 2 chickens with 2 cells of rice. Hence, the difference between the maximum and the minimum number of cells with rice assigned to a chicken is 3 - 2 = 1.
<image>
In the third test case, each chicken has 3 cells with rice. <image>
In the last test case, since there are 62 chicken with exactly 62 cells of rice, each chicken must be assigned to exactly one cell. The sample output is one of the possible way. | instruction | 0 | 2,581 | 15 | 5,162 |
Tags: constructive algorithms, greedy, implementation
Correct Solution:
```
from string import ascii_letters, digits
def snake(n, m):
i = j = 0
d = 1
while i < n:
while 0 <= j < m:
yield i, j
j += d
i += 1
d *= -1
j += d
chickens = ascii_letters + digits
cfield = [[''] * 100 for _ in range(100)]
rfield = [''] * 100
for _ in range(int(input())):
r, c, k = map(int, input().split())
n = 0
for i in range(r):
rfield[i] = input()
n += rfield[i].count('R')
q = n // k
a = n % k
u = 0
v = q + int(u < a)
for i, j in snake(r, c):
cfield[i][j] = chickens[min(u, k - 1)]
if rfield[i][j] == 'R':
v -= 1
if v == 0:
u += 1
v = q + int(u < a)
for i in range(r):
print(*cfield[i][:c], sep='')
``` | output | 1 | 2,581 | 15 | 5,163 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Long is a huge fan of CFC (Codeforces Fried Chicken). But the price of CFC is increasing, so he decides to breed the chicken on his own farm.
His farm is presented by a rectangle grid with r rows and c columns. Some of these cells contain rice, others are empty. k chickens are living on his farm. The number of chickens is not greater than the number of cells with rice on the farm.
Long wants to give his chicken playgrounds by assigning these farm cells to his chickens. He would like to satisfy the following requirements:
* Each cell of the farm is assigned to exactly one chicken.
* Each chicken is assigned at least one cell.
* The set of cells assigned to every chicken forms a connected area. More precisely, if two cells (x, y) and (u, v) are assigned to the same chicken, this chicken is able to walk from (x, y) to (u, v) by passing only its cells and moving from each cell to another cell sharing a side.
Long also wants to prevent his chickens from fighting for food. Hence he wants the difference between the maximum and the minimum number of cells with rice assigned to a chicken to be as small as possible. Please help him.
Input
Each test contains multiple test cases. The first line contains the number of test cases T (1 ≤ T ≤ 2 ⋅ 10^4). Description of the test cases follows.
The first line of each test case contains three integers r, c and k (1 ≤ r, c ≤ 100, 1 ≤ k ≤ 62), representing the size of Long's farm and the number of chickens Long has.
Each of the next r lines contains c characters, each is either "." or "R", representing an empty cell or a cell with rice. It is guaranteed that the number of chickens is not greater than the number of cells with rice on the farm.
It is guaranteed that the sum of r ⋅ c over all test cases does not exceed 2 ⋅ 10^4.
Output
For each test case, print r lines with c characters on each line. Each character should be either a lowercase English character, an uppercase English character, or a digit. Two characters should be equal if and only if the two corresponding cells are assigned to the same chicken. Uppercase and lowercase characters are considered different, so "A" and "a" belong to two different chickens.
If there are multiple optimal answers, print any.
Example
Input
4
3 5 3
..R..
...R.
....R
6 4 6
R..R
R..R
RRRR
RRRR
R..R
R..R
5 5 4
RRR..
R.R..
RRR..
R..R.
R...R
2 31 62
RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR
RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR
Output
11122
22223
33333
aacc
aBBc
aBBc
CbbA
CbbA
CCAA
11114
22244
32444
33344
33334
abcdefghijklmnopqrstuvwxyzABCDE
FGHIJKLMNOPQRSTUVWXYZ0123456789
Note
These pictures explain the sample output. Each color represents one chicken. Cells filled with patterns (not solid colors) contain rice.
In the first test case, each chicken has one cell with rice. Hence, the difference between the maximum and the minimum number of cells with rice assigned to a chicken is 0.
<image>
In the second test case, there are 4 chickens with 3 cells of rice, and 2 chickens with 2 cells of rice. Hence, the difference between the maximum and the minimum number of cells with rice assigned to a chicken is 3 - 2 = 1.
<image>
In the third test case, each chicken has 3 cells with rice. <image>
In the last test case, since there are 62 chicken with exactly 62 cells of rice, each chicken must be assigned to exactly one cell. The sample output is one of the possible way. | instruction | 0 | 2,582 | 15 | 5,164 |
Tags: constructive algorithms, greedy, implementation
Correct Solution:
```
import sys
from string import ascii_letters, digits
readline = sys.stdin.readline
T = int(readline())
Ans = []
cnums = ascii_letters + digits
for qu in range(T):
r, c, k = map(int, readline().split())
G = [[1 if s == 'R' else 0 for s in readline().strip()] for _ in range(r)]
ans = [[None]*c for _ in range(r)]
tr = sum(sum(g) for g in G)
visited = set([-1])
nr, nc = 0, -1
sep = [tr//k + (1 if i < tr%k else 0) for i in range(k)]
cc = 0
chiken = 0
for cnt in range(r*c):
for dr, dc in ((0, 1), (0, -1), (1, 0)):
if not 0 <= nc + dc <= c-1 or ((nr+dr)*c + nc+dc) in visited:
continue
else:
nc += dc
nr += dr
visited.add(nr*c + nc)
break
if G[nr][nc]:
cc += 1
ans[nr][nc] = chiken
if cc == sep[chiken] and chiken + 1 <k :
cc = 0
chiken += 1
for an in ans:
sys.stdout.write(''.join(cnums[a] for a in an))
sys.stdout.write('\n')
``` | output | 1 | 2,582 | 15 | 5,165 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Long is a huge fan of CFC (Codeforces Fried Chicken). But the price of CFC is increasing, so he decides to breed the chicken on his own farm.
His farm is presented by a rectangle grid with r rows and c columns. Some of these cells contain rice, others are empty. k chickens are living on his farm. The number of chickens is not greater than the number of cells with rice on the farm.
Long wants to give his chicken playgrounds by assigning these farm cells to his chickens. He would like to satisfy the following requirements:
* Each cell of the farm is assigned to exactly one chicken.
* Each chicken is assigned at least one cell.
* The set of cells assigned to every chicken forms a connected area. More precisely, if two cells (x, y) and (u, v) are assigned to the same chicken, this chicken is able to walk from (x, y) to (u, v) by passing only its cells and moving from each cell to another cell sharing a side.
Long also wants to prevent his chickens from fighting for food. Hence he wants the difference between the maximum and the minimum number of cells with rice assigned to a chicken to be as small as possible. Please help him.
Input
Each test contains multiple test cases. The first line contains the number of test cases T (1 ≤ T ≤ 2 ⋅ 10^4). Description of the test cases follows.
The first line of each test case contains three integers r, c and k (1 ≤ r, c ≤ 100, 1 ≤ k ≤ 62), representing the size of Long's farm and the number of chickens Long has.
Each of the next r lines contains c characters, each is either "." or "R", representing an empty cell or a cell with rice. It is guaranteed that the number of chickens is not greater than the number of cells with rice on the farm.
It is guaranteed that the sum of r ⋅ c over all test cases does not exceed 2 ⋅ 10^4.
Output
For each test case, print r lines with c characters on each line. Each character should be either a lowercase English character, an uppercase English character, or a digit. Two characters should be equal if and only if the two corresponding cells are assigned to the same chicken. Uppercase and lowercase characters are considered different, so "A" and "a" belong to two different chickens.
If there are multiple optimal answers, print any.
Example
Input
4
3 5 3
..R..
...R.
....R
6 4 6
R..R
R..R
RRRR
RRRR
R..R
R..R
5 5 4
RRR..
R.R..
RRR..
R..R.
R...R
2 31 62
RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR
RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR
Output
11122
22223
33333
aacc
aBBc
aBBc
CbbA
CbbA
CCAA
11114
22244
32444
33344
33334
abcdefghijklmnopqrstuvwxyzABCDE
FGHIJKLMNOPQRSTUVWXYZ0123456789
Note
These pictures explain the sample output. Each color represents one chicken. Cells filled with patterns (not solid colors) contain rice.
In the first test case, each chicken has one cell with rice. Hence, the difference between the maximum and the minimum number of cells with rice assigned to a chicken is 0.
<image>
In the second test case, there are 4 chickens with 3 cells of rice, and 2 chickens with 2 cells of rice. Hence, the difference between the maximum and the minimum number of cells with rice assigned to a chicken is 3 - 2 = 1.
<image>
In the third test case, each chicken has 3 cells with rice. <image>
In the last test case, since there are 62 chicken with exactly 62 cells of rice, each chicken must be assigned to exactly one cell. The sample output is one of the possible way. | instruction | 0 | 2,583 | 15 | 5,166 |
Tags: constructive algorithms, greedy, implementation
Correct Solution:
```
from collections import deque, Counter
import array
from itertools import combinations, permutations
from math import sqrt
import unittest
def read_int():
return int(input().strip())
def read_int_array():
return [int(i) for i in input().strip().split(' ')]
for test in range(read_int()):
rows, cols, ch = read_int_array()
rice = 0
field = []
for r in range(rows):
field += [list(input().strip())]
rice += field[-1].count('R')
code = '1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
i = 0
j = 0
count = 0
ch_n = 1
base = rice // ch
rem = rice % ch
base_num = ch - rem
for i in range(rows):
for j in range(cols):
j = j if i % 2 == 0 else -j-1
if field[i][j] == 'R':
count += 1
if count > (base if ch_n <= base_num else base + 1):
ch_n += 1
count = 1
field[i][j] = code[ch_n - 1]
print('\n'.join(''.join(field[i]) for i in range(rows)))
``` | output | 1 | 2,583 | 15 | 5,167 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Long is a huge fan of CFC (Codeforces Fried Chicken). But the price of CFC is increasing, so he decides to breed the chicken on his own farm.
His farm is presented by a rectangle grid with r rows and c columns. Some of these cells contain rice, others are empty. k chickens are living on his farm. The number of chickens is not greater than the number of cells with rice on the farm.
Long wants to give his chicken playgrounds by assigning these farm cells to his chickens. He would like to satisfy the following requirements:
* Each cell of the farm is assigned to exactly one chicken.
* Each chicken is assigned at least one cell.
* The set of cells assigned to every chicken forms a connected area. More precisely, if two cells (x, y) and (u, v) are assigned to the same chicken, this chicken is able to walk from (x, y) to (u, v) by passing only its cells and moving from each cell to another cell sharing a side.
Long also wants to prevent his chickens from fighting for food. Hence he wants the difference between the maximum and the minimum number of cells with rice assigned to a chicken to be as small as possible. Please help him.
Input
Each test contains multiple test cases. The first line contains the number of test cases T (1 ≤ T ≤ 2 ⋅ 10^4). Description of the test cases follows.
The first line of each test case contains three integers r, c and k (1 ≤ r, c ≤ 100, 1 ≤ k ≤ 62), representing the size of Long's farm and the number of chickens Long has.
Each of the next r lines contains c characters, each is either "." or "R", representing an empty cell or a cell with rice. It is guaranteed that the number of chickens is not greater than the number of cells with rice on the farm.
It is guaranteed that the sum of r ⋅ c over all test cases does not exceed 2 ⋅ 10^4.
Output
For each test case, print r lines with c characters on each line. Each character should be either a lowercase English character, an uppercase English character, or a digit. Two characters should be equal if and only if the two corresponding cells are assigned to the same chicken. Uppercase and lowercase characters are considered different, so "A" and "a" belong to two different chickens.
If there are multiple optimal answers, print any.
Example
Input
4
3 5 3
..R..
...R.
....R
6 4 6
R..R
R..R
RRRR
RRRR
R..R
R..R
5 5 4
RRR..
R.R..
RRR..
R..R.
R...R
2 31 62
RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR
RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR
Output
11122
22223
33333
aacc
aBBc
aBBc
CbbA
CbbA
CCAA
11114
22244
32444
33344
33334
abcdefghijklmnopqrstuvwxyzABCDE
FGHIJKLMNOPQRSTUVWXYZ0123456789
Note
These pictures explain the sample output. Each color represents one chicken. Cells filled with patterns (not solid colors) contain rice.
In the first test case, each chicken has one cell with rice. Hence, the difference between the maximum and the minimum number of cells with rice assigned to a chicken is 0.
<image>
In the second test case, there are 4 chickens with 3 cells of rice, and 2 chickens with 2 cells of rice. Hence, the difference between the maximum and the minimum number of cells with rice assigned to a chicken is 3 - 2 = 1.
<image>
In the third test case, each chicken has 3 cells with rice. <image>
In the last test case, since there are 62 chicken with exactly 62 cells of rice, each chicken must be assigned to exactly one cell. The sample output is one of the possible way.
Submitted Solution:
```
import string
chars=string.ascii_letters+string.digits
def main():
# Alternately fill left-right and right-left
t=int(input())
for _ in range(t):
n,m,k=readIntArr()
grid=list()
for __ in range(n):
grid.append(input())
riceCnts=0
for i in range(n):
for j in range(m):
if grid[i][j]=='R':
riceCnts+=1
base=riceCnts//k
remainder=riceCnts%k
chickenCnts=[base for __ in range(k)]
for i in range(remainder):
chickenCnts[i]+=1
assert sum(chickenCnts)==riceCnts
ans=[[-1 for _ in range(m)] for __ in range(n)]
fromLeft=True
chickenIdx=0
for row in range(n):
if fromLeft:
start,end,inc=0,m,1
else:
start,end,inc=m-1,-1,-1
for col in range(start,end,inc):
ans[row][col]=chars[chickenIdx]
if grid[row][col]=='R':
chickenCnts[chickenIdx]-=1
if chickenIdx+1<k and chickenCnts[chickenIdx]==0: # move on to the next chicken
chickenIdx+=1
fromLeft=not fromLeft
multiLineArrayOfArraysPrint(ans)
return
import sys
# input=sys.stdin.buffer.readline #FOR READING PURE INTEGER INPUTS (space separation ok)
input=lambda: sys.stdin.readline().rstrip("\r\n") #FOR READING STRING/TEXT INPUTS.
def oneLineArrayPrint(arr):
print(' '.join([str(x) for x in arr]))
def multiLineArrayPrint(arr):
print('\n'.join([str(x) for x in arr]))
def multiLineArrayOfArraysPrint(arr):
print('\n'.join([''.join([str(x) for x in y]) for y in arr]))
def readIntArr():
return [int(x) for x in input().split()]
# def readFloatArr():
# return [float(x) for x in input().split()]
def makeArr(defaultVal,dimensionArr): # eg. makeArr(0,[n,m])
dv=defaultVal;da=dimensionArr
if len(da)==1:return [dv for _ in range(da[0])]
else:return [makeArr(dv,da[1:]) for _ in range(da[0])]
def queryInteractive(x,y):
print('? {} {}'.format(x,y))
sys.stdout.flush()
return int(input())
def answerInteractive(ans):
print('! {}'.format(ans))
sys.stdout.flush()
inf=float('inf')
MOD=10**9+7
for _abc in range(1):
main()
``` | instruction | 0 | 2,584 | 15 | 5,168 |
Yes | output | 1 | 2,584 | 15 | 5,169 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Long is a huge fan of CFC (Codeforces Fried Chicken). But the price of CFC is increasing, so he decides to breed the chicken on his own farm.
His farm is presented by a rectangle grid with r rows and c columns. Some of these cells contain rice, others are empty. k chickens are living on his farm. The number of chickens is not greater than the number of cells with rice on the farm.
Long wants to give his chicken playgrounds by assigning these farm cells to his chickens. He would like to satisfy the following requirements:
* Each cell of the farm is assigned to exactly one chicken.
* Each chicken is assigned at least one cell.
* The set of cells assigned to every chicken forms a connected area. More precisely, if two cells (x, y) and (u, v) are assigned to the same chicken, this chicken is able to walk from (x, y) to (u, v) by passing only its cells and moving from each cell to another cell sharing a side.
Long also wants to prevent his chickens from fighting for food. Hence he wants the difference between the maximum and the minimum number of cells with rice assigned to a chicken to be as small as possible. Please help him.
Input
Each test contains multiple test cases. The first line contains the number of test cases T (1 ≤ T ≤ 2 ⋅ 10^4). Description of the test cases follows.
The first line of each test case contains three integers r, c and k (1 ≤ r, c ≤ 100, 1 ≤ k ≤ 62), representing the size of Long's farm and the number of chickens Long has.
Each of the next r lines contains c characters, each is either "." or "R", representing an empty cell or a cell with rice. It is guaranteed that the number of chickens is not greater than the number of cells with rice on the farm.
It is guaranteed that the sum of r ⋅ c over all test cases does not exceed 2 ⋅ 10^4.
Output
For each test case, print r lines with c characters on each line. Each character should be either a lowercase English character, an uppercase English character, or a digit. Two characters should be equal if and only if the two corresponding cells are assigned to the same chicken. Uppercase and lowercase characters are considered different, so "A" and "a" belong to two different chickens.
If there are multiple optimal answers, print any.
Example
Input
4
3 5 3
..R..
...R.
....R
6 4 6
R..R
R..R
RRRR
RRRR
R..R
R..R
5 5 4
RRR..
R.R..
RRR..
R..R.
R...R
2 31 62
RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR
RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR
Output
11122
22223
33333
aacc
aBBc
aBBc
CbbA
CbbA
CCAA
11114
22244
32444
33344
33334
abcdefghijklmnopqrstuvwxyzABCDE
FGHIJKLMNOPQRSTUVWXYZ0123456789
Note
These pictures explain the sample output. Each color represents one chicken. Cells filled with patterns (not solid colors) contain rice.
In the first test case, each chicken has one cell with rice. Hence, the difference between the maximum and the minimum number of cells with rice assigned to a chicken is 0.
<image>
In the second test case, there are 4 chickens with 3 cells of rice, and 2 chickens with 2 cells of rice. Hence, the difference between the maximum and the minimum number of cells with rice assigned to a chicken is 3 - 2 = 1.
<image>
In the third test case, each chicken has 3 cells with rice. <image>
In the last test case, since there are 62 chicken with exactly 62 cells of rice, each chicken must be assigned to exactly one cell. The sample output is one of the possible way.
Submitted Solution:
```
from string import ascii_letters
import os
L = ascii_letters + "".join(map(str, range(10)))
def f(lines, n_chick):
n_food = sum(x == "R" for l in lines for x in l)
res = [["X"] * len(lines[0]) for _ in range(len(lines))]
food_per_chick, extra_food = divmod(n_food, n_chick)
chick_num = 0
current_food_count = 0
for r_idx in range(len(lines)):
if r_idx % 2 == 0:
cc = range(len(lines[0]))
else:
cc = range(len(lines[0]) - 1, -1, -1)
for c_idx in cc:
if lines[r_idx][c_idx] == "R":
current_food_count += 1
if current_food_count > food_per_chick + (chick_num < extra_food):
chick_num += 1
current_food_count = 1
res[r_idx][c_idx] = L[chick_num]
return "\n".join("".join(r) for r in res)
def pp(input):
n = int(input())
for test in range(n):
r, c, k = map(int, input().split())
lines = [input() for _ in range(r)]
print(f(lines, k))
if "paalto" in os.getcwd():
from string_source import string_source
s0 = string_source(
"""4
3 5 3
..R..
...R.
....R
6 4 6
R..R
R..R
RRRR
RRRR
R..R
R..R
5 5 4
RRR..
R.R..
RRR..
R..R.
R...R
2 31 62
RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR
RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR"""
)
pp(s0)
else:
pp(input)
``` | instruction | 0 | 2,585 | 15 | 5,170 |
Yes | output | 1 | 2,585 | 15 | 5,171 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Long is a huge fan of CFC (Codeforces Fried Chicken). But the price of CFC is increasing, so he decides to breed the chicken on his own farm.
His farm is presented by a rectangle grid with r rows and c columns. Some of these cells contain rice, others are empty. k chickens are living on his farm. The number of chickens is not greater than the number of cells with rice on the farm.
Long wants to give his chicken playgrounds by assigning these farm cells to his chickens. He would like to satisfy the following requirements:
* Each cell of the farm is assigned to exactly one chicken.
* Each chicken is assigned at least one cell.
* The set of cells assigned to every chicken forms a connected area. More precisely, if two cells (x, y) and (u, v) are assigned to the same chicken, this chicken is able to walk from (x, y) to (u, v) by passing only its cells and moving from each cell to another cell sharing a side.
Long also wants to prevent his chickens from fighting for food. Hence he wants the difference between the maximum and the minimum number of cells with rice assigned to a chicken to be as small as possible. Please help him.
Input
Each test contains multiple test cases. The first line contains the number of test cases T (1 ≤ T ≤ 2 ⋅ 10^4). Description of the test cases follows.
The first line of each test case contains three integers r, c and k (1 ≤ r, c ≤ 100, 1 ≤ k ≤ 62), representing the size of Long's farm and the number of chickens Long has.
Each of the next r lines contains c characters, each is either "." or "R", representing an empty cell or a cell with rice. It is guaranteed that the number of chickens is not greater than the number of cells with rice on the farm.
It is guaranteed that the sum of r ⋅ c over all test cases does not exceed 2 ⋅ 10^4.
Output
For each test case, print r lines with c characters on each line. Each character should be either a lowercase English character, an uppercase English character, or a digit. Two characters should be equal if and only if the two corresponding cells are assigned to the same chicken. Uppercase and lowercase characters are considered different, so "A" and "a" belong to two different chickens.
If there are multiple optimal answers, print any.
Example
Input
4
3 5 3
..R..
...R.
....R
6 4 6
R..R
R..R
RRRR
RRRR
R..R
R..R
5 5 4
RRR..
R.R..
RRR..
R..R.
R...R
2 31 62
RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR
RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR
Output
11122
22223
33333
aacc
aBBc
aBBc
CbbA
CbbA
CCAA
11114
22244
32444
33344
33334
abcdefghijklmnopqrstuvwxyzABCDE
FGHIJKLMNOPQRSTUVWXYZ0123456789
Note
These pictures explain the sample output. Each color represents one chicken. Cells filled with patterns (not solid colors) contain rice.
In the first test case, each chicken has one cell with rice. Hence, the difference between the maximum and the minimum number of cells with rice assigned to a chicken is 0.
<image>
In the second test case, there are 4 chickens with 3 cells of rice, and 2 chickens with 2 cells of rice. Hence, the difference between the maximum and the minimum number of cells with rice assigned to a chicken is 3 - 2 = 1.
<image>
In the third test case, each chicken has 3 cells with rice. <image>
In the last test case, since there are 62 chicken with exactly 62 cells of rice, each chicken must be assigned to exactly one cell. The sample output is one of the possible way.
Submitted Solution:
```
from collections import Counter, OrderedDict
from itertools import permutations as perm
from collections import deque
from sys import stdin
from bisect import *
from heapq import *
import math
g = lambda : stdin.readline().strip()
gl = lambda : g().split()
gil = lambda : [int(var) for var in gl()]
gfl = lambda : [float(var) for var in gl()]
gcl = lambda : list(g())
gbs = lambda : [int(var) for var in g()]
mod = int(1e9)+7
inf = float("inf")
t, = gil()
for _ in range(t):
n, m, k = gil()
mat = []
r = 0
for _ in range(n):
mat.append(g())
r += mat[-1].count("R")
cnt = {}; base = r//k
cnt[base] = k - r%k
cnt[base+1] = r%k
ide = []
for i in range(10):
ide.append(str(i))
for ch in "abcdefghijklmnopqrstuvwxyz":
ide.append(ch)
ide.append(ch.capitalize())
x, y, idx, ct = 0, 0, 0, 0
dt = 1
# print(cnt)
ans = []
for i in range(n):
ans.append([None for _ in range(m)])
while y < n and x < m:
ans[y][x] = ide[idx]
if mat[y][x] == "R":
ct += 1
if ct in cnt :
cnt[ct] -= 1
if cnt[ct] == 0:
del cnt[ct]
idx += 1
# print(ct)
ct =0
idx = min(idx, k-1)
y += dt
if y == n:
x+=1
y=n-1
dt = -1
if y == -1:
x += 1
y = 0
dt = 1
for r in ans:
print("".join(r))
# print()
``` | instruction | 0 | 2,586 | 15 | 5,172 |
Yes | output | 1 | 2,586 | 15 | 5,173 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Long is a huge fan of CFC (Codeforces Fried Chicken). But the price of CFC is increasing, so he decides to breed the chicken on his own farm.
His farm is presented by a rectangle grid with r rows and c columns. Some of these cells contain rice, others are empty. k chickens are living on his farm. The number of chickens is not greater than the number of cells with rice on the farm.
Long wants to give his chicken playgrounds by assigning these farm cells to his chickens. He would like to satisfy the following requirements:
* Each cell of the farm is assigned to exactly one chicken.
* Each chicken is assigned at least one cell.
* The set of cells assigned to every chicken forms a connected area. More precisely, if two cells (x, y) and (u, v) are assigned to the same chicken, this chicken is able to walk from (x, y) to (u, v) by passing only its cells and moving from each cell to another cell sharing a side.
Long also wants to prevent his chickens from fighting for food. Hence he wants the difference between the maximum and the minimum number of cells with rice assigned to a chicken to be as small as possible. Please help him.
Input
Each test contains multiple test cases. The first line contains the number of test cases T (1 ≤ T ≤ 2 ⋅ 10^4). Description of the test cases follows.
The first line of each test case contains three integers r, c and k (1 ≤ r, c ≤ 100, 1 ≤ k ≤ 62), representing the size of Long's farm and the number of chickens Long has.
Each of the next r lines contains c characters, each is either "." or "R", representing an empty cell or a cell with rice. It is guaranteed that the number of chickens is not greater than the number of cells with rice on the farm.
It is guaranteed that the sum of r ⋅ c over all test cases does not exceed 2 ⋅ 10^4.
Output
For each test case, print r lines with c characters on each line. Each character should be either a lowercase English character, an uppercase English character, or a digit. Two characters should be equal if and only if the two corresponding cells are assigned to the same chicken. Uppercase and lowercase characters are considered different, so "A" and "a" belong to two different chickens.
If there are multiple optimal answers, print any.
Example
Input
4
3 5 3
..R..
...R.
....R
6 4 6
R..R
R..R
RRRR
RRRR
R..R
R..R
5 5 4
RRR..
R.R..
RRR..
R..R.
R...R
2 31 62
RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR
RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR
Output
11122
22223
33333
aacc
aBBc
aBBc
CbbA
CbbA
CCAA
11114
22244
32444
33344
33334
abcdefghijklmnopqrstuvwxyzABCDE
FGHIJKLMNOPQRSTUVWXYZ0123456789
Note
These pictures explain the sample output. Each color represents one chicken. Cells filled with patterns (not solid colors) contain rice.
In the first test case, each chicken has one cell with rice. Hence, the difference between the maximum and the minimum number of cells with rice assigned to a chicken is 0.
<image>
In the second test case, there are 4 chickens with 3 cells of rice, and 2 chickens with 2 cells of rice. Hence, the difference between the maximum and the minimum number of cells with rice assigned to a chicken is 3 - 2 = 1.
<image>
In the third test case, each chicken has 3 cells with rice. <image>
In the last test case, since there are 62 chicken with exactly 62 cells of rice, each chicken must be assigned to exactly one cell. The sample output is one of the possible way.
Submitted Solution:
```
arid='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890'
for _ in range(int(input())):
r,c,k=map(int,input().split())
ar=[]
count=0
for i in range(r):
ar.append(input())
for j in ar[-1]:
if(j=='R'):
count+=1
each=count//k
rem=count%k
count=0
tem=0
for i in range(r):
if(i%2==0):
xx=''
for j in range(0,c,1):
if(ar[i][j]=='R'):
if(count<=(rem-1)):
if(tem==(each+1)):
count+=1
tem=0
if(tem<(each+1)):
xx+=arid[count]
tem+=1
elif(count>(rem-1)):
if(tem==each):
count+=1
tem=0
if(tem<each):
xx+=arid[count]
tem+=1
else:
xx+=arid[count]
print(xx)
else:
xx=''
for j in range(c-1,-1,-1):
if(ar[i][j]=='R'):
if(count<=(rem-1)):
if(tem==(each+1)):
count+=1
tem=0
if(tem<(each+1)):
xx+=arid[count]
tem+=1
elif(count>(rem-1)):
if(tem==each):
count+=1
tem=0
if(tem<each):
xx+=arid[count]
tem+=1
else:
xx+=arid[count]
print(xx[::-1])
``` | instruction | 0 | 2,587 | 15 | 5,174 |
Yes | output | 1 | 2,587 | 15 | 5,175 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Long is a huge fan of CFC (Codeforces Fried Chicken). But the price of CFC is increasing, so he decides to breed the chicken on his own farm.
His farm is presented by a rectangle grid with r rows and c columns. Some of these cells contain rice, others are empty. k chickens are living on his farm. The number of chickens is not greater than the number of cells with rice on the farm.
Long wants to give his chicken playgrounds by assigning these farm cells to his chickens. He would like to satisfy the following requirements:
* Each cell of the farm is assigned to exactly one chicken.
* Each chicken is assigned at least one cell.
* The set of cells assigned to every chicken forms a connected area. More precisely, if two cells (x, y) and (u, v) are assigned to the same chicken, this chicken is able to walk from (x, y) to (u, v) by passing only its cells and moving from each cell to another cell sharing a side.
Long also wants to prevent his chickens from fighting for food. Hence he wants the difference between the maximum and the minimum number of cells with rice assigned to a chicken to be as small as possible. Please help him.
Input
Each test contains multiple test cases. The first line contains the number of test cases T (1 ≤ T ≤ 2 ⋅ 10^4). Description of the test cases follows.
The first line of each test case contains three integers r, c and k (1 ≤ r, c ≤ 100, 1 ≤ k ≤ 62), representing the size of Long's farm and the number of chickens Long has.
Each of the next r lines contains c characters, each is either "." or "R", representing an empty cell or a cell with rice. It is guaranteed that the number of chickens is not greater than the number of cells with rice on the farm.
It is guaranteed that the sum of r ⋅ c over all test cases does not exceed 2 ⋅ 10^4.
Output
For each test case, print r lines with c characters on each line. Each character should be either a lowercase English character, an uppercase English character, or a digit. Two characters should be equal if and only if the two corresponding cells are assigned to the same chicken. Uppercase and lowercase characters are considered different, so "A" and "a" belong to two different chickens.
If there are multiple optimal answers, print any.
Example
Input
4
3 5 3
..R..
...R.
....R
6 4 6
R..R
R..R
RRRR
RRRR
R..R
R..R
5 5 4
RRR..
R.R..
RRR..
R..R.
R...R
2 31 62
RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR
RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR
Output
11122
22223
33333
aacc
aBBc
aBBc
CbbA
CbbA
CCAA
11114
22244
32444
33344
33334
abcdefghijklmnopqrstuvwxyzABCDE
FGHIJKLMNOPQRSTUVWXYZ0123456789
Note
These pictures explain the sample output. Each color represents one chicken. Cells filled with patterns (not solid colors) contain rice.
In the first test case, each chicken has one cell with rice. Hence, the difference between the maximum and the minimum number of cells with rice assigned to a chicken is 0.
<image>
In the second test case, there are 4 chickens with 3 cells of rice, and 2 chickens with 2 cells of rice. Hence, the difference between the maximum and the minimum number of cells with rice assigned to a chicken is 3 - 2 = 1.
<image>
In the third test case, each chicken has 3 cells with rice. <image>
In the last test case, since there are 62 chicken with exactly 62 cells of rice, each chicken must be assigned to exactly one cell. The sample output is one of the possible way.
Submitted Solution:
```
# Legends Always Come Up with Solution
# Author: Manvir Singh
import os
from io import BytesIO, IOBase
import sys
from collections import deque
from string import ascii_letters
def main():
t=[]
zzz=list(ascii_letters)+[chr(i+48) for i in range(10)]
for _ in range(int(input())):
r,c,kk=map(int,input().split())
a=[list(input().rstrip())+["#"] for _ in range(r)]
a.append(["#"]*(c+1))
u,v=divmod(sum(i.count("R") for i in a),kk)
dx=[0,1,-1,0]
dy=[-1,0,0,1]
k=0
for i in range(r):
for j in range(c):
if a[i][j] not in "R.":
continue
q,z,a[i][j]=deque([(i,j)]),u+(v>0)-(a[i][j]=="R"),zzz[k]
while z and q:
x,y=q.popleft()
for l in range(4):
xx,yy=x+dx[l],y+dy[l]
if a[xx][yy]=="R":
a[xx][yy],z=zzz[k],z-1
if not z:
break
q.append((xx,yy))
elif a[xx][yy]==".":
a[xx][yy]=zzz[k]
q.append((xx, yy))
v,k=v-1,k+1
if k==kk:
break
if k==kk:
break
for i in range(r):
for j in range(c):
if a[i][j]==".":
continue
q,z=deque([(i,j)]),a[i][j]
while q:
x,y=q.popleft()
for l in range(4):
xx,yy=x+dx[l],y+dy[l]
if a[xx][yy] ==".":
a[xx][yy]=z
q.append((xx,yy))
for i in a[:r]:
print("".join(i[:c]))
# FAST INPUT OUTPUT REGION
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
if __name__ == "__main__":
main()
``` | instruction | 0 | 2,588 | 15 | 5,176 |
No | output | 1 | 2,588 | 15 | 5,177 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Long is a huge fan of CFC (Codeforces Fried Chicken). But the price of CFC is increasing, so he decides to breed the chicken on his own farm.
His farm is presented by a rectangle grid with r rows and c columns. Some of these cells contain rice, others are empty. k chickens are living on his farm. The number of chickens is not greater than the number of cells with rice on the farm.
Long wants to give his chicken playgrounds by assigning these farm cells to his chickens. He would like to satisfy the following requirements:
* Each cell of the farm is assigned to exactly one chicken.
* Each chicken is assigned at least one cell.
* The set of cells assigned to every chicken forms a connected area. More precisely, if two cells (x, y) and (u, v) are assigned to the same chicken, this chicken is able to walk from (x, y) to (u, v) by passing only its cells and moving from each cell to another cell sharing a side.
Long also wants to prevent his chickens from fighting for food. Hence he wants the difference between the maximum and the minimum number of cells with rice assigned to a chicken to be as small as possible. Please help him.
Input
Each test contains multiple test cases. The first line contains the number of test cases T (1 ≤ T ≤ 2 ⋅ 10^4). Description of the test cases follows.
The first line of each test case contains three integers r, c and k (1 ≤ r, c ≤ 100, 1 ≤ k ≤ 62), representing the size of Long's farm and the number of chickens Long has.
Each of the next r lines contains c characters, each is either "." or "R", representing an empty cell or a cell with rice. It is guaranteed that the number of chickens is not greater than the number of cells with rice on the farm.
It is guaranteed that the sum of r ⋅ c over all test cases does not exceed 2 ⋅ 10^4.
Output
For each test case, print r lines with c characters on each line. Each character should be either a lowercase English character, an uppercase English character, or a digit. Two characters should be equal if and only if the two corresponding cells are assigned to the same chicken. Uppercase and lowercase characters are considered different, so "A" and "a" belong to two different chickens.
If there are multiple optimal answers, print any.
Example
Input
4
3 5 3
..R..
...R.
....R
6 4 6
R..R
R..R
RRRR
RRRR
R..R
R..R
5 5 4
RRR..
R.R..
RRR..
R..R.
R...R
2 31 62
RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR
RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR
Output
11122
22223
33333
aacc
aBBc
aBBc
CbbA
CbbA
CCAA
11114
22244
32444
33344
33334
abcdefghijklmnopqrstuvwxyzABCDE
FGHIJKLMNOPQRSTUVWXYZ0123456789
Note
These pictures explain the sample output. Each color represents one chicken. Cells filled with patterns (not solid colors) contain rice.
In the first test case, each chicken has one cell with rice. Hence, the difference between the maximum and the minimum number of cells with rice assigned to a chicken is 0.
<image>
In the second test case, there are 4 chickens with 3 cells of rice, and 2 chickens with 2 cells of rice. Hence, the difference between the maximum and the minimum number of cells with rice assigned to a chicken is 3 - 2 = 1.
<image>
In the third test case, each chicken has 3 cells with rice. <image>
In the last test case, since there are 62 chicken with exactly 62 cells of rice, each chicken must be assigned to exactly one cell. The sample output is one of the possible way.
Submitted Solution:
```
# Legends Always Come Up with Solution
# Author: Manvir Singh
import os
from io import BytesIO, IOBase
import sys
from collections import deque
from string import ascii_letters
from copy import deepcopy
def main():
t,f=[],0
zzz=list(ascii_letters)+[chr(i+48) for i in range(10)]
for tt in range(int(input())):
r,c,kk=map(int,input().split())
a=[list(input().rstrip())+["#"] for _ in range(r)]
a.append(["#"]*(c+1))
b=deepcopy(a)
u,v=divmod(sum(i.count("R") for i in a),kk)
dx=[0,1,-1,0]
dy=[-1,0,0,1]
k=0
for i in range(r):
for j in range(c):
if a[i][j]!="R":
continue
q,z,a[i][j]=deque([(i,j)]),u+(v>0)-1,zzz[k]
while z and q:
x,y=q.popleft()
for l in range(4):
xx,yy=x+dx[l],y+dy[l]
if a[xx][yy]=="R":
a[xx][yy],z=zzz[k],z-1
if not z:
break
q.append((xx,yy))
elif a[xx][yy]==".":
a[xx][yy]=zzz[k]
q.append((xx, yy))
if z:
f=1
print(r,c,kk,tt+1,b)
break
v,k=v-1,k+1
if f:
break
if not f:
for i in range(r):
for j in range(c):
if a[i][j]==".":
continue
q,z=deque([(i,j)]),a[i][j]
while q:
x,y=q.popleft()
for l in range(4):
xx,yy=x+dx[l],y+dy[l]
if a[xx][yy] ==".":
a[xx][yy]=z
q.append((xx,yy))
t.append(a)
if not f:
for i in t:
for j in i[:len(i)-1]:
print("".join(j[:len(j)-1]))
# FAST INPUT OUTPUT REGION
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
if __name__ == "__main__":
main()
``` | instruction | 0 | 2,589 | 15 | 5,178 |
No | output | 1 | 2,589 | 15 | 5,179 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Long is a huge fan of CFC (Codeforces Fried Chicken). But the price of CFC is increasing, so he decides to breed the chicken on his own farm.
His farm is presented by a rectangle grid with r rows and c columns. Some of these cells contain rice, others are empty. k chickens are living on his farm. The number of chickens is not greater than the number of cells with rice on the farm.
Long wants to give his chicken playgrounds by assigning these farm cells to his chickens. He would like to satisfy the following requirements:
* Each cell of the farm is assigned to exactly one chicken.
* Each chicken is assigned at least one cell.
* The set of cells assigned to every chicken forms a connected area. More precisely, if two cells (x, y) and (u, v) are assigned to the same chicken, this chicken is able to walk from (x, y) to (u, v) by passing only its cells and moving from each cell to another cell sharing a side.
Long also wants to prevent his chickens from fighting for food. Hence he wants the difference between the maximum and the minimum number of cells with rice assigned to a chicken to be as small as possible. Please help him.
Input
Each test contains multiple test cases. The first line contains the number of test cases T (1 ≤ T ≤ 2 ⋅ 10^4). Description of the test cases follows.
The first line of each test case contains three integers r, c and k (1 ≤ r, c ≤ 100, 1 ≤ k ≤ 62), representing the size of Long's farm and the number of chickens Long has.
Each of the next r lines contains c characters, each is either "." or "R", representing an empty cell or a cell with rice. It is guaranteed that the number of chickens is not greater than the number of cells with rice on the farm.
It is guaranteed that the sum of r ⋅ c over all test cases does not exceed 2 ⋅ 10^4.
Output
For each test case, print r lines with c characters on each line. Each character should be either a lowercase English character, an uppercase English character, or a digit. Two characters should be equal if and only if the two corresponding cells are assigned to the same chicken. Uppercase and lowercase characters are considered different, so "A" and "a" belong to two different chickens.
If there are multiple optimal answers, print any.
Example
Input
4
3 5 3
..R..
...R.
....R
6 4 6
R..R
R..R
RRRR
RRRR
R..R
R..R
5 5 4
RRR..
R.R..
RRR..
R..R.
R...R
2 31 62
RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR
RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR
Output
11122
22223
33333
aacc
aBBc
aBBc
CbbA
CbbA
CCAA
11114
22244
32444
33344
33334
abcdefghijklmnopqrstuvwxyzABCDE
FGHIJKLMNOPQRSTUVWXYZ0123456789
Note
These pictures explain the sample output. Each color represents one chicken. Cells filled with patterns (not solid colors) contain rice.
In the first test case, each chicken has one cell with rice. Hence, the difference between the maximum and the minimum number of cells with rice assigned to a chicken is 0.
<image>
In the second test case, there are 4 chickens with 3 cells of rice, and 2 chickens with 2 cells of rice. Hence, the difference between the maximum and the minimum number of cells with rice assigned to a chicken is 3 - 2 = 1.
<image>
In the third test case, each chicken has 3 cells with rice. <image>
In the last test case, since there are 62 chicken with exactly 62 cells of rice, each chicken must be assigned to exactly one cell. The sample output is one of the possible way.
Submitted Solution:
```
import os
import sys
from io import BytesIO, IOBase
# region fastio
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
# ------------------------------
def RL(): return map(int, sys.stdin.readline().rstrip().split())
def RLL(): return list(map(int, sys.stdin.readline().rstrip().split()))
def N(): return int(input())
def comb(n, m): return factorial(n) / (factorial(m) * factorial(n - m)) if n >= m else 0
def perm(n, m): return factorial(n) // (factorial(n - m)) if n >= m else 0
def mdis(x1, y1, x2, y2): return abs(x1 - x2) + abs(y1 - y2)
def toord(c): return ord(c) - ord('a')
def lcm(a, b): return a * b // lcm(a, b)
mod = 998244353
INF = float('inf')
from math import factorial, sqrt, ceil, floor, gcd
from collections import Counter, defaultdict, deque
from heapq import heapify, heappop, heappush
from string import ascii_lowercase as lw
from string import ascii_uppercase as uw
from string import digits as dg
# ------------------------------
# f = open('./input.txt')
# sys.stdin = f
def main():
for _ in range(N()):
r, c, k = RL()
arr = [list(input()) for _ in range(r)]
rnum = 0
for i in arr:
rnum+=i.count('R')
sig = rnum//k
dif = rnum%k
st = lw + uw + dg
res = [['']*c for _ in range(r)]
now = 0
tag = 0
stag = 0
for i in range(r):
for j in range(c):
if tag==0:
nj = j
else:
nj = c-j-1
if arr[i][nj]=='R':
now+=1
res[i][nj] = st[stag]
if dif==0:
if now == sig:
now = 0
stag+=1
else:
if now==sig+1:
now = 0
stag+=1
dif-=1
tag^=1
for i in res: print(''.join(i))
if __name__ == "__main__":
main()
``` | instruction | 0 | 2,590 | 15 | 5,180 |
No | output | 1 | 2,590 | 15 | 5,181 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Long is a huge fan of CFC (Codeforces Fried Chicken). But the price of CFC is increasing, so he decides to breed the chicken on his own farm.
His farm is presented by a rectangle grid with r rows and c columns. Some of these cells contain rice, others are empty. k chickens are living on his farm. The number of chickens is not greater than the number of cells with rice on the farm.
Long wants to give his chicken playgrounds by assigning these farm cells to his chickens. He would like to satisfy the following requirements:
* Each cell of the farm is assigned to exactly one chicken.
* Each chicken is assigned at least one cell.
* The set of cells assigned to every chicken forms a connected area. More precisely, if two cells (x, y) and (u, v) are assigned to the same chicken, this chicken is able to walk from (x, y) to (u, v) by passing only its cells and moving from each cell to another cell sharing a side.
Long also wants to prevent his chickens from fighting for food. Hence he wants the difference between the maximum and the minimum number of cells with rice assigned to a chicken to be as small as possible. Please help him.
Input
Each test contains multiple test cases. The first line contains the number of test cases T (1 ≤ T ≤ 2 ⋅ 10^4). Description of the test cases follows.
The first line of each test case contains three integers r, c and k (1 ≤ r, c ≤ 100, 1 ≤ k ≤ 62), representing the size of Long's farm and the number of chickens Long has.
Each of the next r lines contains c characters, each is either "." or "R", representing an empty cell or a cell with rice. It is guaranteed that the number of chickens is not greater than the number of cells with rice on the farm.
It is guaranteed that the sum of r ⋅ c over all test cases does not exceed 2 ⋅ 10^4.
Output
For each test case, print r lines with c characters on each line. Each character should be either a lowercase English character, an uppercase English character, or a digit. Two characters should be equal if and only if the two corresponding cells are assigned to the same chicken. Uppercase and lowercase characters are considered different, so "A" and "a" belong to two different chickens.
If there are multiple optimal answers, print any.
Example
Input
4
3 5 3
..R..
...R.
....R
6 4 6
R..R
R..R
RRRR
RRRR
R..R
R..R
5 5 4
RRR..
R.R..
RRR..
R..R.
R...R
2 31 62
RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR
RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR
Output
11122
22223
33333
aacc
aBBc
aBBc
CbbA
CbbA
CCAA
11114
22244
32444
33344
33334
abcdefghijklmnopqrstuvwxyzABCDE
FGHIJKLMNOPQRSTUVWXYZ0123456789
Note
These pictures explain the sample output. Each color represents one chicken. Cells filled with patterns (not solid colors) contain rice.
In the first test case, each chicken has one cell with rice. Hence, the difference between the maximum and the minimum number of cells with rice assigned to a chicken is 0.
<image>
In the second test case, there are 4 chickens with 3 cells of rice, and 2 chickens with 2 cells of rice. Hence, the difference between the maximum and the minimum number of cells with rice assigned to a chicken is 3 - 2 = 1.
<image>
In the third test case, each chicken has 3 cells with rice. <image>
In the last test case, since there are 62 chicken with exactly 62 cells of rice, each chicken must be assigned to exactly one cell. The sample output is one of the possible way.
Submitted Solution:
```
# Legends Always Come Up with Solution
# Author: Manvir Singh
import os
from io import BytesIO, IOBase
import sys
from string import ascii_letters
def solve(a,x,y,ch):
for i in range(x,len(a),1):
for j in range(y,len(a[0]),1):
a[i][j]=ch
y=0
def main():
al=list(ascii_letters)+[chr(i+48) for i in range(10)]
for _ in range(int(input())):
r,c,k=map(int,input().split())
a=[list(input().rstrip()) for _ in range(r)]
u,v=divmod(sum(i.count("R") for i in a),k)
z,v,k=u+(v>0),v-1,k-1
for i in range(r):
if i&1:
for j in range(c-1,-1,-1):
a[i][j],z=al[k],z-(a[i][j]=="R")
if z==0:
z,v,k=u+(v>0),v-1,k-1
if k==-1:
solve(a,i,j,al[0])
else:
for j in range(c):
a[i][j],z=al[k],z-(a[i][j]=="R")
if z==0:
z,v,k=u+(v>0),v-1,k-1
if k==-1:
solve(a,i,j,al[0])
for i in a:
print("".join(i))
# FAST INPUT OUTPUT REGION
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
if __name__ == "__main__":
main()
``` | instruction | 0 | 2,591 | 15 | 5,182 |
No | output | 1 | 2,591 | 15 | 5,183 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Galya is playing one-dimensional Sea Battle on a 1 × n grid. In this game a ships are placed on the grid. Each of the ships consists of b consecutive cells. No cell can be part of two ships, however, the ships can touch each other.
Galya doesn't know the ships location. She can shoot to some cells and after each shot she is told if that cell was a part of some ship (this case is called "hit") or not (this case is called "miss").
Galya has already made k shots, all of them were misses.
Your task is to calculate the minimum number of cells such that if Galya shoot at all of them, she would hit at least one ship.
It is guaranteed that there is at least one valid ships placement.
Input
The first line contains four positive integers n, a, b, k (1 ≤ n ≤ 2·105, 1 ≤ a, b ≤ n, 0 ≤ k ≤ n - 1) — the length of the grid, the number of ships on the grid, the length of each ship and the number of shots Galya has already made.
The second line contains a string of length n, consisting of zeros and ones. If the i-th character is one, Galya has already made a shot to this cell. Otherwise, she hasn't. It is guaranteed that there are exactly k ones in this string.
Output
In the first line print the minimum number of cells such that if Galya shoot at all of them, she would hit at least one ship.
In the second line print the cells Galya should shoot at.
Each cell should be printed exactly once. You can print the cells in arbitrary order. The cells are numbered from 1 to n, starting from the left.
If there are multiple answers, you can print any of them.
Examples
Input
5 1 2 1
00100
Output
2
4 2
Input
13 3 2 3
1000000010001
Output
2
7 11
Note
There is one ship in the first sample. It can be either to the left or to the right from the shot Galya has already made (the "1" character). So, it is necessary to make two shots: one at the left part, and one at the right part. | instruction | 0 | 2,956 | 15 | 5,912 |
Tags: constructive algorithms, greedy, math
Correct Solution:
```
n, s, b, k = map(int, input().split())
a = list('1' + input() + '1')
ans = []
cnt = 0
for i in range(len(a)):
if a[i] == '0':
cnt += 1
else:
cnt = 0
if cnt == b:
if s > 1:
s -= 1
else:
ans.append(i)
cnt = 0
print(len(ans))
for i in range(len(ans)):
print(ans[i], end=' ')
``` | output | 1 | 2,956 | 15 | 5,913 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Galya is playing one-dimensional Sea Battle on a 1 × n grid. In this game a ships are placed on the grid. Each of the ships consists of b consecutive cells. No cell can be part of two ships, however, the ships can touch each other.
Galya doesn't know the ships location. She can shoot to some cells and after each shot she is told if that cell was a part of some ship (this case is called "hit") or not (this case is called "miss").
Galya has already made k shots, all of them were misses.
Your task is to calculate the minimum number of cells such that if Galya shoot at all of them, she would hit at least one ship.
It is guaranteed that there is at least one valid ships placement.
Input
The first line contains four positive integers n, a, b, k (1 ≤ n ≤ 2·105, 1 ≤ a, b ≤ n, 0 ≤ k ≤ n - 1) — the length of the grid, the number of ships on the grid, the length of each ship and the number of shots Galya has already made.
The second line contains a string of length n, consisting of zeros and ones. If the i-th character is one, Galya has already made a shot to this cell. Otherwise, she hasn't. It is guaranteed that there are exactly k ones in this string.
Output
In the first line print the minimum number of cells such that if Galya shoot at all of them, she would hit at least one ship.
In the second line print the cells Galya should shoot at.
Each cell should be printed exactly once. You can print the cells in arbitrary order. The cells are numbered from 1 to n, starting from the left.
If there are multiple answers, you can print any of them.
Examples
Input
5 1 2 1
00100
Output
2
4 2
Input
13 3 2 3
1000000010001
Output
2
7 11
Note
There is one ship in the first sample. It can be either to the left or to the right from the shot Galya has already made (the "1" character). So, it is necessary to make two shots: one at the left part, and one at the right part. | instruction | 0 | 2,957 | 15 | 5,914 |
Tags: constructive algorithms, greedy, math
Correct Solution:
```
'''input
5 4 1 0
00000
'''
from sys import stdin
import collections
import math
def get_working(string):
aux = []
first = None
if string[0] == 1:
pass
else:
first = -1
for i in range(len(string)):
if string[i] == '1':
if first == None:
first = i
elif first != None:
aux.append([first, i, (i - first - 1)])
first = i
if first != None:
aux.append([first, len(string), (len(string) - first) - 1])
return aux
# main starts
n, a, b, k = list(map(int, stdin.readline().split()))
string = list(stdin.readline().strip())
ans = 0
working = get_working(string)
# print(working)
current = a
flag = 0
for i in working:
if flag == 1:
break
start, end, gap = i
j = end - 1
if gap//b > 0:
while j > start:
if current == 0:
flag = 1
break
if (j - start)// b > 0:
for k in range(j, j - b, -1):
string[k] = '2'
j -= b
current -= 1
else:
break
ans = []
count = 0
for i in range(len(string)):
if string[i] == '0':
if i > 0 and string[i - 1] == '0':
count += 1
else:
count = 1
if count == b:
string[i] = 'b'
ans.append(i + 1)
count = 0
for i in range(len(string)):
if string[i] == '2':
ans.append(i + 1)
break
# print(string)
print(len(ans))
print(*ans)
# print(ans)
# for i in range(n):
# if string[i] == 'b':
# print(i + 1, end = ' ')
``` | output | 1 | 2,957 | 15 | 5,915 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Galya is playing one-dimensional Sea Battle on a 1 × n grid. In this game a ships are placed on the grid. Each of the ships consists of b consecutive cells. No cell can be part of two ships, however, the ships can touch each other.
Galya doesn't know the ships location. She can shoot to some cells and after each shot she is told if that cell was a part of some ship (this case is called "hit") or not (this case is called "miss").
Galya has already made k shots, all of them were misses.
Your task is to calculate the minimum number of cells such that if Galya shoot at all of them, she would hit at least one ship.
It is guaranteed that there is at least one valid ships placement.
Input
The first line contains four positive integers n, a, b, k (1 ≤ n ≤ 2·105, 1 ≤ a, b ≤ n, 0 ≤ k ≤ n - 1) — the length of the grid, the number of ships on the grid, the length of each ship and the number of shots Galya has already made.
The second line contains a string of length n, consisting of zeros and ones. If the i-th character is one, Galya has already made a shot to this cell. Otherwise, she hasn't. It is guaranteed that there are exactly k ones in this string.
Output
In the first line print the minimum number of cells such that if Galya shoot at all of them, she would hit at least one ship.
In the second line print the cells Galya should shoot at.
Each cell should be printed exactly once. You can print the cells in arbitrary order. The cells are numbered from 1 to n, starting from the left.
If there are multiple answers, you can print any of them.
Examples
Input
5 1 2 1
00100
Output
2
4 2
Input
13 3 2 3
1000000010001
Output
2
7 11
Note
There is one ship in the first sample. It can be either to the left or to the right from the shot Galya has already made (the "1" character). So, it is necessary to make two shots: one at the left part, and one at the right part. | instruction | 0 | 2,958 | 15 | 5,916 |
Tags: constructive algorithms, greedy, math
Correct Solution:
```
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
INF = 10 ** 18
MOD = 10**9+7
Ri = lambda : [int(x) for x in sys.stdin.readline().split()]
ri = lambda : sys.stdin.readline().strip()
n,a,b,k = Ri()
s = ri()
cnt = 0
totans = 0; ans = []
for i in range(len(s)):
if s[i] == '0':
cnt+=1
else:
cnt= 0
if cnt == b:
if a > 1:
a-=1
else:
ans.append(i+1)
totans+=1
cnt = 0
print(totans)
print(*ans)
``` | output | 1 | 2,958 | 15 | 5,917 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Galya is playing one-dimensional Sea Battle on a 1 × n grid. In this game a ships are placed on the grid. Each of the ships consists of b consecutive cells. No cell can be part of two ships, however, the ships can touch each other.
Galya doesn't know the ships location. She can shoot to some cells and after each shot she is told if that cell was a part of some ship (this case is called "hit") or not (this case is called "miss").
Galya has already made k shots, all of them were misses.
Your task is to calculate the minimum number of cells such that if Galya shoot at all of them, she would hit at least one ship.
It is guaranteed that there is at least one valid ships placement.
Input
The first line contains four positive integers n, a, b, k (1 ≤ n ≤ 2·105, 1 ≤ a, b ≤ n, 0 ≤ k ≤ n - 1) — the length of the grid, the number of ships on the grid, the length of each ship and the number of shots Galya has already made.
The second line contains a string of length n, consisting of zeros and ones. If the i-th character is one, Galya has already made a shot to this cell. Otherwise, she hasn't. It is guaranteed that there are exactly k ones in this string.
Output
In the first line print the minimum number of cells such that if Galya shoot at all of them, she would hit at least one ship.
In the second line print the cells Galya should shoot at.
Each cell should be printed exactly once. You can print the cells in arbitrary order. The cells are numbered from 1 to n, starting from the left.
If there are multiple answers, you can print any of them.
Examples
Input
5 1 2 1
00100
Output
2
4 2
Input
13 3 2 3
1000000010001
Output
2
7 11
Note
There is one ship in the first sample. It can be either to the left or to the right from the shot Galya has already made (the "1" character). So, it is necessary to make two shots: one at the left part, and one at the right part. | instruction | 0 | 2,959 | 15 | 5,918 |
Tags: constructive algorithms, greedy, math
Correct Solution:
```
n,a,b,k=map(int,input().split())
A=input()
B=A.split('1')
C=[]
l=1
for i in B:
if len(i)>=b:
for j in range(b-1,len(i),b):
C.append(j+l)
l+=len(i)+1
C=C[:len(C)-a+1]
print(len(C))
print(' '.join(list(map(str,C))))
# Made By Mostafa_Khaled
``` | output | 1 | 2,959 | 15 | 5,919 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Galya is playing one-dimensional Sea Battle on a 1 × n grid. In this game a ships are placed on the grid. Each of the ships consists of b consecutive cells. No cell can be part of two ships, however, the ships can touch each other.
Galya doesn't know the ships location. She can shoot to some cells and after each shot she is told if that cell was a part of some ship (this case is called "hit") or not (this case is called "miss").
Galya has already made k shots, all of them were misses.
Your task is to calculate the minimum number of cells such that if Galya shoot at all of them, she would hit at least one ship.
It is guaranteed that there is at least one valid ships placement.
Input
The first line contains four positive integers n, a, b, k (1 ≤ n ≤ 2·105, 1 ≤ a, b ≤ n, 0 ≤ k ≤ n - 1) — the length of the grid, the number of ships on the grid, the length of each ship and the number of shots Galya has already made.
The second line contains a string of length n, consisting of zeros and ones. If the i-th character is one, Galya has already made a shot to this cell. Otherwise, she hasn't. It is guaranteed that there are exactly k ones in this string.
Output
In the first line print the minimum number of cells such that if Galya shoot at all of them, she would hit at least one ship.
In the second line print the cells Galya should shoot at.
Each cell should be printed exactly once. You can print the cells in arbitrary order. The cells are numbered from 1 to n, starting from the left.
If there are multiple answers, you can print any of them.
Examples
Input
5 1 2 1
00100
Output
2
4 2
Input
13 3 2 3
1000000010001
Output
2
7 11
Note
There is one ship in the first sample. It can be either to the left or to the right from the shot Galya has already made (the "1" character). So, it is necessary to make two shots: one at the left part, and one at the right part. | instruction | 0 | 2,960 | 15 | 5,920 |
Tags: constructive algorithms, greedy, math
Correct Solution:
```
# Why do we fall ? So we can learn to pick ourselves up.
from itertools import groupby
n,a,b,k = map(int,input().split())
s = input()
sg = [list(g) for s,g in groupby(s)]
ll = 0
hits = []
for i in range(0,len(sg)):
if sg[i][0] == '0' and len(sg[i]) >= b:
for hit in range(b-1,len(sg[i]),b):
hits.append(hit+ll+1)
ll += len(sg[i])
else:
ll += len(sg[i])
# print(hits)
# We remove number of (ships-1) from the total number of hits because we are hitting at every possible location where
# where the ship can be placed and since we want to hit AT LEAST ONE SHIP, removing (ships-1) will still hit at least one ship
hits = hits[a-1:]
print(len(hits))
print(*hits)
"""
13 3 2 3
1000000010001
15 3 2 3
1000000000010001
"""
``` | output | 1 | 2,960 | 15 | 5,921 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Galya is playing one-dimensional Sea Battle on a 1 × n grid. In this game a ships are placed on the grid. Each of the ships consists of b consecutive cells. No cell can be part of two ships, however, the ships can touch each other.
Galya doesn't know the ships location. She can shoot to some cells and after each shot she is told if that cell was a part of some ship (this case is called "hit") or not (this case is called "miss").
Galya has already made k shots, all of them were misses.
Your task is to calculate the minimum number of cells such that if Galya shoot at all of them, she would hit at least one ship.
It is guaranteed that there is at least one valid ships placement.
Input
The first line contains four positive integers n, a, b, k (1 ≤ n ≤ 2·105, 1 ≤ a, b ≤ n, 0 ≤ k ≤ n - 1) — the length of the grid, the number of ships on the grid, the length of each ship and the number of shots Galya has already made.
The second line contains a string of length n, consisting of zeros and ones. If the i-th character is one, Galya has already made a shot to this cell. Otherwise, she hasn't. It is guaranteed that there are exactly k ones in this string.
Output
In the first line print the minimum number of cells such that if Galya shoot at all of them, she would hit at least one ship.
In the second line print the cells Galya should shoot at.
Each cell should be printed exactly once. You can print the cells in arbitrary order. The cells are numbered from 1 to n, starting from the left.
If there are multiple answers, you can print any of them.
Examples
Input
5 1 2 1
00100
Output
2
4 2
Input
13 3 2 3
1000000010001
Output
2
7 11
Note
There is one ship in the first sample. It can be either to the left or to the right from the shot Galya has already made (the "1" character). So, it is necessary to make two shots: one at the left part, and one at the right part. | instruction | 0 | 2,961 | 15 | 5,922 |
Tags: constructive algorithms, greedy, math
Correct Solution:
```
n,a,b,k=[int(i) for i in input().split()]
s=input()
l=[]
i=0
j=0
while i<len(s):
if s[i]=="1":
j=0
else :
j+=1
if(j%b)==0:
l+=[i+1]
j=0
i+=1
l=l[a-1:]
print(len(l))
print(*l)
``` | output | 1 | 2,961 | 15 | 5,923 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Galya is playing one-dimensional Sea Battle on a 1 × n grid. In this game a ships are placed on the grid. Each of the ships consists of b consecutive cells. No cell can be part of two ships, however, the ships can touch each other.
Galya doesn't know the ships location. She can shoot to some cells and after each shot she is told if that cell was a part of some ship (this case is called "hit") or not (this case is called "miss").
Galya has already made k shots, all of them were misses.
Your task is to calculate the minimum number of cells such that if Galya shoot at all of them, she would hit at least one ship.
It is guaranteed that there is at least one valid ships placement.
Input
The first line contains four positive integers n, a, b, k (1 ≤ n ≤ 2·105, 1 ≤ a, b ≤ n, 0 ≤ k ≤ n - 1) — the length of the grid, the number of ships on the grid, the length of each ship and the number of shots Galya has already made.
The second line contains a string of length n, consisting of zeros and ones. If the i-th character is one, Galya has already made a shot to this cell. Otherwise, she hasn't. It is guaranteed that there are exactly k ones in this string.
Output
In the first line print the minimum number of cells such that if Galya shoot at all of them, she would hit at least one ship.
In the second line print the cells Galya should shoot at.
Each cell should be printed exactly once. You can print the cells in arbitrary order. The cells are numbered from 1 to n, starting from the left.
If there are multiple answers, you can print any of them.
Examples
Input
5 1 2 1
00100
Output
2
4 2
Input
13 3 2 3
1000000010001
Output
2
7 11
Note
There is one ship in the first sample. It can be either to the left or to the right from the shot Galya has already made (the "1" character). So, it is necessary to make two shots: one at the left part, and one at the right part. | instruction | 0 | 2,962 | 15 | 5,924 |
Tags: constructive algorithms, greedy, math
Correct Solution:
```
"Codeforces Round #384 (Div. 2)"
"C. Vladik and fractions"
# y=int(input())
# a=y
# b=a+1
# c=y*b
# if y==1:
# print(-1)
# else:
# print(a,b,c)
"Technocup 2017 - Elimination Round 2"
"D. Sea Battle"
n,a,b,k=map(int,input().split())
s=list(input())
n=len(s)
lz=[]
zeros=[]
indexes=[]
flage=0
if s[0]=="0":
lz.append(0)
flage=1
for i in range(1,n):
if flage==1 and s[i]=="1":
zeros.append(i-1-(lz[-1])+1)
lz.append(i-1)
flage=0
elif flage==0 and s[i]=="0":
lz.append(i)
flage=1
if s[-1]=="0":
zeros.append(n-1-(lz[-1])+1)
lz.append(n-1)
min_no_spaces=(a-1)*b
spaces_left=n-k
l=len(lz)
# print(lz)
# print(zeros)
shotes=0
for i in range(len(zeros)):
h=i*2
if min_no_spaces!=0:
# print(min_no_spaces)
if min_no_spaces>=zeros[i]:
min_no_spaces-=(int(zeros[i]/b))*b
elif min_no_spaces<zeros[i]:
shotes+=int((zeros[i]-min_no_spaces)/b)
for j in range(int((zeros[i]-min_no_spaces)/b)):
indexes.append(lz[h]+((j+1)*b))
min_no_spaces=0
elif min_no_spaces==0:
# print(min_no_spaces)
shotes+=int(zeros[i]/b)
for j in range(int(zeros[i]/b)):
indexes.append(lz[h]+((j+1)*b))
print(shotes)
for i in indexes:
print(i," ",end="",sep="")
``` | output | 1 | 2,962 | 15 | 5,925 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Galya is playing one-dimensional Sea Battle on a 1 × n grid. In this game a ships are placed on the grid. Each of the ships consists of b consecutive cells. No cell can be part of two ships, however, the ships can touch each other.
Galya doesn't know the ships location. She can shoot to some cells and after each shot she is told if that cell was a part of some ship (this case is called "hit") or not (this case is called "miss").
Galya has already made k shots, all of them were misses.
Your task is to calculate the minimum number of cells such that if Galya shoot at all of them, she would hit at least one ship.
It is guaranteed that there is at least one valid ships placement.
Input
The first line contains four positive integers n, a, b, k (1 ≤ n ≤ 2·105, 1 ≤ a, b ≤ n, 0 ≤ k ≤ n - 1) — the length of the grid, the number of ships on the grid, the length of each ship and the number of shots Galya has already made.
The second line contains a string of length n, consisting of zeros and ones. If the i-th character is one, Galya has already made a shot to this cell. Otherwise, she hasn't. It is guaranteed that there are exactly k ones in this string.
Output
In the first line print the minimum number of cells such that if Galya shoot at all of them, she would hit at least one ship.
In the second line print the cells Galya should shoot at.
Each cell should be printed exactly once. You can print the cells in arbitrary order. The cells are numbered from 1 to n, starting from the left.
If there are multiple answers, you can print any of them.
Examples
Input
5 1 2 1
00100
Output
2
4 2
Input
13 3 2 3
1000000010001
Output
2
7 11
Note
There is one ship in the first sample. It can be either to the left or to the right from the shot Galya has already made (the "1" character). So, it is necessary to make two shots: one at the left part, and one at the right part. | instruction | 0 | 2,963 | 15 | 5,926 |
Tags: constructive algorithms, greedy, math
Correct Solution:
```
#from bisect import bisect_left as bl #c++ lowerbound bl(array,element)
#from bisect import bisect_right as br #c++ upperbound br(array,element)
#from __future__ import print_function, division #while using python2
# from itertools import accumulate
# from collections import defaultdict, Counter
def modinv(n,p):
return pow(n,p-2,p)
def main():
#sys.stdin = open('input.txt', 'r')
#sys.stdout = open('output.txt', 'w')
n, a, b, k = [int(x) for x in input().split()]
ip = input()
s = ip.split('1')
segments = []
indices = []
possible = 0
for x in s:
if len(x) > 0:
segments.append(len(x))
possible += (len(x) // b)
if ip[0] == '0':
indices.append(1)
for i in range(1, n):
if ip[i] == '0' and ip[i-1] == '1':
indices.append(i+1)
rem = k
ans = 0
shots = []
# print(segments)
# print(indices)
# print("total possible", possible)
for i in range(len(segments)):
ind = indices[i]
x = segments[i]
if possible - (x // b) >= a:
ans += (x // b)
possible -= (x // b)
j = ind + (b - 1)
for y in range(x//b):
shots.append(j)
j += b
else:
j = ind + (b-1)
while possible - a >= 0:
shots.append(j)
j += b
possible -= 1
ans += 1
print(ans)
print(*shots)
#------------------ Python 2 and 3 footer by Pajenegod and c1729-----------------------------------------
py2 = round(0.5)
if py2:
from future_builtins import ascii, filter, hex, map, oct, zip
range = xrange
import os, sys
from io import IOBase, BytesIO
BUFSIZE = 8192
class FastIO(BytesIO):
newlines = 0
def __init__(self, file):
self._file = file
self._fd = file.fileno()
self.writable = "x" in file.mode or "w" in file.mode
self.write = super(FastIO, self).write if self.writable else None
def _fill(self):
s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.seek((self.tell(), self.seek(0,2), super(FastIO, self).write(s))[0])
return s
def read(self):
while self._fill(): pass
return super(FastIO,self).read()
def readline(self):
while self.newlines == 0:
s = self._fill(); self.newlines = s.count(b"\n") + (not s)
self.newlines -= 1
return super(FastIO, self).readline()
def flush(self):
if self.writable:
os.write(self._fd, self.getvalue())
self.truncate(0), self.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
if py2:
self.write = self.buffer.write
self.read = self.buffer.read
self.readline = self.buffer.readline
else:
self.write = lambda s:self.buffer.write(s.encode('ascii'))
self.read = lambda:self.buffer.read().decode('ascii')
self.readline = lambda:self.buffer.readline().decode('ascii')
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip('\r\n')
if __name__ == '__main__':
main()
``` | output | 1 | 2,963 | 15 | 5,927 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Galya is playing one-dimensional Sea Battle on a 1 × n grid. In this game a ships are placed on the grid. Each of the ships consists of b consecutive cells. No cell can be part of two ships, however, the ships can touch each other.
Galya doesn't know the ships location. She can shoot to some cells and after each shot she is told if that cell was a part of some ship (this case is called "hit") or not (this case is called "miss").
Galya has already made k shots, all of them were misses.
Your task is to calculate the minimum number of cells such that if Galya shoot at all of them, she would hit at least one ship.
It is guaranteed that there is at least one valid ships placement.
Input
The first line contains four positive integers n, a, b, k (1 ≤ n ≤ 2·105, 1 ≤ a, b ≤ n, 0 ≤ k ≤ n - 1) — the length of the grid, the number of ships on the grid, the length of each ship and the number of shots Galya has already made.
The second line contains a string of length n, consisting of zeros and ones. If the i-th character is one, Galya has already made a shot to this cell. Otherwise, she hasn't. It is guaranteed that there are exactly k ones in this string.
Output
In the first line print the minimum number of cells such that if Galya shoot at all of them, she would hit at least one ship.
In the second line print the cells Galya should shoot at.
Each cell should be printed exactly once. You can print the cells in arbitrary order. The cells are numbered from 1 to n, starting from the left.
If there are multiple answers, you can print any of them.
Examples
Input
5 1 2 1
00100
Output
2
4 2
Input
13 3 2 3
1000000010001
Output
2
7 11
Note
There is one ship in the first sample. It can be either to the left or to the right from the shot Galya has already made (the "1" character). So, it is necessary to make two shots: one at the left part, and one at the right part.
Submitted Solution:
```
from collections import deque
n, a, b, k = map(int, input().split())
s = input()
start = False
cnt = 0
arr = []
idx = -1
for i in range(n):
if(s[i] == "0"):
if(start):
cnt += 1
else:
start = True
idx = i
cnt = 1
else:
if(start):
start = False
arr.append([cnt, idx])
cnt = 0
if(cnt):
arr.append([cnt, idx])
divides = deque([])
for i in range(len(arr)):
if(arr[i][0] % b == 0):
divides.append(arr[i])
else:
divides.appendleft(arr[i])
pos = 0
# print(divides)
while(a != 1):
if(divides[pos][0] >= b):
divides[pos][0] -= b
divides[pos][1] += b
a -= 1
else:
pos += 1
ans = 0
at = []
# print(divides)
for i in range(len(arr)):
if(divides[i][0]):
times = int(divides[i][0]//b)
ans += times
start = divides[i][1] + b - 1
while(times):
at.append(start+1)
start += b
times -= 1
print(ans)
print(*at)
``` | instruction | 0 | 2,964 | 15 | 5,928 |
Yes | output | 1 | 2,964 | 15 | 5,929 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Galya is playing one-dimensional Sea Battle on a 1 × n grid. In this game a ships are placed on the grid. Each of the ships consists of b consecutive cells. No cell can be part of two ships, however, the ships can touch each other.
Galya doesn't know the ships location. She can shoot to some cells and after each shot she is told if that cell was a part of some ship (this case is called "hit") or not (this case is called "miss").
Galya has already made k shots, all of them were misses.
Your task is to calculate the minimum number of cells such that if Galya shoot at all of them, she would hit at least one ship.
It is guaranteed that there is at least one valid ships placement.
Input
The first line contains four positive integers n, a, b, k (1 ≤ n ≤ 2·105, 1 ≤ a, b ≤ n, 0 ≤ k ≤ n - 1) — the length of the grid, the number of ships on the grid, the length of each ship and the number of shots Galya has already made.
The second line contains a string of length n, consisting of zeros and ones. If the i-th character is one, Galya has already made a shot to this cell. Otherwise, she hasn't. It is guaranteed that there are exactly k ones in this string.
Output
In the first line print the minimum number of cells such that if Galya shoot at all of them, she would hit at least one ship.
In the second line print the cells Galya should shoot at.
Each cell should be printed exactly once. You can print the cells in arbitrary order. The cells are numbered from 1 to n, starting from the left.
If there are multiple answers, you can print any of them.
Examples
Input
5 1 2 1
00100
Output
2
4 2
Input
13 3 2 3
1000000010001
Output
2
7 11
Note
There is one ship in the first sample. It can be either to the left or to the right from the shot Galya has already made (the "1" character). So, it is necessary to make two shots: one at the left part, and one at the right part.
Submitted Solution:
```
# Why do we fall ? So we can learn to pick ourselves up.
from itertools import groupby
n,a,b,k = map(int,input().split())
s = input()
sg = [list(g) for s,g in groupby(s)]
ll = 0
hits = []
for i in range(0,len(sg)):
if sg[i][0] == '0' and len(sg[i]) >= b:
for hit in range(b-1,len(sg[i]),b):
hits.append(hit+ll+1)
ll += len(sg[i])
else:
ll += len(sg[i])
# print(hits)
hits = hits[a-1:]
print(len(hits))
print(*hits)
"""
13 3 2 3
1000000010001
15 3 2 3
1000000000010001
"""
``` | instruction | 0 | 2,965 | 15 | 5,930 |
Yes | output | 1 | 2,965 | 15 | 5,931 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Galya is playing one-dimensional Sea Battle on a 1 × n grid. In this game a ships are placed on the grid. Each of the ships consists of b consecutive cells. No cell can be part of two ships, however, the ships can touch each other.
Galya doesn't know the ships location. She can shoot to some cells and after each shot she is told if that cell was a part of some ship (this case is called "hit") or not (this case is called "miss").
Galya has already made k shots, all of them were misses.
Your task is to calculate the minimum number of cells such that if Galya shoot at all of them, she would hit at least one ship.
It is guaranteed that there is at least one valid ships placement.
Input
The first line contains four positive integers n, a, b, k (1 ≤ n ≤ 2·105, 1 ≤ a, b ≤ n, 0 ≤ k ≤ n - 1) — the length of the grid, the number of ships on the grid, the length of each ship and the number of shots Galya has already made.
The second line contains a string of length n, consisting of zeros and ones. If the i-th character is one, Galya has already made a shot to this cell. Otherwise, she hasn't. It is guaranteed that there are exactly k ones in this string.
Output
In the first line print the minimum number of cells such that if Galya shoot at all of them, she would hit at least one ship.
In the second line print the cells Galya should shoot at.
Each cell should be printed exactly once. You can print the cells in arbitrary order. The cells are numbered from 1 to n, starting from the left.
If there are multiple answers, you can print any of them.
Examples
Input
5 1 2 1
00100
Output
2
4 2
Input
13 3 2 3
1000000010001
Output
2
7 11
Note
There is one ship in the first sample. It can be either to the left or to the right from the shot Galya has already made (the "1" character). So, it is necessary to make two shots: one at the left part, and one at the right part.
Submitted Solution:
```
n,a,b,k=map(int,input().split())
A=input()
B=A.split('1')
C=[]
l=1
for i in B:
if len(i)>=b:
for j in range(b-1,len(i),b):
C.append(j+l)
l+=len(i)+1
C=C[:len(C)-a+1]
print(len(C))
print(' '.join(list(map(str,C))))
``` | instruction | 0 | 2,966 | 15 | 5,932 |
Yes | output | 1 | 2,966 | 15 | 5,933 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Galya is playing one-dimensional Sea Battle on a 1 × n grid. In this game a ships are placed on the grid. Each of the ships consists of b consecutive cells. No cell can be part of two ships, however, the ships can touch each other.
Galya doesn't know the ships location. She can shoot to some cells and after each shot she is told if that cell was a part of some ship (this case is called "hit") or not (this case is called "miss").
Galya has already made k shots, all of them were misses.
Your task is to calculate the minimum number of cells such that if Galya shoot at all of them, she would hit at least one ship.
It is guaranteed that there is at least one valid ships placement.
Input
The first line contains four positive integers n, a, b, k (1 ≤ n ≤ 2·105, 1 ≤ a, b ≤ n, 0 ≤ k ≤ n - 1) — the length of the grid, the number of ships on the grid, the length of each ship and the number of shots Galya has already made.
The second line contains a string of length n, consisting of zeros and ones. If the i-th character is one, Galya has already made a shot to this cell. Otherwise, she hasn't. It is guaranteed that there are exactly k ones in this string.
Output
In the first line print the minimum number of cells such that if Galya shoot at all of them, she would hit at least one ship.
In the second line print the cells Galya should shoot at.
Each cell should be printed exactly once. You can print the cells in arbitrary order. The cells are numbered from 1 to n, starting from the left.
If there are multiple answers, you can print any of them.
Examples
Input
5 1 2 1
00100
Output
2
4 2
Input
13 3 2 3
1000000010001
Output
2
7 11
Note
There is one ship in the first sample. It can be either to the left or to the right from the shot Galya has already made (the "1" character). So, it is necessary to make two shots: one at the left part, and one at the right part.
Submitted Solution:
```
n, a, b, k = map(int, input().split())
s = input()
ind = 0
ans = []
for i in range(k):
l = s[ind:].find("1")
if (l ) >= b:
ans.append([l , ind, ind + l])
ind += l + 1
if (len(s) - ind ) >= b:
ans.append([len(s) - ind , ind, len(s)])
#print(ans)
aans = []
count = 0
for i in range(len(ans)):
j = ans[i][1] - 1
while j + b < ans[i][2]:
j += b
aans.append(j + 1)
#print(*aans)
l = len(aans) - a + 1
aans =aans[:l]
print(len(aans))
print(*aans)
``` | instruction | 0 | 2,967 | 15 | 5,934 |
Yes | output | 1 | 2,967 | 15 | 5,935 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Galya is playing one-dimensional Sea Battle on a 1 × n grid. In this game a ships are placed on the grid. Each of the ships consists of b consecutive cells. No cell can be part of two ships, however, the ships can touch each other.
Galya doesn't know the ships location. She can shoot to some cells and after each shot she is told if that cell was a part of some ship (this case is called "hit") or not (this case is called "miss").
Galya has already made k shots, all of them were misses.
Your task is to calculate the minimum number of cells such that if Galya shoot at all of them, she would hit at least one ship.
It is guaranteed that there is at least one valid ships placement.
Input
The first line contains four positive integers n, a, b, k (1 ≤ n ≤ 2·105, 1 ≤ a, b ≤ n, 0 ≤ k ≤ n - 1) — the length of the grid, the number of ships on the grid, the length of each ship and the number of shots Galya has already made.
The second line contains a string of length n, consisting of zeros and ones. If the i-th character is one, Galya has already made a shot to this cell. Otherwise, she hasn't. It is guaranteed that there are exactly k ones in this string.
Output
In the first line print the minimum number of cells such that if Galya shoot at all of them, she would hit at least one ship.
In the second line print the cells Galya should shoot at.
Each cell should be printed exactly once. You can print the cells in arbitrary order. The cells are numbered from 1 to n, starting from the left.
If there are multiple answers, you can print any of them.
Examples
Input
5 1 2 1
00100
Output
2
4 2
Input
13 3 2 3
1000000010001
Output
2
7 11
Note
There is one ship in the first sample. It can be either to the left or to the right from the shot Galya has already made (the "1" character). So, it is necessary to make two shots: one at the left part, and one at the right part.
Submitted Solution:
```
n, a, b, k = map(int, input().split())
s, d = 0, []
for i, q in enumerate(input(), 1):
if q == '0': s += 1
else: s = 0
if s == b: d.append(str(i))
m = len(d) - a + 1
print(m, ' '.join(d[:m]))
``` | instruction | 0 | 2,968 | 15 | 5,936 |
No | output | 1 | 2,968 | 15 | 5,937 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Galya is playing one-dimensional Sea Battle on a 1 × n grid. In this game a ships are placed on the grid. Each of the ships consists of b consecutive cells. No cell can be part of two ships, however, the ships can touch each other.
Galya doesn't know the ships location. She can shoot to some cells and after each shot she is told if that cell was a part of some ship (this case is called "hit") or not (this case is called "miss").
Galya has already made k shots, all of them were misses.
Your task is to calculate the minimum number of cells such that if Galya shoot at all of them, she would hit at least one ship.
It is guaranteed that there is at least one valid ships placement.
Input
The first line contains four positive integers n, a, b, k (1 ≤ n ≤ 2·105, 1 ≤ a, b ≤ n, 0 ≤ k ≤ n - 1) — the length of the grid, the number of ships on the grid, the length of each ship and the number of shots Galya has already made.
The second line contains a string of length n, consisting of zeros and ones. If the i-th character is one, Galya has already made a shot to this cell. Otherwise, she hasn't. It is guaranteed that there are exactly k ones in this string.
Output
In the first line print the minimum number of cells such that if Galya shoot at all of them, she would hit at least one ship.
In the second line print the cells Galya should shoot at.
Each cell should be printed exactly once. You can print the cells in arbitrary order. The cells are numbered from 1 to n, starting from the left.
If there are multiple answers, you can print any of them.
Examples
Input
5 1 2 1
00100
Output
2
4 2
Input
13 3 2 3
1000000010001
Output
2
7 11
Note
There is one ship in the first sample. It can be either to the left or to the right from the shot Galya has already made (the "1" character). So, it is necessary to make two shots: one at the left part, and one at the right part.
Submitted Solution:
```
n, a, b, k = map(int, input().split()) #a de dimensiune b
s = input()
v, u = [0]*(n+1), [0]*(n+1) #v = unde NU poate sa inceapa nava
for i in range(n):
if s[i] == '1':
u[max(0, i-b+1)] += 1
u[min(n, i+1)] -= 1
for i in range(n):
if i > 0:
u[i] += u[i-1]
v[i] = min(u[i], 1)
i, itv, tot = 0, [], 0
while i < n:
if v[i] == 1:
i += 1
else:
j = i+1
while j < n and v[j] == 0:
j += 1
itv.append([j-i, i+1])
tot += (j-i+b-1)//b #tot = nr maxim de barci ce pot exista
i = j
mx = 0
for lg in itv:
mx = max(mx, max(0, a-tot + (lg[0]+b-1)//b))
sol = []
if mx > 0:
ans, ind = 1<<30, -1
for i in range(len(itv)):
lg = itv[i]
mb = max(0, a-tot + (lg[0]+b-1)//b) #nr minim de barci ce pot exista in intervalul lg
if mb > 0:
lgn = lg[0] - b*max(0, mb-1) #lungime noua: in cel mai rau caz ai mb-1 barci una langa alta in stanga si trebuie sa o cauti pe a mb-a in restul de lungime lgn
if ans > (lgn+b-1)//b:
ans = (lgn+b-1)//b
ind = i
lg = itv[ind]
mb = max(0, a-tot + (lg[0]+b-1)//b)
i = min(lg[1]+lg[0]-1, lg[1] + b*max(0, mb-1) + b-1)
while i < lg[1]+lg[0]:
sol.append(min(i, lg[1]+lg[0]-1))
i += b
else:
ans = 0
for lg in itv:
ans += (lg[0]+b-1)//b
i = min(lg[1]+lg[0]-1, lg[1] + b-1)
while i < lg[1]+lg[0]:
sol.append(min(i, lg[1]+lg[0]-1))
i += b
print(ans)
for x in sol:
print(x, end = ' ')
``` | instruction | 0 | 2,969 | 15 | 5,938 |
No | output | 1 | 2,969 | 15 | 5,939 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Galya is playing one-dimensional Sea Battle on a 1 × n grid. In this game a ships are placed on the grid. Each of the ships consists of b consecutive cells. No cell can be part of two ships, however, the ships can touch each other.
Galya doesn't know the ships location. She can shoot to some cells and after each shot she is told if that cell was a part of some ship (this case is called "hit") or not (this case is called "miss").
Galya has already made k shots, all of them were misses.
Your task is to calculate the minimum number of cells such that if Galya shoot at all of them, she would hit at least one ship.
It is guaranteed that there is at least one valid ships placement.
Input
The first line contains four positive integers n, a, b, k (1 ≤ n ≤ 2·105, 1 ≤ a, b ≤ n, 0 ≤ k ≤ n - 1) — the length of the grid, the number of ships on the grid, the length of each ship and the number of shots Galya has already made.
The second line contains a string of length n, consisting of zeros and ones. If the i-th character is one, Galya has already made a shot to this cell. Otherwise, she hasn't. It is guaranteed that there are exactly k ones in this string.
Output
In the first line print the minimum number of cells such that if Galya shoot at all of them, she would hit at least one ship.
In the second line print the cells Galya should shoot at.
Each cell should be printed exactly once. You can print the cells in arbitrary order. The cells are numbered from 1 to n, starting from the left.
If there are multiple answers, you can print any of them.
Examples
Input
5 1 2 1
00100
Output
2
4 2
Input
13 3 2 3
1000000010001
Output
2
7 11
Note
There is one ship in the first sample. It can be either to the left or to the right from the shot Galya has already made (the "1" character). So, it is necessary to make two shots: one at the left part, and one at the right part.
Submitted Solution:
```
'''input
5 1 2 1
00100
'''
from sys import stdin
import collections
import math
def get_working(string):
aux = []
first = None
if string[0] == 1:
pass
else:
first = -1
for i in range(len(string)):
if string[i] == '1':
if first == None:
first = i
elif first != None:
aux.append([first, i, (i - first - 1)])
first = i
if first != None:
aux.append([first, len(string), (len(string) - first) - 1])
return aux
# main starts
n, a, b, k = list(map(int, stdin.readline().split()))
string = list(stdin.readline().strip())
ans = 0
working = get_working(string)
# print(working)
current = a
flag = 0
for i in working:
if flag == 1:
break
start, end, gap = i
j = end - 1
if gap//b > 0:
while j > start:
if current == 0:
flag = 1
break
if (j - start)// b > 0:
for k in range(j, j - b, -1):
string[k] = '2'
j -= b
current -= 1
else:
break
ans = []
count = 0
for i in range(len(string)):
if string[i] == '0':
if i > 0 and string[i - 1] == '0':
count += 1
else:
count = 1
if count == b:
string[i] = 'b'
ans.append(i + 1)
count = 0
for i in range(len(string)):
if string[i] == '2':
if i > 0 and string[i - 1] == '2':
count += 1
else:
count = 1
if count == b:
string[i] = 'b'
ans.append(i + 1)
count = 0
break
# print(string)
print(len(ans))
print(*ans)
# print(ans)
# for i in range(n):
# if string[i] == 'b':
# print(i + 1, end = ' ')
``` | instruction | 0 | 2,970 | 15 | 5,940 |
No | output | 1 | 2,970 | 15 | 5,941 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Galya is playing one-dimensional Sea Battle on a 1 × n grid. In this game a ships are placed on the grid. Each of the ships consists of b consecutive cells. No cell can be part of two ships, however, the ships can touch each other.
Galya doesn't know the ships location. She can shoot to some cells and after each shot she is told if that cell was a part of some ship (this case is called "hit") or not (this case is called "miss").
Galya has already made k shots, all of them were misses.
Your task is to calculate the minimum number of cells such that if Galya shoot at all of them, she would hit at least one ship.
It is guaranteed that there is at least one valid ships placement.
Input
The first line contains four positive integers n, a, b, k (1 ≤ n ≤ 2·105, 1 ≤ a, b ≤ n, 0 ≤ k ≤ n - 1) — the length of the grid, the number of ships on the grid, the length of each ship and the number of shots Galya has already made.
The second line contains a string of length n, consisting of zeros and ones. If the i-th character is one, Galya has already made a shot to this cell. Otherwise, she hasn't. It is guaranteed that there are exactly k ones in this string.
Output
In the first line print the minimum number of cells such that if Galya shoot at all of them, she would hit at least one ship.
In the second line print the cells Galya should shoot at.
Each cell should be printed exactly once. You can print the cells in arbitrary order. The cells are numbered from 1 to n, starting from the left.
If there are multiple answers, you can print any of them.
Examples
Input
5 1 2 1
00100
Output
2
4 2
Input
13 3 2 3
1000000010001
Output
2
7 11
Note
There is one ship in the first sample. It can be either to the left or to the right from the shot Galya has already made (the "1" character). So, it is necessary to make two shots: one at the left part, and one at the right part.
Submitted Solution:
```
from collections import deque
n, a, b, k = map(int, input().split())
s = input()
start = False
cnt = 0
arr = []
idx = -1
for i in range(n):
if(s[i] == "0"):
if(start):
cnt += 1
else:
start = True
idx = i
cnt = 1
else:
if(start):
start = False
arr.append([cnt, idx])
cnt = 0
if(cnt):
arr.append([cnt, idx])
divides = deque([])
for i in range(len(arr)):
if(arr[i][0] % b == 0):
divides.appendleft(arr[i])
else:
divides.append(arr[i])
pos = 0
while(a != 1):
if(divides[pos][0] >= b):
divides[pos][0] -= b
divides[pos][1] += b
else:
pos += 1
a -= 1
ans = 0
at = []
for i in range(len(arr)):
if(divides[i][0]):
times = int(divides[i][0]//b)
ans += times
start = divides[i][1] + b - 1
while(times):
at.append(start+1)
start += b
times -= 1
print(ans)
print(*at)
``` | instruction | 0 | 2,971 | 15 | 5,942 |
No | output | 1 | 2,971 | 15 | 5,943 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.