message stringlengths 2 39.6k | message_type stringclasses 2 values | message_id int64 0 1 | conversation_id int64 450 109k | cluster float64 2 2 | __index_level_0__ int64 900 217k |
|---|---|---|---|---|---|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Problem
Great Demon King Megumi wants to defeat the $ N $ hero who lives on the ground.
Megumi can cast explosion magic up to $ M $ times.
Explosion magic is magic that extinguishes heroes who exist within a radius of $ r $ around arbitrary coordinates.
The hero is very thin, so you don't have to consider the size.
All $ M $ explosion spells shall be cast with the same radius.
I decided to use the magic of the minimum radius necessary to annihilate the hero.
Minimize the size of the explosive magic radius.
Constraints
The input satisfies the following conditions.
* $ 1 \ leq M \ leq N \ leq 14 $
* $ 0 \ leq x_i $, $ y_i \ leq 10 ^ 5 $
Input
$ N $ $ M $
$ x_1 $ $ y_1 $
...
$ x_N $ $ y_N $
The input is given in the following format.
The number of heroes $ N $ and the number of explosions to cast $ M $ are given as integers on the first line.
From the second line onward, the coordinates $ x_i $ $, $ $ y_i $ of each hero $ i $ are given as integers.
Output
Output the minimum value of the explosive magic radius as a real number.
Must not contain absolute error greater than $ 10 ^ {-3} $.
Examples
Input
5 2
0 0
5 5
10 10
100 100
200 200
Output
70.710678118755
Input
10 5
321 675
4312 6534
312 532
412 6543
21 43
654 321
543 0
32 5
41 76
5 1
Output
169.824909833728
Input
14 3
312 342
4893 432
321 4
389 4
23 543
0 0
1 1
2 2
432 12
435 32
1 5
2 10
100 100
20 50
Output
218.087711712613
Input
5 2
0 0
0 0
0 0
0 0
0 0
Output
0.000000000001
Submitted Solution:
```
N, M = map(int, input().split())
PS = [list(map(int, input().split())) for i in range(N)]
from itertools import combinations
from math import sqrt
def dist(p):
x, y = p
return x**2 + y**2
def dist2(p, q):
x0, y0 = p; x1, y1 = q
return (x0 - x1)**2 + (y0 - y1)**2
def cross(p0, p1):
x0, y0 = p0; x1, y1 = p1
return x0*y1 - x1*y0
memo = {}
EPS = 1e-8
ALL = 2**N-1
def dfs(state, cnt):
key = (state, cnt)
if key in memo:
return memo[key]
if state == ALL:
return 0.
if cnt == 0:
return 1e18
res = 0.
P = []
for i in range(N):
if not (state >> i) & 1:
P.append(i)
l = len(P)
if l <= cnt:
return 0.
if l == 2:
return dist2(PS[P[0]], PS[P[1]])
res = 1e18
for i, j in combinations(P, 2):
p0 = x0, y0 = PS[i]
p1 = x1, y1 = PS[j]
a = (x0+x1)/2; b = (y0+y1)/2; r = ((x0 - x1)/2)**2 + ((y0 - y1)/2)**2
cont = 0
for l in P:
x, y = PS[l]
if (x-a)**2 + (y-b)**2 <= r + EPS:
cont |= 1 << l
res = min(res, max(r, dfs(state | cont, cnt-1)))
for p in combinations(P, 3):
i, j, k = p
det = cross(PS[i], PS[j]) + cross(PS[j], PS[k]) + cross(PS[k], PS[i])
if det == 0:
continue
D0 = -dist(PS[i]); D1 = -dist(PS[j]); D2 = -dist(PS[k])
R = []
for l in [0, -1, 1]:
p0 = x0, y0 = PS[p[l]]
p1 = x1, y1 = PS[p[l+1]]
R.append((y0-y1)*D0 - (x0-x1)*D1 + cross(p0, p1)*D2)
a, b, c = R
cont = 0
r = -c-(a/2)**2-(b/2)**4
for l in P:
x, y = PS[l]
if (x+a/2)**2 + (y+b/2)**2 <= r + EPS:
cont |= 1 << l
res = min(res, max(r, dfs(state | cont, cnt-1)))
memo[key] = res
return res
print(sqrt(dfs(0, M)))
``` | instruction | 0 | 47,903 | 2 | 95,806 |
No | output | 1 | 47,903 | 2 | 95,807 |
Provide tags and a correct Python 3 solution for this coding contest problem.
For some reason in many American cartoons anvils fall from time to time onto heroes' heads. Of course, safes, wardrobes, cruisers, planes fall sometimes too... But anvils do so most of all.
Anvils come in different sizes and shapes. Quite often they get the hero stuck deep in the ground. But have you ever thought who throws anvils from the sky? From what height? We are sure that such questions have never troubled you!
It turns out that throwing an anvil properly is not an easy task at all. Let's describe one of the most popular anvil throwing models.
Let the height p of the potential victim vary in the range [0;a] and the direction of the wind q vary in the range [ - b;b]. p and q could be any real (floating) numbers. Then we can assume that the anvil will fit the toon's head perfectly only if the following equation has at least one real root:
<image>
Determine the probability with which an aim can be successfully hit by an anvil.
You can assume that the p and q coefficients are chosen equiprobably and independently in their ranges.
Input
The first line contains integer t (1 β€ t β€ 10000) β amount of testcases.
Each of the following t lines contain two space-separated integers a and b (0 β€ a, b β€ 106).
Pretests contain all the tests with 0 < a < 10, 0 β€ b < 10.
Output
Print t lines β the probability of a successful anvil hit for each testcase. The absolute or relative error of the answer should not exceed 10 - 6.
Examples
Input
2
4 2
1 2
Output
0.6250000000
0.5312500000 | instruction | 0 | 48,466 | 2 | 96,932 |
Tags: math, probabilities
Correct Solution:
```
def li():
return list(map(int, input().split(" ")))
for _ in range(int(input())):
a, b=li()
if b != 0 and a != 0:
s = (max(0, a-4*b) + a)/2
s*=min((a/4), b)
ans = 1/2 + s/(2*a*b)
print("{:.8f}".format(ans))
elif b == 0:
print(1)
else:
print(0.5)
``` | output | 1 | 48,466 | 2 | 96,933 |
Provide tags and a correct Python 3 solution for this coding contest problem.
For some reason in many American cartoons anvils fall from time to time onto heroes' heads. Of course, safes, wardrobes, cruisers, planes fall sometimes too... But anvils do so most of all.
Anvils come in different sizes and shapes. Quite often they get the hero stuck deep in the ground. But have you ever thought who throws anvils from the sky? From what height? We are sure that such questions have never troubled you!
It turns out that throwing an anvil properly is not an easy task at all. Let's describe one of the most popular anvil throwing models.
Let the height p of the potential victim vary in the range [0;a] and the direction of the wind q vary in the range [ - b;b]. p and q could be any real (floating) numbers. Then we can assume that the anvil will fit the toon's head perfectly only if the following equation has at least one real root:
<image>
Determine the probability with which an aim can be successfully hit by an anvil.
You can assume that the p and q coefficients are chosen equiprobably and independently in their ranges.
Input
The first line contains integer t (1 β€ t β€ 10000) β amount of testcases.
Each of the following t lines contain two space-separated integers a and b (0 β€ a, b β€ 106).
Pretests contain all the tests with 0 < a < 10, 0 β€ b < 10.
Output
Print t lines β the probability of a successful anvil hit for each testcase. The absolute or relative error of the answer should not exceed 10 - 6.
Examples
Input
2
4 2
1 2
Output
0.6250000000
0.5312500000 | instruction | 0 | 48,467 | 2 | 96,934 |
Tags: math, probabilities
Correct Solution:
```
for i in range(int(input())):print("%.8f"%(lambda a,b:1 if a==0==b else (a/b/16+1/2)if b>a/4 else(1-b/a))(*list(map(int,input().split()))[0:2]))
``` | output | 1 | 48,467 | 2 | 96,935 |
Provide tags and a correct Python 3 solution for this coding contest problem.
For some reason in many American cartoons anvils fall from time to time onto heroes' heads. Of course, safes, wardrobes, cruisers, planes fall sometimes too... But anvils do so most of all.
Anvils come in different sizes and shapes. Quite often they get the hero stuck deep in the ground. But have you ever thought who throws anvils from the sky? From what height? We are sure that such questions have never troubled you!
It turns out that throwing an anvil properly is not an easy task at all. Let's describe one of the most popular anvil throwing models.
Let the height p of the potential victim vary in the range [0;a] and the direction of the wind q vary in the range [ - b;b]. p and q could be any real (floating) numbers. Then we can assume that the anvil will fit the toon's head perfectly only if the following equation has at least one real root:
<image>
Determine the probability with which an aim can be successfully hit by an anvil.
You can assume that the p and q coefficients are chosen equiprobably and independently in their ranges.
Input
The first line contains integer t (1 β€ t β€ 10000) β amount of testcases.
Each of the following t lines contain two space-separated integers a and b (0 β€ a, b β€ 106).
Pretests contain all the tests with 0 < a < 10, 0 β€ b < 10.
Output
Print t lines β the probability of a successful anvil hit for each testcase. The absolute or relative error of the answer should not exceed 10 - 6.
Examples
Input
2
4 2
1 2
Output
0.6250000000
0.5312500000 | instruction | 0 | 48,468 | 2 | 96,936 |
Tags: math, probabilities
Correct Solution:
```
for i in range(int(input())):
a, b = map(int, input().split())
print(0.5 + a / (b << 4) if 4 * b > a else 1 - b / a if a else 1)
# Made By Mostafa_Khaled
``` | output | 1 | 48,468 | 2 | 96,937 |
Provide tags and a correct Python 3 solution for this coding contest problem.
For some reason in many American cartoons anvils fall from time to time onto heroes' heads. Of course, safes, wardrobes, cruisers, planes fall sometimes too... But anvils do so most of all.
Anvils come in different sizes and shapes. Quite often they get the hero stuck deep in the ground. But have you ever thought who throws anvils from the sky? From what height? We are sure that such questions have never troubled you!
It turns out that throwing an anvil properly is not an easy task at all. Let's describe one of the most popular anvil throwing models.
Let the height p of the potential victim vary in the range [0;a] and the direction of the wind q vary in the range [ - b;b]. p and q could be any real (floating) numbers. Then we can assume that the anvil will fit the toon's head perfectly only if the following equation has at least one real root:
<image>
Determine the probability with which an aim can be successfully hit by an anvil.
You can assume that the p and q coefficients are chosen equiprobably and independently in their ranges.
Input
The first line contains integer t (1 β€ t β€ 10000) β amount of testcases.
Each of the following t lines contain two space-separated integers a and b (0 β€ a, b β€ 106).
Pretests contain all the tests with 0 < a < 10, 0 β€ b < 10.
Output
Print t lines β the probability of a successful anvil hit for each testcase. The absolute or relative error of the answer should not exceed 10 - 6.
Examples
Input
2
4 2
1 2
Output
0.6250000000
0.5312500000 | instruction | 0 | 48,469 | 2 | 96,938 |
Tags: math, probabilities
Correct Solution:
```
from fractions import Fraction
t = int(input())
for _ in range(t):
a, b = map(lambda x: Fraction(x), input().split(' '))
if b == 0:
print(1)
continue
elif a == 0:
print(0.5)
continue
up = a * (b + b + a / 4) / 2 - max(0, a - 4 * b) * (a / 4 - b) / 2
down = a * 2 * b
print(float(up/down))
``` | output | 1 | 48,469 | 2 | 96,939 |
Provide tags and a correct Python 3 solution for this coding contest problem.
For some reason in many American cartoons anvils fall from time to time onto heroes' heads. Of course, safes, wardrobes, cruisers, planes fall sometimes too... But anvils do so most of all.
Anvils come in different sizes and shapes. Quite often they get the hero stuck deep in the ground. But have you ever thought who throws anvils from the sky? From what height? We are sure that such questions have never troubled you!
It turns out that throwing an anvil properly is not an easy task at all. Let's describe one of the most popular anvil throwing models.
Let the height p of the potential victim vary in the range [0;a] and the direction of the wind q vary in the range [ - b;b]. p and q could be any real (floating) numbers. Then we can assume that the anvil will fit the toon's head perfectly only if the following equation has at least one real root:
<image>
Determine the probability with which an aim can be successfully hit by an anvil.
You can assume that the p and q coefficients are chosen equiprobably and independently in their ranges.
Input
The first line contains integer t (1 β€ t β€ 10000) β amount of testcases.
Each of the following t lines contain two space-separated integers a and b (0 β€ a, b β€ 106).
Pretests contain all the tests with 0 < a < 10, 0 β€ b < 10.
Output
Print t lines β the probability of a successful anvil hit for each testcase. The absolute or relative error of the answer should not exceed 10 - 6.
Examples
Input
2
4 2
1 2
Output
0.6250000000
0.5312500000 | instruction | 0 | 48,470 | 2 | 96,940 |
Tags: math, probabilities
Correct Solution:
```
t = int(input())
for _ in range(t):
a, b = map(int, input().split())
if a == 0 and b == 0:
print(1)
elif a == 0:
print(0.5)
elif b == 0:
print(1)
elif a > 4 * b:
print('%.10f' % ((a - b) / a))
else:
print('%.10f' % (a / 16 / b + 0.5))
``` | output | 1 | 48,470 | 2 | 96,941 |
Provide tags and a correct Python 3 solution for this coding contest problem.
For some reason in many American cartoons anvils fall from time to time onto heroes' heads. Of course, safes, wardrobes, cruisers, planes fall sometimes too... But anvils do so most of all.
Anvils come in different sizes and shapes. Quite often they get the hero stuck deep in the ground. But have you ever thought who throws anvils from the sky? From what height? We are sure that such questions have never troubled you!
It turns out that throwing an anvil properly is not an easy task at all. Let's describe one of the most popular anvil throwing models.
Let the height p of the potential victim vary in the range [0;a] and the direction of the wind q vary in the range [ - b;b]. p and q could be any real (floating) numbers. Then we can assume that the anvil will fit the toon's head perfectly only if the following equation has at least one real root:
<image>
Determine the probability with which an aim can be successfully hit by an anvil.
You can assume that the p and q coefficients are chosen equiprobably and independently in their ranges.
Input
The first line contains integer t (1 β€ t β€ 10000) β amount of testcases.
Each of the following t lines contain two space-separated integers a and b (0 β€ a, b β€ 106).
Pretests contain all the tests with 0 < a < 10, 0 β€ b < 10.
Output
Print t lines β the probability of a successful anvil hit for each testcase. The absolute or relative error of the answer should not exceed 10 - 6.
Examples
Input
2
4 2
1 2
Output
0.6250000000
0.5312500000 | instruction | 0 | 48,471 | 2 | 96,942 |
Tags: math, probabilities
Correct Solution:
```
def f(p, q):
if p == 0 and q == 0:
return 1
if p == 0:
return 0.5
if q == 0:
return 1
#p 0 -> a
#q -b -> b
if (q*4 <= p):
return 1-(q*2*q)/(2*p*q)
else:
return 1-(q - p/4 + q) * p /(4*p*q)
for i in range(int(input())):
p, q = map(int, input().split(' '))
print(f(p,q))
``` | output | 1 | 48,471 | 2 | 96,943 |
Provide tags and a correct Python 3 solution for this coding contest problem.
For some reason in many American cartoons anvils fall from time to time onto heroes' heads. Of course, safes, wardrobes, cruisers, planes fall sometimes too... But anvils do so most of all.
Anvils come in different sizes and shapes. Quite often they get the hero stuck deep in the ground. But have you ever thought who throws anvils from the sky? From what height? We are sure that such questions have never troubled you!
It turns out that throwing an anvil properly is not an easy task at all. Let's describe one of the most popular anvil throwing models.
Let the height p of the potential victim vary in the range [0;a] and the direction of the wind q vary in the range [ - b;b]. p and q could be any real (floating) numbers. Then we can assume that the anvil will fit the toon's head perfectly only if the following equation has at least one real root:
<image>
Determine the probability with which an aim can be successfully hit by an anvil.
You can assume that the p and q coefficients are chosen equiprobably and independently in their ranges.
Input
The first line contains integer t (1 β€ t β€ 10000) β amount of testcases.
Each of the following t lines contain two space-separated integers a and b (0 β€ a, b β€ 106).
Pretests contain all the tests with 0 < a < 10, 0 β€ b < 10.
Output
Print t lines β the probability of a successful anvil hit for each testcase. The absolute or relative error of the answer should not exceed 10 - 6.
Examples
Input
2
4 2
1 2
Output
0.6250000000
0.5312500000 | instruction | 0 | 48,472 | 2 | 96,944 |
Tags: math, probabilities
Correct Solution:
```
t = int( input() )
for i in range( t ):
a, b = list( map( int, input().split() ) )
if a == 0 and b == 0:
print( 1 )
elif a == 0:
print( 0.5 )
elif b == 0:
print( 1 )
else:
if a < 4*b:
ans = (b*a + a*a / 8) / (2*a*b)
else:
ans = 1 - b/a
print( ans )
``` | output | 1 | 48,472 | 2 | 96,945 |
Provide tags and a correct Python 3 solution for this coding contest problem.
For some reason in many American cartoons anvils fall from time to time onto heroes' heads. Of course, safes, wardrobes, cruisers, planes fall sometimes too... But anvils do so most of all.
Anvils come in different sizes and shapes. Quite often they get the hero stuck deep in the ground. But have you ever thought who throws anvils from the sky? From what height? We are sure that such questions have never troubled you!
It turns out that throwing an anvil properly is not an easy task at all. Let's describe one of the most popular anvil throwing models.
Let the height p of the potential victim vary in the range [0;a] and the direction of the wind q vary in the range [ - b;b]. p and q could be any real (floating) numbers. Then we can assume that the anvil will fit the toon's head perfectly only if the following equation has at least one real root:
<image>
Determine the probability with which an aim can be successfully hit by an anvil.
You can assume that the p and q coefficients are chosen equiprobably and independently in their ranges.
Input
The first line contains integer t (1 β€ t β€ 10000) β amount of testcases.
Each of the following t lines contain two space-separated integers a and b (0 β€ a, b β€ 106).
Pretests contain all the tests with 0 < a < 10, 0 β€ b < 10.
Output
Print t lines β the probability of a successful anvil hit for each testcase. The absolute or relative error of the answer should not exceed 10 - 6.
Examples
Input
2
4 2
1 2
Output
0.6250000000
0.5312500000 | instruction | 0 | 48,473 | 2 | 96,946 |
Tags: math, probabilities
Correct Solution:
```
#Code by Sounak, IIESTS
#------------------------------warmup----------------------------
import os
import sys
import math
from io import BytesIO, IOBase
from fractions import Fraction
import collections
from itertools import permutations
from collections import defaultdict
from collections import deque
import threading
threading.stack_size(10**8)
sys.setrecursionlimit(300000)
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")
#-------------------game starts now-----------------------------------------------------
class Factorial:
def __init__(self, MOD):
self.MOD = MOD
self.factorials = [1, 1]
self.invModulos = [0, 1]
self.invFactorial_ = [1, 1]
def calc(self, n):
if n <= -1:
print("Invalid argument to calculate n!")
print("n must be non-negative value. But the argument was " + str(n))
exit()
if n < len(self.factorials):
return self.factorials[n]
nextArr = [0] * (n + 1 - len(self.factorials))
initialI = len(self.factorials)
prev = self.factorials[-1]
m = self.MOD
for i in range(initialI, n + 1):
prev = nextArr[i - initialI] = prev * i % m
self.factorials += nextArr
return self.factorials[n]
def inv(self, n):
if n <= -1:
print("Invalid argument to calculate n^(-1)")
print("n must be non-negative value. But the argument was " + str(n))
exit()
p = self.MOD
pi = n % p
if pi < len(self.invModulos):
return self.invModulos[pi]
nextArr = [0] * (n + 1 - len(self.invModulos))
initialI = len(self.invModulos)
for i in range(initialI, min(p, n + 1)):
next = -self.invModulos[p % i] * (p // i) % p
self.invModulos.append(next)
return self.invModulos[pi]
def invFactorial(self, n):
if n <= -1:
print("Invalid argument to calculate (n^(-1))!")
print("n must be non-negative value. But the argument was " + str(n))
exit()
if n < len(self.invFactorial_):
return self.invFactorial_[n]
self.inv(n) # To make sure already calculated n^-1
nextArr = [0] * (n + 1 - len(self.invFactorial_))
initialI = len(self.invFactorial_)
prev = self.invFactorial_[-1]
p = self.MOD
for i in range(initialI, n + 1):
prev = nextArr[i - initialI] = (prev * self.invModulos[i % p]) % p
self.invFactorial_ += nextArr
return self.invFactorial_[n]
class Combination:
def __init__(self, MOD):
self.MOD = MOD
self.factorial = Factorial(MOD)
def ncr(self, n, k):
if k < 0 or n < k:
return 0
k = min(k, n - k)
f = self.factorial
return f.calc(n) * f.invFactorial(max(n - k, k)) * f.invFactorial(min(k, n - k)) % self.MOD
#-------------------------------------------------------------------------
t = int( input() )
for i in range( t ):
a, b = list( map( int, input().split() ) )
if a == 0 and b == 0:
print( 1 )
elif a == 0:
print( 0.5 )
elif b == 0:
print( 1 )
else:
if a < 4*b:
ans = (b*a + a*a / 8) / (2*a*b)
else:
ans = 1 - b/a
print( ans )
``` | output | 1 | 48,473 | 2 | 96,947 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
For some reason in many American cartoons anvils fall from time to time onto heroes' heads. Of course, safes, wardrobes, cruisers, planes fall sometimes too... But anvils do so most of all.
Anvils come in different sizes and shapes. Quite often they get the hero stuck deep in the ground. But have you ever thought who throws anvils from the sky? From what height? We are sure that such questions have never troubled you!
It turns out that throwing an anvil properly is not an easy task at all. Let's describe one of the most popular anvil throwing models.
Let the height p of the potential victim vary in the range [0;a] and the direction of the wind q vary in the range [ - b;b]. p and q could be any real (floating) numbers. Then we can assume that the anvil will fit the toon's head perfectly only if the following equation has at least one real root:
<image>
Determine the probability with which an aim can be successfully hit by an anvil.
You can assume that the p and q coefficients are chosen equiprobably and independently in their ranges.
Input
The first line contains integer t (1 β€ t β€ 10000) β amount of testcases.
Each of the following t lines contain two space-separated integers a and b (0 β€ a, b β€ 106).
Pretests contain all the tests with 0 < a < 10, 0 β€ b < 10.
Output
Print t lines β the probability of a successful anvil hit for each testcase. The absolute or relative error of the answer should not exceed 10 - 6.
Examples
Input
2
4 2
1 2
Output
0.6250000000
0.5312500000
Submitted Solution:
```
for i in range(int(input())):
a, b = map(int, input().split())
print(0.5 + a / (b << 4) if 4 * b > a else 1 - b / a if a else 1)
``` | instruction | 0 | 48,474 | 2 | 96,948 |
Yes | output | 1 | 48,474 | 2 | 96,949 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
For some reason in many American cartoons anvils fall from time to time onto heroes' heads. Of course, safes, wardrobes, cruisers, planes fall sometimes too... But anvils do so most of all.
Anvils come in different sizes and shapes. Quite often they get the hero stuck deep in the ground. But have you ever thought who throws anvils from the sky? From what height? We are sure that such questions have never troubled you!
It turns out that throwing an anvil properly is not an easy task at all. Let's describe one of the most popular anvil throwing models.
Let the height p of the potential victim vary in the range [0;a] and the direction of the wind q vary in the range [ - b;b]. p and q could be any real (floating) numbers. Then we can assume that the anvil will fit the toon's head perfectly only if the following equation has at least one real root:
<image>
Determine the probability with which an aim can be successfully hit by an anvil.
You can assume that the p and q coefficients are chosen equiprobably and independently in their ranges.
Input
The first line contains integer t (1 β€ t β€ 10000) β amount of testcases.
Each of the following t lines contain two space-separated integers a and b (0 β€ a, b β€ 106).
Pretests contain all the tests with 0 < a < 10, 0 β€ b < 10.
Output
Print t lines β the probability of a successful anvil hit for each testcase. The absolute or relative error of the answer should not exceed 10 - 6.
Examples
Input
2
4 2
1 2
Output
0.6250000000
0.5312500000
Submitted Solution:
```
t = int(input())
for i in range(t):
a, b = input().split()
a = int(a)
b = int(b)
print(0.5 + a / (b << 4) if 4 * b > a else 1 - b / a if a else 1)
``` | instruction | 0 | 48,475 | 2 | 96,950 |
Yes | output | 1 | 48,475 | 2 | 96,951 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
For some reason in many American cartoons anvils fall from time to time onto heroes' heads. Of course, safes, wardrobes, cruisers, planes fall sometimes too... But anvils do so most of all.
Anvils come in different sizes and shapes. Quite often they get the hero stuck deep in the ground. But have you ever thought who throws anvils from the sky? From what height? We are sure that such questions have never troubled you!
It turns out that throwing an anvil properly is not an easy task at all. Let's describe one of the most popular anvil throwing models.
Let the height p of the potential victim vary in the range [0;a] and the direction of the wind q vary in the range [ - b;b]. p and q could be any real (floating) numbers. Then we can assume that the anvil will fit the toon's head perfectly only if the following equation has at least one real root:
<image>
Determine the probability with which an aim can be successfully hit by an anvil.
You can assume that the p and q coefficients are chosen equiprobably and independently in their ranges.
Input
The first line contains integer t (1 β€ t β€ 10000) β amount of testcases.
Each of the following t lines contain two space-separated integers a and b (0 β€ a, b β€ 106).
Pretests contain all the tests with 0 < a < 10, 0 β€ b < 10.
Output
Print t lines β the probability of a successful anvil hit for each testcase. The absolute or relative error of the answer should not exceed 10 - 6.
Examples
Input
2
4 2
1 2
Output
0.6250000000
0.5312500000
Submitted Solution:
```
# ---------------------------iye ha aam zindegi---------------------------------------------
import math
import random
import heapq, bisect
import sys
from collections import deque, defaultdict
from fractions import Fraction
import sys
import threading
from collections import defaultdict
#threading.stack_size(10**8)
mod = 10 ** 9 + 7
mod1 = 998244353
# ------------------------------warmup----------------------------
import os
import sys
from io import BytesIO, IOBase
#sys.setrecursionlimit(300000)
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")
# -------------------game starts now----------------------------------------------------import math
class TreeNode:
def __init__(self, k, v):
self.key = k
self.value = v
self.left = None
self.right = None
self.parent = None
self.height = 1
self.num_left = 1
self.num_total = 1
class AvlTree:
def __init__(self):
self._tree = None
def add(self, k, v):
if not self._tree:
self._tree = TreeNode(k, v)
return
node = self._add(k, v)
if node:
self._rebalance(node)
def _add(self, k, v):
node = self._tree
while node:
if k < node.key:
if node.left:
node = node.left
else:
node.left = TreeNode(k, v)
node.left.parent = node
return node.left
elif node.key < k:
if node.right:
node = node.right
else:
node.right = TreeNode(k, v)
node.right.parent = node
return node.right
else:
node.value = v
return
@staticmethod
def get_height(x):
return x.height if x else 0
@staticmethod
def get_num_total(x):
return x.num_total if x else 0
def _rebalance(self, node):
n = node
while n:
lh = self.get_height(n.left)
rh = self.get_height(n.right)
n.height = max(lh, rh) + 1
balance_factor = lh - rh
n.num_total = 1 + self.get_num_total(n.left) + self.get_num_total(n.right)
n.num_left = 1 + self.get_num_total(n.left)
if balance_factor > 1:
if self.get_height(n.left.left) < self.get_height(n.left.right):
self._rotate_left(n.left)
self._rotate_right(n)
elif balance_factor < -1:
if self.get_height(n.right.right) < self.get_height(n.right.left):
self._rotate_right(n.right)
self._rotate_left(n)
else:
n = n.parent
def _remove_one(self, node):
"""
Side effect!!! Changes node. Node should have exactly one child
"""
replacement = node.left or node.right
if node.parent:
if AvlTree._is_left(node):
node.parent.left = replacement
else:
node.parent.right = replacement
replacement.parent = node.parent
node.parent = None
else:
self._tree = replacement
replacement.parent = None
node.left = None
node.right = None
node.parent = None
self._rebalance(replacement)
def _remove_leaf(self, node):
if node.parent:
if AvlTree._is_left(node):
node.parent.left = None
else:
node.parent.right = None
self._rebalance(node.parent)
else:
self._tree = None
node.parent = None
node.left = None
node.right = None
def remove(self, k):
node = self._get_node(k)
if not node:
return
if AvlTree._is_leaf(node):
self._remove_leaf(node)
return
if node.left and node.right:
nxt = AvlTree._get_next(node)
node.key = nxt.key
node.value = nxt.value
if self._is_leaf(nxt):
self._remove_leaf(nxt)
else:
self._remove_one(nxt)
self._rebalance(node)
else:
self._remove_one(node)
def get(self, k):
node = self._get_node(k)
return node.value if node else -1
def _get_node(self, k):
if not self._tree:
return None
node = self._tree
while node:
if k < node.key:
node = node.left
elif node.key < k:
node = node.right
else:
return node
return None
def get_at(self, pos):
x = pos + 1
node = self._tree
while node:
if x < node.num_left:
node = node.left
elif node.num_left < x:
x -= node.num_left
node = node.right
else:
return (node.key, node.value)
raise IndexError("Out of ranges")
@staticmethod
def _is_left(node):
return node.parent.left and node.parent.left == node
@staticmethod
def _is_leaf(node):
return node.left is None and node.right is None
def _rotate_right(self, node):
if not node.parent:
self._tree = node.left
node.left.parent = None
elif AvlTree._is_left(node):
node.parent.left = node.left
node.left.parent = node.parent
else:
node.parent.right = node.left
node.left.parent = node.parent
bk = node.left.right
node.left.right = node
node.parent = node.left
node.left = bk
if bk:
bk.parent = node
node.height = max(self.get_height(node.left), self.get_height(node.right)) + 1
node.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right)
node.num_left = 1 + self.get_num_total(node.left)
def _rotate_left(self, node):
if not node.parent:
self._tree = node.right
node.right.parent = None
elif AvlTree._is_left(node):
node.parent.left = node.right
node.right.parent = node.parent
else:
node.parent.right = node.right
node.right.parent = node.parent
bk = node.right.left
node.right.left = node
node.parent = node.right
node.right = bk
if bk:
bk.parent = node
node.height = max(self.get_height(node.left), self.get_height(node.right)) + 1
node.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right)
node.num_left = 1 + self.get_num_total(node.left)
@staticmethod
def _get_next(node):
if not node.right:
return node.parent
n = node.right
while n.left:
n = n.left
return n
# -----------------------------------------------binary seacrh tree---------------------------------------
class SegmentTree1:
def __init__(self, data, default=0, func=lambda a, b: max(a , b)):
"""initialize the segment tree with data"""
self._default = default
self._func = func
self._len = len(data)
self._size = _size = 1 << (self._len - 1).bit_length()
self.data = [default] * (2 * _size)
self.data[_size:_size + self._len] = data
for i in reversed(range(_size)):
self.data[i] = func(self.data[i + i], self.data[i + i + 1])
def __delitem__(self, idx):
self[idx] = self._default
def __getitem__(self, idx):
return self.data[idx + self._size]
def __setitem__(self, idx, value):
idx += self._size
self.data[idx] = value
idx >>= 1
while idx:
self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
idx >>= 1
def __len__(self):
return self._len
def query(self, start, stop):
if start == stop:
return self.__getitem__(start)
stop += 1
start += self._size
stop += self._size
res = self._default
while start < stop:
if start & 1:
res = self._func(res, self.data[start])
start += 1
if stop & 1:
stop -= 1
res = self._func(res, self.data[stop])
start >>= 1
stop >>= 1
return res
def __repr__(self):
return "SegmentTree({0})".format(self.data)
# -------------------game starts now----------------------------------------------------import math
class SegmentTree:
def __init__(self, data, default=0, func=lambda a, b:a + b):
"""initialize the segment tree with data"""
self._default = default
self._func = func
self._len = len(data)
self._size = _size = 1 << (self._len - 1).bit_length()
self.data = [default] * (2 * _size)
self.data[_size:_size + self._len] = data
for i in reversed(range(_size)):
self.data[i] = func(self.data[i + i], self.data[i + i + 1])
def __delitem__(self, idx):
self[idx] = self._default
def __getitem__(self, idx):
return self.data[idx + self._size]
def __setitem__(self, idx, value):
idx += self._size
self.data[idx] = value
idx >>= 1
while idx:
self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
idx >>= 1
def __len__(self):
return self._len
def query(self, start, stop):
if start == stop:
return self.__getitem__(start)
stop += 1
start += self._size
stop += self._size
res = self._default
while start < stop:
if start & 1:
res = self._func(res, self.data[start])
start += 1
if stop & 1:
stop -= 1
res = self._func(res, self.data[stop])
start >>= 1
stop >>= 1
return res
def __repr__(self):
return "SegmentTree({0})".format(self.data)
# -------------------------------iye ha chutiya zindegi-------------------------------------
class Factorial:
def __init__(self, MOD):
self.MOD = MOD
self.factorials = [1, 1]
self.invModulos = [0, 1]
self.invFactorial_ = [1, 1]
def calc(self, n):
if n <= -1:
print("Invalid argument to calculate n!")
print("n must be non-negative value. But the argument was " + str(n))
exit()
if n < len(self.factorials):
return self.factorials[n]
nextArr = [0] * (n + 1 - len(self.factorials))
initialI = len(self.factorials)
prev = self.factorials[-1]
m = self.MOD
for i in range(initialI, n + 1):
prev = nextArr[i - initialI] = prev * i % m
self.factorials += nextArr
return self.factorials[n]
def inv(self, n):
if n <= -1:
print("Invalid argument to calculate n^(-1)")
print("n must be non-negative value. But the argument was " + str(n))
exit()
p = self.MOD
pi = n % p
if pi < len(self.invModulos):
return self.invModulos[pi]
nextArr = [0] * (n + 1 - len(self.invModulos))
initialI = len(self.invModulos)
for i in range(initialI, min(p, n + 1)):
next = -self.invModulos[p % i] * (p // i) % p
self.invModulos.append(next)
return self.invModulos[pi]
def invFactorial(self, n):
if n <= -1:
print("Invalid argument to calculate (n^(-1))!")
print("n must be non-negative value. But the argument was " + str(n))
exit()
if n < len(self.invFactorial_):
return self.invFactorial_[n]
self.inv(n) # To make sure already calculated n^-1
nextArr = [0] * (n + 1 - len(self.invFactorial_))
initialI = len(self.invFactorial_)
prev = self.invFactorial_[-1]
p = self.MOD
for i in range(initialI, n + 1):
prev = nextArr[i - initialI] = (prev * self.invModulos[i % p]) % p
self.invFactorial_ += nextArr
return self.invFactorial_[n]
class Combination:
def __init__(self, MOD):
self.MOD = MOD
self.factorial = Factorial(MOD)
def ncr(self, n, k):
if k < 0 or n < k:
return 0
k = min(k, n - k)
f = self.factorial
return f.calc(n) * f.invFactorial(max(n - k, k)) * f.invFactorial(min(k, n - k)) % self.MOD
# --------------------------------------iye ha combinations ka zindegi---------------------------------
def powm(a, n, m):
if a == 1 or n == 0:
return 1
if n % 2 == 0:
s = powm(a, n // 2, m)
return s * s % m
else:
return a * powm(a, n - 1, m) % m
# --------------------------------------iye ha power ka zindegi---------------------------------
def sort_list(list1, list2):
zipped_pairs = zip(list2, list1)
z = [x for _, x in sorted(zipped_pairs)]
return z
# --------------------------------------------------product----------------------------------------
def product(l):
por = 1
for i in range(len(l)):
por *= l[i]
return por
# --------------------------------------------------binary----------------------------------------
def binarySearchCount(arr, n, key):
left = 0
right = n - 1
count = 0
while (left <= right):
mid = int((right + left) / 2)
# Check if middle element is
# less than or equal to key
if (arr[mid] < key):
count = mid + 1
left = mid + 1
# If key is smaller, ignore right half
else:
right = mid - 1
return count
# --------------------------------------------------binary----------------------------------------
def countdig(n):
c = 0
while (n > 0):
n //= 10
c += 1
return c
def binary(x, length):
y = bin(x)[2:]
return y if len(y) >= length else "0" * (length - len(y)) + y
def countGreater(arr, n, k):
l = 0
r = n - 1
# Stores the index of the left most element
# from the array which is greater than k
leftGreater = n
# Finds number of elements greater than k
while (l <= r):
m = int(l + (r - l) / 2)
if (arr[m] >= k):
leftGreater = m
r = m - 1
# If mid element is less than
# or equal to k update l
else:
l = m + 1
# Return the count of elements
# greater than k
return (n - leftGreater)
# --------------------------------------------------binary------------------------------------
for ik in range(int(input())):
a,b=map(int,input().split())
if b==0:
print(1)
continue
elif a==0:
print(0.5)
continue
if 4*b>=a:
print((a*b+(a*a)/8)/(2*a*b))
else:
print((2*a*b-2*b*b)/(2*a*b))
``` | instruction | 0 | 48,476 | 2 | 96,952 |
Yes | output | 1 | 48,476 | 2 | 96,953 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
For some reason in many American cartoons anvils fall from time to time onto heroes' heads. Of course, safes, wardrobes, cruisers, planes fall sometimes too... But anvils do so most of all.
Anvils come in different sizes and shapes. Quite often they get the hero stuck deep in the ground. But have you ever thought who throws anvils from the sky? From what height? We are sure that such questions have never troubled you!
It turns out that throwing an anvil properly is not an easy task at all. Let's describe one of the most popular anvil throwing models.
Let the height p of the potential victim vary in the range [0;a] and the direction of the wind q vary in the range [ - b;b]. p and q could be any real (floating) numbers. Then we can assume that the anvil will fit the toon's head perfectly only if the following equation has at least one real root:
<image>
Determine the probability with which an aim can be successfully hit by an anvil.
You can assume that the p and q coefficients are chosen equiprobably and independently in their ranges.
Input
The first line contains integer t (1 β€ t β€ 10000) β amount of testcases.
Each of the following t lines contain two space-separated integers a and b (0 β€ a, b β€ 106).
Pretests contain all the tests with 0 < a < 10, 0 β€ b < 10.
Output
Print t lines β the probability of a successful anvil hit for each testcase. The absolute or relative error of the answer should not exceed 10 - 6.
Examples
Input
2
4 2
1 2
Output
0.6250000000
0.5312500000
Submitted Solution:
```
t = int(input())
for _ in range(t):
a, b = map(float, input().split())
if b == 0.0:
print(1.0)
elif a == 0.0:
print(0.5)
elif a / 4.0 <= b:
print((a + 8.0 * b) / 16.0 / b)
else:
print(1.0 - b / a)
``` | instruction | 0 | 48,477 | 2 | 96,954 |
Yes | output | 1 | 48,477 | 2 | 96,955 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
For some reason in many American cartoons anvils fall from time to time onto heroes' heads. Of course, safes, wardrobes, cruisers, planes fall sometimes too... But anvils do so most of all.
Anvils come in different sizes and shapes. Quite often they get the hero stuck deep in the ground. But have you ever thought who throws anvils from the sky? From what height? We are sure that such questions have never troubled you!
It turns out that throwing an anvil properly is not an easy task at all. Let's describe one of the most popular anvil throwing models.
Let the height p of the potential victim vary in the range [0;a] and the direction of the wind q vary in the range [ - b;b]. p and q could be any real (floating) numbers. Then we can assume that the anvil will fit the toon's head perfectly only if the following equation has at least one real root:
<image>
Determine the probability with which an aim can be successfully hit by an anvil.
You can assume that the p and q coefficients are chosen equiprobably and independently in their ranges.
Input
The first line contains integer t (1 β€ t β€ 10000) β amount of testcases.
Each of the following t lines contain two space-separated integers a and b (0 β€ a, b β€ 106).
Pretests contain all the tests with 0 < a < 10, 0 β€ b < 10.
Output
Print t lines β the probability of a successful anvil hit for each testcase. The absolute or relative error of the answer should not exceed 10 - 6.
Examples
Input
2
4 2
1 2
Output
0.6250000000
0.5312500000
Submitted Solution:
```
import sys
lines = int(sys.stdin.readline())
for _ in range(lines):
a, b = map(float, sys.stdin.readline().split(' '))
if b == 0.0:
print(1)
elif a <= 4*b:
print((0.125*a + b) / (2.0*b))
else:
print(a - b)
``` | instruction | 0 | 48,478 | 2 | 96,956 |
No | output | 1 | 48,478 | 2 | 96,957 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
For some reason in many American cartoons anvils fall from time to time onto heroes' heads. Of course, safes, wardrobes, cruisers, planes fall sometimes too... But anvils do so most of all.
Anvils come in different sizes and shapes. Quite often they get the hero stuck deep in the ground. But have you ever thought who throws anvils from the sky? From what height? We are sure that such questions have never troubled you!
It turns out that throwing an anvil properly is not an easy task at all. Let's describe one of the most popular anvil throwing models.
Let the height p of the potential victim vary in the range [0;a] and the direction of the wind q vary in the range [ - b;b]. p and q could be any real (floating) numbers. Then we can assume that the anvil will fit the toon's head perfectly only if the following equation has at least one real root:
<image>
Determine the probability with which an aim can be successfully hit by an anvil.
You can assume that the p and q coefficients are chosen equiprobably and independently in their ranges.
Input
The first line contains integer t (1 β€ t β€ 10000) β amount of testcases.
Each of the following t lines contain two space-separated integers a and b (0 β€ a, b β€ 106).
Pretests contain all the tests with 0 < a < 10, 0 β€ b < 10.
Output
Print t lines β the probability of a successful anvil hit for each testcase. The absolute or relative error of the answer should not exceed 10 - 6.
Examples
Input
2
4 2
1 2
Output
0.6250000000
0.5312500000
Submitted Solution:
```
def li():
return list(map(int, input().split(" ")))
for _ in range(int(input())):
a, b=li()
if b != 0:
s = (max(0, a-4*b) + a)/2
s*=min((a/4), b)
ans = 1/2 + s/(2*a*b)
print("{:.8f}".format(ans), (max(0, a-4*b) + a)/2)
else:
print(1)
``` | instruction | 0 | 48,479 | 2 | 96,958 |
No | output | 1 | 48,479 | 2 | 96,959 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
For some reason in many American cartoons anvils fall from time to time onto heroes' heads. Of course, safes, wardrobes, cruisers, planes fall sometimes too... But anvils do so most of all.
Anvils come in different sizes and shapes. Quite often they get the hero stuck deep in the ground. But have you ever thought who throws anvils from the sky? From what height? We are sure that such questions have never troubled you!
It turns out that throwing an anvil properly is not an easy task at all. Let's describe one of the most popular anvil throwing models.
Let the height p of the potential victim vary in the range [0;a] and the direction of the wind q vary in the range [ - b;b]. p and q could be any real (floating) numbers. Then we can assume that the anvil will fit the toon's head perfectly only if the following equation has at least one real root:
<image>
Determine the probability with which an aim can be successfully hit by an anvil.
You can assume that the p and q coefficients are chosen equiprobably and independently in their ranges.
Input
The first line contains integer t (1 β€ t β€ 10000) β amount of testcases.
Each of the following t lines contain two space-separated integers a and b (0 β€ a, b β€ 106).
Pretests contain all the tests with 0 < a < 10, 0 β€ b < 10.
Output
Print t lines β the probability of a successful anvil hit for each testcase. The absolute or relative error of the answer should not exceed 10 - 6.
Examples
Input
2
4 2
1 2
Output
0.6250000000
0.5312500000
Submitted Solution:
```
t = int(input())
while t > 0:
a, b = map(int, input().split())
if a == 0 or b == 0:
print(0)
t -= 1
continue
ans = a * b + a * a / 8.0
ans /= 2.0 * a * b
print("%.10f" % ans)
t -= 1
``` | instruction | 0 | 48,480 | 2 | 96,960 |
No | output | 1 | 48,480 | 2 | 96,961 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
For some reason in many American cartoons anvils fall from time to time onto heroes' heads. Of course, safes, wardrobes, cruisers, planes fall sometimes too... But anvils do so most of all.
Anvils come in different sizes and shapes. Quite often they get the hero stuck deep in the ground. But have you ever thought who throws anvils from the sky? From what height? We are sure that such questions have never troubled you!
It turns out that throwing an anvil properly is not an easy task at all. Let's describe one of the most popular anvil throwing models.
Let the height p of the potential victim vary in the range [0;a] and the direction of the wind q vary in the range [ - b;b]. p and q could be any real (floating) numbers. Then we can assume that the anvil will fit the toon's head perfectly only if the following equation has at least one real root:
<image>
Determine the probability with which an aim can be successfully hit by an anvil.
You can assume that the p and q coefficients are chosen equiprobably and independently in their ranges.
Input
The first line contains integer t (1 β€ t β€ 10000) β amount of testcases.
Each of the following t lines contain two space-separated integers a and b (0 β€ a, b β€ 106).
Pretests contain all the tests with 0 < a < 10, 0 β€ b < 10.
Output
Print t lines β the probability of a successful anvil hit for each testcase. The absolute or relative error of the answer should not exceed 10 - 6.
Examples
Input
2
4 2
1 2
Output
0.6250000000
0.5312500000
Submitted Solution:
```
#!/usr/bin/env python3
def solve(a,b):
answer = 0
if ((a>0) and (b>0)):
height = a / 4
if (height <= b):
answer = ((a*b)+0.5*a*height)/(2*b*a)
else:
base = b*4
answer = ((2*a*b)-0.5*base*b)/(2*b*a)
pass
print("%.10f" % answer)
n = int(input())
for i in range(n):
a,b = map(int, input().split())
solve(a,b)
``` | instruction | 0 | 48,481 | 2 | 96,962 |
No | output | 1 | 48,481 | 2 | 96,963 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Berland is facing dark times again. The army of evil lord Van de Mart is going to conquer the whole kingdom. To the council of war called by the Berland's king Valery the Severe came n knights. After long discussions it became clear that the kingdom has exactly n control points (if the enemy conquers at least one of these points, the war is lost) and each knight will occupy one of these points.
Berland is divided into m + 1 regions with m fences, and the only way to get from one region to another is to climb over the fence. Each fence is a circle on a plane, no two fences have common points, and no control point is on the fence. You are given k pairs of numbers ai, bi. For each pair you have to find out: how many fences a knight from control point with index ai has to climb over to reach control point bi (in case when Van de Mart attacks control point bi first). As each knight rides a horse (it is very difficult to throw a horse over a fence), you are to find out for each pair the minimum amount of fences to climb over.
Input
The first input line contains three integers n, m, k (1 β€ n, m β€ 1000, 0 β€ k β€ 100000). Then follow n lines, each containing two integers Kxi, Kyi ( - 109 β€ Kxi, Kyi β€ 109) β coordinates of control point with index i. Control points can coincide.
Each of the following m lines describes fence with index i with three integers ri, Cxi, Cyi (1 β€ ri β€ 109, - 109 β€ Cxi, Cyi β€ 109) β radius and center of the circle where the corresponding fence is situated.
Then follow k pairs of integers ai, bi (1 β€ ai, bi β€ n), each in a separate line β requests that you have to answer. ai and bi can coincide.
Output
Output exactly k lines, each containing one integer β the answer to the corresponding request.
Examples
Input
2 1 1
0 0
3 3
2 0 0
1 2
Output
1
Input
2 3 1
0 0
4 4
1 0 0
2 0 0
3 0 0
1 2
Output
3
Submitted Solution:
```
import sys; input = sys.stdin.readline
from collections import deque
import heapq as hq
N = 2*10**5+5
def read():
return map(int, input().split())
n, m, k = read()
points = [list(read()) for i in range(n)]
fences = [list(read()) for i in range(m)]
def dist(x1, y1, x2, y2):
return (x1-x2)**2 + (y1-y2)**2
largest_fence = [-1]*n
cnt = [0]*n
for i in range(n):
point = points[i]
for j in range(m):
fence = fences[j]
if dist(point[0], point[1], fence[1], fence[2]) > fence[0]**2:
continue
cnt[i] += 1
if largest_fence[i] == -1 or fences[largest_fence[i]][1]**2 < fence[0]**2:
largest_fence[i] = j
while k:
k -= 1
a, b = read()
a, b = a-1, b-1
same = largest_fence[a] == largest_fence[b]
print(abs(cnt[a]-cnt[b]) if same else cnt[a]+cnt[b])
``` | instruction | 0 | 49,976 | 2 | 99,952 |
No | output | 1 | 49,976 | 2 | 99,953 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Berland is facing dark times again. The army of evil lord Van de Mart is going to conquer the whole kingdom. To the council of war called by the Berland's king Valery the Severe came n knights. After long discussions it became clear that the kingdom has exactly n control points (if the enemy conquers at least one of these points, the war is lost) and each knight will occupy one of these points.
Berland is divided into m + 1 regions with m fences, and the only way to get from one region to another is to climb over the fence. Each fence is a circle on a plane, no two fences have common points, and no control point is on the fence. You are given k pairs of numbers ai, bi. For each pair you have to find out: how many fences a knight from control point with index ai has to climb over to reach control point bi (in case when Van de Mart attacks control point bi first). As each knight rides a horse (it is very difficult to throw a horse over a fence), you are to find out for each pair the minimum amount of fences to climb over.
Input
The first input line contains three integers n, m, k (1 β€ n, m β€ 1000, 0 β€ k β€ 100000). Then follow n lines, each containing two integers Kxi, Kyi ( - 109 β€ Kxi, Kyi β€ 109) β coordinates of control point with index i. Control points can coincide.
Each of the following m lines describes fence with index i with three integers ri, Cxi, Cyi (1 β€ ri β€ 109, - 109 β€ Cxi, Cyi β€ 109) β radius and center of the circle where the corresponding fence is situated.
Then follow k pairs of integers ai, bi (1 β€ ai, bi β€ n), each in a separate line β requests that you have to answer. ai and bi can coincide.
Output
Output exactly k lines, each containing one integer β the answer to the corresponding request.
Examples
Input
2 1 1
0 0
3 3
2 0 0
1 2
Output
1
Input
2 3 1
0 0
4 4
1 0 0
2 0 0
3 0 0
1 2
Output
3
Submitted Solution:
```
import sys; input = sys.stdin.readline
from collections import deque
import heapq as hq
N = 2*10**5+5
def read():
return map(int, input().split())
n, m, k = read()
points = [list(read()) for i in range(n)]
fences = [list(read()) for i in range(m)]
def dist(x1, y1, x2, y2):
return (x1-x2)**2 + (y1-y2)**2
p = [[] for i in range(n)]
for i in range(n):
point = points[i]
for j in range(m):
fence = fences[j]
if dist(point[0], point[1], fence[1], fence[2]) > fence[0]**2:
continue
p[i].append(j)
p[i].sort()
while k:
k -= 1
a, b = read()
a, b = a-1, b-1
l = p[a].copy()
for x in p[b]: l.append(x)
cnt = len(l)
for i in range(1, len(l)):
if l[i] == l[i-1]: cnt -= 2
print(cnt)
``` | instruction | 0 | 49,977 | 2 | 99,954 |
No | output | 1 | 49,977 | 2 | 99,955 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Berland is facing dark times again. The army of evil lord Van de Mart is going to conquer the whole kingdom. To the council of war called by the Berland's king Valery the Severe came n knights. After long discussions it became clear that the kingdom has exactly n control points (if the enemy conquers at least one of these points, the war is lost) and each knight will occupy one of these points.
Berland is divided into m + 1 regions with m fences, and the only way to get from one region to another is to climb over the fence. Each fence is a circle on a plane, no two fences have common points, and no control point is on the fence. You are given k pairs of numbers ai, bi. For each pair you have to find out: how many fences a knight from control point with index ai has to climb over to reach control point bi (in case when Van de Mart attacks control point bi first). As each knight rides a horse (it is very difficult to throw a horse over a fence), you are to find out for each pair the minimum amount of fences to climb over.
Input
The first input line contains three integers n, m, k (1 β€ n, m β€ 1000, 0 β€ k β€ 100000). Then follow n lines, each containing two integers Kxi, Kyi ( - 109 β€ Kxi, Kyi β€ 109) β coordinates of control point with index i. Control points can coincide.
Each of the following m lines describes fence with index i with three integers ri, Cxi, Cyi (1 β€ ri β€ 109, - 109 β€ Cxi, Cyi β€ 109) β radius and center of the circle where the corresponding fence is situated.
Then follow k pairs of integers ai, bi (1 β€ ai, bi β€ n), each in a separate line β requests that you have to answer. ai and bi can coincide.
Output
Output exactly k lines, each containing one integer β the answer to the corresponding request.
Examples
Input
2 1 1
0 0
3 3
2 0 0
1 2
Output
1
Input
2 3 1
0 0
4 4
1 0 0
2 0 0
3 0 0
1 2
Output
3
Submitted Solution:
```
import functools, collections
def longestPath(nodes, edges):
graph = collections.defaultdict(list)
for i, j in edges:
graph[i].append(j)
def cyclic(node, visited):
if node not in visited:
visited.add(node)
return any(cyclic(nei, visited) for nei in graph[node])
return True
if any(cyclic(node, set()) for node in range(len(nodes))):
return None
@functools.lru_cache(None)
def dfs(node):
value = [0] * 26
for nei in graph[node]:
value = [max(a, b) for a, b in zip(value, dfs(nei))]
value[ord(nodes[node]) - ord('A')] += 1
return value
return max(max(dfs(node)) for node in range(len(nodes)))
tests = [
("A", [(0, 0)], None),
("ABACA", [(0, 1), (0, 2), (2, 3), (3, 4)], 3),
("BAA", [(0, 1), (0, 2)], 1),
("BAA", [(0, 1), (2, 0)], 2)
]
for nodes, edges, ans in tests:
assert longestPath(nodes, edges) == ans
``` | instruction | 0 | 49,978 | 2 | 99,956 |
No | output | 1 | 49,978 | 2 | 99,957 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Apart from plush toys, Imp is a huge fan of little yellow birds!
<image>
To summon birds, Imp needs strong magic. There are n trees in a row on an alley in a park, there is a nest on each of the trees. In the i-th nest there are ci birds; to summon one bird from this nest Imp needs to stay under this tree and it costs him costi points of mana. However, for each bird summoned, Imp increases his mana capacity by B points. Imp summons birds one by one, he can summon any number from 0 to ci birds from the i-th nest.
Initially Imp stands under the first tree and has W points of mana, and his mana capacity equals W as well. He can only go forward, and each time he moves from a tree to the next one, he restores X points of mana (but it can't exceed his current mana capacity). Moving only forward, what is the maximum number of birds Imp can summon?
Input
The first line contains four integers n, W, B, X (1 β€ n β€ 103, 0 β€ W, B, X β€ 109) β the number of trees, the initial points of mana, the number of points the mana capacity increases after a bird is summoned, and the number of points restored when Imp moves from a tree to the next one.
The second line contains n integers c1, c2, ..., cn (0 β€ ci β€ 104) β where ci is the number of birds living in the i-th nest. It is guaranteed that <image>.
The third line contains n integers cost1, cost2, ..., costn (0 β€ costi β€ 109), where costi is the mana cost to summon a bird from the i-th nest.
Output
Print a single integer β the maximum number of birds Imp can summon.
Examples
Input
2 12 0 4
3 4
4 2
Output
6
Input
4 1000 10 35
1 2 4 5
1000 500 250 200
Output
5
Input
2 10 7 11
2 10
6 1
Output
11
Note
In the first sample base amount of Imp's mana is equal to 12 (with maximum capacity also equal to 12). After he summons two birds from the first nest, he loses 8 mana points, although his maximum capacity will not increase (since B = 0). After this step his mana will be 4 of 12; during the move you will replenish 4 mana points, and hence own 8 mana out of 12 possible. Now it's optimal to take 4 birds from the second nest and spend 8 mana. The final answer will be β 6.
In the second sample the base amount of mana is equal to 1000. The right choice will be to simply pick all birds from the last nest. Note that Imp's mana doesn't restore while moving because it's initially full.
Submitted Solution:
```
n , st_cap , plus, rest = (int (i) for i in input().split())
nest = [ int(i) for i in input().split()]
cost = [ int(i) for i in input().split()]
data = []
all_max = []
def look_up(fromm,require_mana,require_cap):
# return bird and mana
if fromm < 0:
if require_cap > st_cap or require_mana > st_cap:
return 0,-1
else:
return 0,st_cap
x_nest = data[fromm]
max_bird = 0
mana = 0
for option in x_nest:
if option['mana'] >= require_mana and option['bird_no']>max_bird and option['cap'] >= require_cap:
max_bird = option['bird_no']
mana = option['mana']
if mana == 0:
max_bird, mana = look_up(fromm-1,require_mana-rest,require_cap)
if mana != -1:
return max_bird, mana+rest
else:
return 0,-1
else:
return max_bird, mana
for i in range(n):
cost_s = cost[i]
bird_num = nest[i]
this_nest = []
bird_max_step = 0
for j in range(bird_num+1):
bird, mana = look_up(i-1, cost_s*j, cost_s*j)
if mana != -1:
bird_no = bird + j
cap = st_cap + bird_no * plus
mana = mana - cost_s*j + rest
if mana > cap:
mana = cap
else:
mana = -1
bird_no = -1
cap = 0
data_each = {
'bird_no' :bird_no,
'cap': cap,
'mana' : mana
}
this_nest.append(data_each)
if data_each['bird_no'] > bird_max_step:
bird_max_step = data_each['bird_no']
all_max.append(bird_max_step)
data.append(this_nest)
print(all_max[-1])
``` | instruction | 0 | 50,213 | 2 | 100,426 |
No | output | 1 | 50,213 | 2 | 100,427 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Apart from plush toys, Imp is a huge fan of little yellow birds!
<image>
To summon birds, Imp needs strong magic. There are n trees in a row on an alley in a park, there is a nest on each of the trees. In the i-th nest there are ci birds; to summon one bird from this nest Imp needs to stay under this tree and it costs him costi points of mana. However, for each bird summoned, Imp increases his mana capacity by B points. Imp summons birds one by one, he can summon any number from 0 to ci birds from the i-th nest.
Initially Imp stands under the first tree and has W points of mana, and his mana capacity equals W as well. He can only go forward, and each time he moves from a tree to the next one, he restores X points of mana (but it can't exceed his current mana capacity). Moving only forward, what is the maximum number of birds Imp can summon?
Input
The first line contains four integers n, W, B, X (1 β€ n β€ 103, 0 β€ W, B, X β€ 109) β the number of trees, the initial points of mana, the number of points the mana capacity increases after a bird is summoned, and the number of points restored when Imp moves from a tree to the next one.
The second line contains n integers c1, c2, ..., cn (0 β€ ci β€ 104) β where ci is the number of birds living in the i-th nest. It is guaranteed that <image>.
The third line contains n integers cost1, cost2, ..., costn (0 β€ costi β€ 109), where costi is the mana cost to summon a bird from the i-th nest.
Output
Print a single integer β the maximum number of birds Imp can summon.
Examples
Input
2 12 0 4
3 4
4 2
Output
6
Input
4 1000 10 35
1 2 4 5
1000 500 250 200
Output
5
Input
2 10 7 11
2 10
6 1
Output
11
Note
In the first sample base amount of Imp's mana is equal to 12 (with maximum capacity also equal to 12). After he summons two birds from the first nest, he loses 8 mana points, although his maximum capacity will not increase (since B = 0). After this step his mana will be 4 of 12; during the move you will replenish 4 mana points, and hence own 8 mana out of 12 possible. Now it's optimal to take 4 birds from the second nest and spend 8 mana. The final answer will be β 6.
In the second sample the base amount of mana is equal to 1000. The right choice will be to simply pick all birds from the last nest. Note that Imp's mana doesn't restore while moving because it's initially full.
Submitted Solution:
```
#!/usr/bin/python3
import sys;
def max_number( number_of_trees, max_mana, gain_birds, gain_movement,
birds_number, birds_cost,
actual_tree, mana_left, memoization_table):
if (actual_tree,mana_left) in memoization_table:
return memoization_table[actual_tree,mana_left]
if actual_tree >= number_of_trees:
return 0
best_number = max_number(number_of_trees, max_mana, gain_birds, gain_movement,
birds_number,birds_cost,
actual_tree + 1, min(mana_left + gain_movement,max_mana),
memoization_table)
actual_mana = mana_left
for i in range (1,birds_number[actual_tree] + 1):
if ( actual_mana < birds_cost[actual_tree] ):
break;
else:
actual_mana = actual_mana - birds_cost[actual_tree] + gain_birds;
actual_number = i + max_number(number_of_trees,max_mana,gain_birds,gain_movement,
birds_number,birds_cost,
actual_tree+1,min(actual_mana + gain_movement,max_mana),
memoization_table)
if actual_number > best_number:
best_number = actual_number
memoization_table[actual_tree,mana_left] = best_number
return best_number
if __name__ == "__main__":
line = input()
value = line.split(" ")
number_of_trees = int(value[0])
max_mana = int(value[1])
gain_birds = int(value[2])
gain_movement = int(value[3])
line = input()
value = line.split(" ")
birds_number = []
for i in range(0, number_of_trees ):
birds_number.append(int(value[i]))
line = input()
value = line.split(" ")
birds_cost = []
for i in range(0, number_of_trees ):
birds_cost.append(int(value[i]))
memoization_table = dict()
print(max_number(number_of_trees,max_mana,gain_birds,gain_movement,birds_number,
birds_cost, 0, max_mana, memoization_table))
``` | instruction | 0 | 50,214 | 2 | 100,428 |
No | output | 1 | 50,214 | 2 | 100,429 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Apart from plush toys, Imp is a huge fan of little yellow birds!
<image>
To summon birds, Imp needs strong magic. There are n trees in a row on an alley in a park, there is a nest on each of the trees. In the i-th nest there are ci birds; to summon one bird from this nest Imp needs to stay under this tree and it costs him costi points of mana. However, for each bird summoned, Imp increases his mana capacity by B points. Imp summons birds one by one, he can summon any number from 0 to ci birds from the i-th nest.
Initially Imp stands under the first tree and has W points of mana, and his mana capacity equals W as well. He can only go forward, and each time he moves from a tree to the next one, he restores X points of mana (but it can't exceed his current mana capacity). Moving only forward, what is the maximum number of birds Imp can summon?
Input
The first line contains four integers n, W, B, X (1 β€ n β€ 103, 0 β€ W, B, X β€ 109) β the number of trees, the initial points of mana, the number of points the mana capacity increases after a bird is summoned, and the number of points restored when Imp moves from a tree to the next one.
The second line contains n integers c1, c2, ..., cn (0 β€ ci β€ 104) β where ci is the number of birds living in the i-th nest. It is guaranteed that <image>.
The third line contains n integers cost1, cost2, ..., costn (0 β€ costi β€ 109), where costi is the mana cost to summon a bird from the i-th nest.
Output
Print a single integer β the maximum number of birds Imp can summon.
Examples
Input
2 12 0 4
3 4
4 2
Output
6
Input
4 1000 10 35
1 2 4 5
1000 500 250 200
Output
5
Input
2 10 7 11
2 10
6 1
Output
11
Note
In the first sample base amount of Imp's mana is equal to 12 (with maximum capacity also equal to 12). After he summons two birds from the first nest, he loses 8 mana points, although his maximum capacity will not increase (since B = 0). After this step his mana will be 4 of 12; during the move you will replenish 4 mana points, and hence own 8 mana out of 12 possible. Now it's optimal to take 4 birds from the second nest and spend 8 mana. The final answer will be β 6.
In the second sample the base amount of mana is equal to 1000. The right choice will be to simply pick all birds from the last nest. Note that Imp's mana doesn't restore while moving because it's initially full.
Submitted Solution:
```
#!/usr/bin/python3
import sys;
def max_number( number_of_trees, max_mana, gain_birds, gain_movement,
birds_number, birds_cost,
actual_tree, mana_left, memoization_table):
print(str(actual_tree) + " " + str(mana_left))
if (actual_tree,mana_left) in memoization_table:
return memoization_table[actual_tree,mana_left]
if actual_tree >= number_of_trees:
return 0
best_number = max_number(number_of_trees, max_mana, gain_birds, gain_movement,
birds_number,birds_cost,
actual_tree + 1, min(mana_left + gain_movement,max_mana),
memoization_table)
actual_mana = mana_left
for i in range (1,birds_number[actual_tree] + 1):
if ( actual_mana < birds_cost[actual_tree] ):
break;
else:
actual_mana = actual_mana - birds_cost[actual_tree] + gain_birds;
actual_number = i + max_number(number_of_trees,max_mana,gain_birds,gain_movement,
birds_number,birds_cost,
actual_tree+1,min(actual_mana + gain_movement,max_mana),
memoization_table)
if actual_number > best_number:
best_number = actual_number
memoization_table[actual_tree,mana_left] = best_number
return best_number
if __name__ == "__main__":
line = input()
value = line.split(" ")
number_of_trees = int(value[0])
max_mana = int(value[1])
gain_birds = int(value[2])
gain_movement = int(value[3])
line = input()
value = line.split(" ")
birds_number = []
for i in range(0, number_of_trees ):
birds_number.append(int(value[i]))
line = input()
value = line.split(" ")
birds_cost = []
for i in range(0, number_of_trees ):
birds_cost.append(int(value[i]))
memoization_table = dict()
print(max_number(number_of_trees,max_mana,gain_birds,gain_movement,birds_number,
birds_cost, 0, max_mana, memoization_table))
``` | instruction | 0 | 50,215 | 2 | 100,430 |
No | output | 1 | 50,215 | 2 | 100,431 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Apart from plush toys, Imp is a huge fan of little yellow birds!
<image>
To summon birds, Imp needs strong magic. There are n trees in a row on an alley in a park, there is a nest on each of the trees. In the i-th nest there are ci birds; to summon one bird from this nest Imp needs to stay under this tree and it costs him costi points of mana. However, for each bird summoned, Imp increases his mana capacity by B points. Imp summons birds one by one, he can summon any number from 0 to ci birds from the i-th nest.
Initially Imp stands under the first tree and has W points of mana, and his mana capacity equals W as well. He can only go forward, and each time he moves from a tree to the next one, he restores X points of mana (but it can't exceed his current mana capacity). Moving only forward, what is the maximum number of birds Imp can summon?
Input
The first line contains four integers n, W, B, X (1 β€ n β€ 103, 0 β€ W, B, X β€ 109) β the number of trees, the initial points of mana, the number of points the mana capacity increases after a bird is summoned, and the number of points restored when Imp moves from a tree to the next one.
The second line contains n integers c1, c2, ..., cn (0 β€ ci β€ 104) β where ci is the number of birds living in the i-th nest. It is guaranteed that <image>.
The third line contains n integers cost1, cost2, ..., costn (0 β€ costi β€ 109), where costi is the mana cost to summon a bird from the i-th nest.
Output
Print a single integer β the maximum number of birds Imp can summon.
Examples
Input
2 12 0 4
3 4
4 2
Output
6
Input
4 1000 10 35
1 2 4 5
1000 500 250 200
Output
5
Input
2 10 7 11
2 10
6 1
Output
11
Note
In the first sample base amount of Imp's mana is equal to 12 (with maximum capacity also equal to 12). After he summons two birds from the first nest, he loses 8 mana points, although his maximum capacity will not increase (since B = 0). After this step his mana will be 4 of 12; during the move you will replenish 4 mana points, and hence own 8 mana out of 12 possible. Now it's optimal to take 4 birds from the second nest and spend 8 mana. The final answer will be β 6.
In the second sample the base amount of mana is equal to 1000. The right choice will be to simply pick all birds from the last nest. Note that Imp's mana doesn't restore while moving because it's initially full.
Submitted Solution:
```
from copy import deepcopy
class route(object):
num_trees = 0
max_mana = 0
mana_per_bird = 0
mana_per_move = 0
mana_costs = list()
@staticmethod
def set_route_variables(num_trees, max_mana, mana_per_bird, mana_per_move, mana_costs):
route.num_trees = num_trees # This is static for each instance of the problem
route.max_mana = max_mana # This is static for each instance of the problem
# This is static for each instance of the problem
route.mana_per_bird = mana_per_bird
# This is static for each instance of the problem
route.mana_per_move = mana_per_move
route.mana_costs = mana_costs # This is static for each instance of the problem
# print(route.num_trees)
# print(route.max_mana)
# print(route.mana_per_bird)
# print(route.mana_per_move)
# print(route.mana_costs)
def __init__(self, birds_per_tree, current_mana, routelist=list(), position=0, birds_summoned=0):
self.birds_per_tree = list(birds_per_tree)
self.routelist = list(routelist)
self.position = position
self.birds_summoned = birds_summoned
self.current_mana = current_mana
# print("The route has:\n route: ", self.routelist, "\n summoned birds: ",
# self.birds_summoned, "\n mana: ", self.current_mana, "\n position: ", self.position)
# print("______________________________________________")
self.alive = False if (
self.position >= route.num_trees or current_mana <= 0) else True
def split_route(self):
# print("______________________________________________")
# print("Splitting route")
if self.can_move():
# print("Considering mana; self.current_mana = ",self.current_mana)
# print("Route's mana per move = ",route.mana_per_move)
pot_new_mana = self.current_mana + route.mana_per_move
new_mana = pot_new_mana if pot_new_mana < route.max_mana else route.max_mana
# print("Hence, the potential mana is: ",pot_new_mana, " and the max mana = ",route.max_mana)
new_route = deepcopy(self.routelist)
new_route.append(1)
new_position = self.position + 1
new_birds_summoned = self.birds_summoned
return route(self.birds_per_tree, new_mana, routelist=new_route, position=new_position,
birds_summoned=new_birds_summoned)
else:
self.is_alive()
def continue_route(self):
# print("______________________________________________")
# print("Continuing route:")
if self.can_summon:
self.current_mana = self.man_after_summon()
self.routelist.append(0)
self.birds_summoned += 1
self.birds_per_tree[self.position] -= 1
# print("Position = ", self.position)
# print("Route = ", self.routelist)
# print("Current mana = ", self.current_mana)
# print("Birds summoned = ", self.birds_summoned)
# print("Birds in tree = ", self.birds_per_tree)
# print("Birds in tree at position = ",
# self.birds_per_tree[self.position])
# print("______________________________________________")
else:
self.is_alive()
def is_alive(self):
if self.can_move() or self.can_summon():
self.alive = True
else:
self.alive = False
def man_after_summon(self):
return self.current_mana - route.mana_costs[self.position]
def can_summon(self):
can_self = True if (self.man_after_summon(
) >= 0 and self.birds_per_tree[self.position] > 0) else False
return can_self
def can_move(self):
can_move_position = True if self.position + 1 < route.num_trees else False
#can_move_mana = self.current_mana >= 0
can_move_mana = self.current_mana > 0
return can_move_mana and can_move_position
def readinvars():
inwrds = str(input()).split(" ")
innums = list()
for wrd in inwrds:
innums.append(int(wrd))
return innums
contolling_vars = readinvars()
birds_in_trees = readinvars()
cost_to_summon = readinvars()
route.set_route_variables(
contolling_vars[0], contolling_vars[1], contolling_vars[2], contolling_vars[3], cost_to_summon)
start_route = route(birds_in_trees, route.max_mana)
workinglist = list()
workinglist.append(start_route)
#print("Working list = ", workinglist)
#print("Length of working list = ", len(workinglist))
safety = 10000
max_birds_summoned = 0
while(safety > 0):
safety -= 1
size = len(workinglist)
#print("size = ", size)
breakit = True
for i in range(size):
rte = workinglist[i]
max_birds_summoned = rte.birds_summoned if rte.birds_summoned >= max_birds_summoned else max_birds_summoned
if rte.can_move():
workinglist.append(rte.split_route())
breakit = False
if not rte.can_summon():
workinglist.remove(rte)
if rte.can_summon():
rte.continue_route()
breakit = False
if(breakit):
break
print(max_birds_summoned)
``` | instruction | 0 | 50,216 | 2 | 100,432 |
No | output | 1 | 50,216 | 2 | 100,433 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Kana was just an ordinary high school girl before a talent scout discovered her. Then, she became an idol. But different from the stereotype, she is also a gameholic.
One day Kana gets interested in a new adventure game called Dragon Quest. In this game, her quest is to beat a dragon.
<image>
The dragon has a hit point of x initially. When its hit point goes to 0 or under 0, it will be defeated. In order to defeat the dragon, Kana can cast the two following types of spells.
* Void Absorption
Assume that the dragon's current hit point is h, after casting this spell its hit point will become \leftβ h/2 \rightβ + 10. Here \leftβ h/2 \rightβ denotes h divided by two, rounded down.
* Lightning Strike
This spell will decrease the dragon's hit point by 10. Assume that the dragon's current hit point is h, after casting this spell its hit point will be lowered to h-10.
Due to some reasons Kana can only cast no more than n Void Absorptions and m Lightning Strikes. She can cast the spells in any order and doesn't have to cast all the spells. Kana isn't good at math, so you are going to help her to find out whether it is possible to defeat the dragon.
Input
The first line contains a single integer t (1 β€ t β€ 1000) β the number of test cases.
The next t lines describe test cases. For each test case the only line contains three integers x, n, m (1β€ x β€ 10^5, 0β€ n,mβ€30) β the dragon's intitial hit point, the maximum number of Void Absorptions and Lightning Strikes Kana can cast respectively.
Output
If it is possible to defeat the dragon, print "YES" (without quotes). Otherwise, print "NO" (without quotes).
You can print each letter in any case (upper or lower).
Example
Input
7
100 3 4
189 3 4
64 2 3
63 2 3
30 27 7
10 9 1
69117 21 2
Output
YES
NO
NO
YES
YES
YES
YES
Note
One possible casting sequence of the first test case is shown below:
* Void Absorption \leftβ 100/2 \rightβ + 10=60.
* Lightning Strike 60-10=50.
* Void Absorption \leftβ 50/2 \rightβ + 10=35.
* Void Absorption \leftβ 35/2 \rightβ + 10=27.
* Lightning Strike 27-10=17.
* Lightning Strike 17-10=7.
* Lightning Strike 7-10=-3. | instruction | 0 | 50,635 | 2 | 101,270 |
Tags: greedy, implementation, math
Correct Solution:
```
t=int(input())
for i in range(t):
h,n,m=map(int,input().split())
for j in range(n):
if h<=20:break
h=h//2+10
if h<=10*m:print("YES")
else:print("NO")
``` | output | 1 | 50,635 | 2 | 101,271 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Kana was just an ordinary high school girl before a talent scout discovered her. Then, she became an idol. But different from the stereotype, she is also a gameholic.
One day Kana gets interested in a new adventure game called Dragon Quest. In this game, her quest is to beat a dragon.
<image>
The dragon has a hit point of x initially. When its hit point goes to 0 or under 0, it will be defeated. In order to defeat the dragon, Kana can cast the two following types of spells.
* Void Absorption
Assume that the dragon's current hit point is h, after casting this spell its hit point will become \leftβ h/2 \rightβ + 10. Here \leftβ h/2 \rightβ denotes h divided by two, rounded down.
* Lightning Strike
This spell will decrease the dragon's hit point by 10. Assume that the dragon's current hit point is h, after casting this spell its hit point will be lowered to h-10.
Due to some reasons Kana can only cast no more than n Void Absorptions and m Lightning Strikes. She can cast the spells in any order and doesn't have to cast all the spells. Kana isn't good at math, so you are going to help her to find out whether it is possible to defeat the dragon.
Input
The first line contains a single integer t (1 β€ t β€ 1000) β the number of test cases.
The next t lines describe test cases. For each test case the only line contains three integers x, n, m (1β€ x β€ 10^5, 0β€ n,mβ€30) β the dragon's intitial hit point, the maximum number of Void Absorptions and Lightning Strikes Kana can cast respectively.
Output
If it is possible to defeat the dragon, print "YES" (without quotes). Otherwise, print "NO" (without quotes).
You can print each letter in any case (upper or lower).
Example
Input
7
100 3 4
189 3 4
64 2 3
63 2 3
30 27 7
10 9 1
69117 21 2
Output
YES
NO
NO
YES
YES
YES
YES
Note
One possible casting sequence of the first test case is shown below:
* Void Absorption \leftβ 100/2 \rightβ + 10=60.
* Lightning Strike 60-10=50.
* Void Absorption \leftβ 50/2 \rightβ + 10=35.
* Void Absorption \leftβ 35/2 \rightβ + 10=27.
* Lightning Strike 27-10=17.
* Lightning Strike 17-10=7.
* Lightning Strike 7-10=-3. | instruction | 0 | 50,636 | 2 | 101,272 |
Tags: greedy, implementation, math
Correct Solution:
```
for i in range(int(input())):
x,n,m=map(int,input().split())
if(x>10):
while(n>0):
x=(x//2)+10
n-=1;
if(x/10)<=m:
print("YES")
else:
print("NO")
else:
if(m>0):
print("YES")
else:
print("NO")
``` | output | 1 | 50,636 | 2 | 101,273 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Kana was just an ordinary high school girl before a talent scout discovered her. Then, she became an idol. But different from the stereotype, she is also a gameholic.
One day Kana gets interested in a new adventure game called Dragon Quest. In this game, her quest is to beat a dragon.
<image>
The dragon has a hit point of x initially. When its hit point goes to 0 or under 0, it will be defeated. In order to defeat the dragon, Kana can cast the two following types of spells.
* Void Absorption
Assume that the dragon's current hit point is h, after casting this spell its hit point will become \leftβ h/2 \rightβ + 10. Here \leftβ h/2 \rightβ denotes h divided by two, rounded down.
* Lightning Strike
This spell will decrease the dragon's hit point by 10. Assume that the dragon's current hit point is h, after casting this spell its hit point will be lowered to h-10.
Due to some reasons Kana can only cast no more than n Void Absorptions and m Lightning Strikes. She can cast the spells in any order and doesn't have to cast all the spells. Kana isn't good at math, so you are going to help her to find out whether it is possible to defeat the dragon.
Input
The first line contains a single integer t (1 β€ t β€ 1000) β the number of test cases.
The next t lines describe test cases. For each test case the only line contains three integers x, n, m (1β€ x β€ 10^5, 0β€ n,mβ€30) β the dragon's intitial hit point, the maximum number of Void Absorptions and Lightning Strikes Kana can cast respectively.
Output
If it is possible to defeat the dragon, print "YES" (without quotes). Otherwise, print "NO" (without quotes).
You can print each letter in any case (upper or lower).
Example
Input
7
100 3 4
189 3 4
64 2 3
63 2 3
30 27 7
10 9 1
69117 21 2
Output
YES
NO
NO
YES
YES
YES
YES
Note
One possible casting sequence of the first test case is shown below:
* Void Absorption \leftβ 100/2 \rightβ + 10=60.
* Lightning Strike 60-10=50.
* Void Absorption \leftβ 50/2 \rightβ + 10=35.
* Void Absorption \leftβ 35/2 \rightβ + 10=27.
* Lightning Strike 27-10=17.
* Lightning Strike 17-10=7.
* Lightning Strike 7-10=-3. | instruction | 0 | 50,637 | 2 | 101,274 |
Tags: greedy, implementation, math
Correct Solution:
```
num = int(input())
for x in range(num):
ss = input().split()
hit = int(ss[0])
void = int(ss[1])
strik = int(ss[2])
for x in range(void):
if( hit // 2 ) + 10 >= hit:
break
hit = (hit // 2) + 10
if hit > 10 * strik:
print('NO')
else:
print('YES')
``` | output | 1 | 50,637 | 2 | 101,275 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Kana was just an ordinary high school girl before a talent scout discovered her. Then, she became an idol. But different from the stereotype, she is also a gameholic.
One day Kana gets interested in a new adventure game called Dragon Quest. In this game, her quest is to beat a dragon.
<image>
The dragon has a hit point of x initially. When its hit point goes to 0 or under 0, it will be defeated. In order to defeat the dragon, Kana can cast the two following types of spells.
* Void Absorption
Assume that the dragon's current hit point is h, after casting this spell its hit point will become \leftβ h/2 \rightβ + 10. Here \leftβ h/2 \rightβ denotes h divided by two, rounded down.
* Lightning Strike
This spell will decrease the dragon's hit point by 10. Assume that the dragon's current hit point is h, after casting this spell its hit point will be lowered to h-10.
Due to some reasons Kana can only cast no more than n Void Absorptions and m Lightning Strikes. She can cast the spells in any order and doesn't have to cast all the spells. Kana isn't good at math, so you are going to help her to find out whether it is possible to defeat the dragon.
Input
The first line contains a single integer t (1 β€ t β€ 1000) β the number of test cases.
The next t lines describe test cases. For each test case the only line contains three integers x, n, m (1β€ x β€ 10^5, 0β€ n,mβ€30) β the dragon's intitial hit point, the maximum number of Void Absorptions and Lightning Strikes Kana can cast respectively.
Output
If it is possible to defeat the dragon, print "YES" (without quotes). Otherwise, print "NO" (without quotes).
You can print each letter in any case (upper or lower).
Example
Input
7
100 3 4
189 3 4
64 2 3
63 2 3
30 27 7
10 9 1
69117 21 2
Output
YES
NO
NO
YES
YES
YES
YES
Note
One possible casting sequence of the first test case is shown below:
* Void Absorption \leftβ 100/2 \rightβ + 10=60.
* Lightning Strike 60-10=50.
* Void Absorption \leftβ 50/2 \rightβ + 10=35.
* Void Absorption \leftβ 35/2 \rightβ + 10=27.
* Lightning Strike 27-10=17.
* Lightning Strike 17-10=7.
* Lightning Strike 7-10=-3. | instruction | 0 | 50,638 | 2 | 101,276 |
Tags: greedy, implementation, math
Correct Solution:
```
t=int(input())
import math
for _ in range(0,t):
x,n,m = input().split()
x=int(x)
n=int(n)
m=int(m)
z=999999999999
flag = 0
if(x-(m*10)<=0):
x=0
flag=1
while(x>=m*10 and n>0 and flag ==0):
if(x>z):
break
else:
x = x//2 +10
z=x
if(x<=0):
break
else:
n=n-1
x=x-(m*10)
if(x<=0):
print("YES")
else:
print("NO")
``` | output | 1 | 50,638 | 2 | 101,277 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Kana was just an ordinary high school girl before a talent scout discovered her. Then, she became an idol. But different from the stereotype, she is also a gameholic.
One day Kana gets interested in a new adventure game called Dragon Quest. In this game, her quest is to beat a dragon.
<image>
The dragon has a hit point of x initially. When its hit point goes to 0 or under 0, it will be defeated. In order to defeat the dragon, Kana can cast the two following types of spells.
* Void Absorption
Assume that the dragon's current hit point is h, after casting this spell its hit point will become \leftβ h/2 \rightβ + 10. Here \leftβ h/2 \rightβ denotes h divided by two, rounded down.
* Lightning Strike
This spell will decrease the dragon's hit point by 10. Assume that the dragon's current hit point is h, after casting this spell its hit point will be lowered to h-10.
Due to some reasons Kana can only cast no more than n Void Absorptions and m Lightning Strikes. She can cast the spells in any order and doesn't have to cast all the spells. Kana isn't good at math, so you are going to help her to find out whether it is possible to defeat the dragon.
Input
The first line contains a single integer t (1 β€ t β€ 1000) β the number of test cases.
The next t lines describe test cases. For each test case the only line contains three integers x, n, m (1β€ x β€ 10^5, 0β€ n,mβ€30) β the dragon's intitial hit point, the maximum number of Void Absorptions and Lightning Strikes Kana can cast respectively.
Output
If it is possible to defeat the dragon, print "YES" (without quotes). Otherwise, print "NO" (without quotes).
You can print each letter in any case (upper or lower).
Example
Input
7
100 3 4
189 3 4
64 2 3
63 2 3
30 27 7
10 9 1
69117 21 2
Output
YES
NO
NO
YES
YES
YES
YES
Note
One possible casting sequence of the first test case is shown below:
* Void Absorption \leftβ 100/2 \rightβ + 10=60.
* Lightning Strike 60-10=50.
* Void Absorption \leftβ 50/2 \rightβ + 10=35.
* Void Absorption \leftβ 35/2 \rightβ + 10=27.
* Lightning Strike 27-10=17.
* Lightning Strike 17-10=7.
* Lightning Strike 7-10=-3. | instruction | 0 | 50,639 | 2 | 101,278 |
Tags: greedy, implementation, math
Correct Solution:
```
t=int(input())
for _ in range(t):
x,n,m=map(int,input().split())
if(m*10>=x):
print("YES")
else:
for i in range(n):
x=(x//2)+10
for i in range(m):
x=x-10
if(x<=0):
print("YES")
else:
print("NO")
``` | output | 1 | 50,639 | 2 | 101,279 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Kana was just an ordinary high school girl before a talent scout discovered her. Then, she became an idol. But different from the stereotype, she is also a gameholic.
One day Kana gets interested in a new adventure game called Dragon Quest. In this game, her quest is to beat a dragon.
<image>
The dragon has a hit point of x initially. When its hit point goes to 0 or under 0, it will be defeated. In order to defeat the dragon, Kana can cast the two following types of spells.
* Void Absorption
Assume that the dragon's current hit point is h, after casting this spell its hit point will become \leftβ h/2 \rightβ + 10. Here \leftβ h/2 \rightβ denotes h divided by two, rounded down.
* Lightning Strike
This spell will decrease the dragon's hit point by 10. Assume that the dragon's current hit point is h, after casting this spell its hit point will be lowered to h-10.
Due to some reasons Kana can only cast no more than n Void Absorptions and m Lightning Strikes. She can cast the spells in any order and doesn't have to cast all the spells. Kana isn't good at math, so you are going to help her to find out whether it is possible to defeat the dragon.
Input
The first line contains a single integer t (1 β€ t β€ 1000) β the number of test cases.
The next t lines describe test cases. For each test case the only line contains three integers x, n, m (1β€ x β€ 10^5, 0β€ n,mβ€30) β the dragon's intitial hit point, the maximum number of Void Absorptions and Lightning Strikes Kana can cast respectively.
Output
If it is possible to defeat the dragon, print "YES" (without quotes). Otherwise, print "NO" (without quotes).
You can print each letter in any case (upper or lower).
Example
Input
7
100 3 4
189 3 4
64 2 3
63 2 3
30 27 7
10 9 1
69117 21 2
Output
YES
NO
NO
YES
YES
YES
YES
Note
One possible casting sequence of the first test case is shown below:
* Void Absorption \leftβ 100/2 \rightβ + 10=60.
* Lightning Strike 60-10=50.
* Void Absorption \leftβ 50/2 \rightβ + 10=35.
* Void Absorption \leftβ 35/2 \rightβ + 10=27.
* Lightning Strike 27-10=17.
* Lightning Strike 17-10=7.
* Lightning Strike 7-10=-3. | instruction | 0 | 50,640 | 2 | 101,280 |
Tags: greedy, implementation, math
Correct Solution:
```
t=int(input())
for i in range(0,t):
x,n,m=map(int,input().split())
while x>20 and n>0:
x=x//2+10
n-=1
if x<=10*m:
print('YES')
else:
print('NO')
``` | output | 1 | 50,640 | 2 | 101,281 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Kana was just an ordinary high school girl before a talent scout discovered her. Then, she became an idol. But different from the stereotype, she is also a gameholic.
One day Kana gets interested in a new adventure game called Dragon Quest. In this game, her quest is to beat a dragon.
<image>
The dragon has a hit point of x initially. When its hit point goes to 0 or under 0, it will be defeated. In order to defeat the dragon, Kana can cast the two following types of spells.
* Void Absorption
Assume that the dragon's current hit point is h, after casting this spell its hit point will become \leftβ h/2 \rightβ + 10. Here \leftβ h/2 \rightβ denotes h divided by two, rounded down.
* Lightning Strike
This spell will decrease the dragon's hit point by 10. Assume that the dragon's current hit point is h, after casting this spell its hit point will be lowered to h-10.
Due to some reasons Kana can only cast no more than n Void Absorptions and m Lightning Strikes. She can cast the spells in any order and doesn't have to cast all the spells. Kana isn't good at math, so you are going to help her to find out whether it is possible to defeat the dragon.
Input
The first line contains a single integer t (1 β€ t β€ 1000) β the number of test cases.
The next t lines describe test cases. For each test case the only line contains three integers x, n, m (1β€ x β€ 10^5, 0β€ n,mβ€30) β the dragon's intitial hit point, the maximum number of Void Absorptions and Lightning Strikes Kana can cast respectively.
Output
If it is possible to defeat the dragon, print "YES" (without quotes). Otherwise, print "NO" (without quotes).
You can print each letter in any case (upper or lower).
Example
Input
7
100 3 4
189 3 4
64 2 3
63 2 3
30 27 7
10 9 1
69117 21 2
Output
YES
NO
NO
YES
YES
YES
YES
Note
One possible casting sequence of the first test case is shown below:
* Void Absorption \leftβ 100/2 \rightβ + 10=60.
* Lightning Strike 60-10=50.
* Void Absorption \leftβ 50/2 \rightβ + 10=35.
* Void Absorption \leftβ 35/2 \rightβ + 10=27.
* Lightning Strike 27-10=17.
* Lightning Strike 17-10=7.
* Lightning Strike 7-10=-3. | instruction | 0 | 50,641 | 2 | 101,282 |
Tags: greedy, implementation, math
Correct Solution:
```
TC = int(input())
for _ in range(TC):
x, n, m = map(int, input().split())
if x <= 20:
if x > 10 * m:
print("NO")
else:
print("YES")
continue
while x > 20 and n > 0:
x = x // 2 + 10
n -= 1
if x > 10 * m:
print("NO")
else:
print("YES")
``` | output | 1 | 50,641 | 2 | 101,283 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Kana was just an ordinary high school girl before a talent scout discovered her. Then, she became an idol. But different from the stereotype, she is also a gameholic.
One day Kana gets interested in a new adventure game called Dragon Quest. In this game, her quest is to beat a dragon.
<image>
The dragon has a hit point of x initially. When its hit point goes to 0 or under 0, it will be defeated. In order to defeat the dragon, Kana can cast the two following types of spells.
* Void Absorption
Assume that the dragon's current hit point is h, after casting this spell its hit point will become \leftβ h/2 \rightβ + 10. Here \leftβ h/2 \rightβ denotes h divided by two, rounded down.
* Lightning Strike
This spell will decrease the dragon's hit point by 10. Assume that the dragon's current hit point is h, after casting this spell its hit point will be lowered to h-10.
Due to some reasons Kana can only cast no more than n Void Absorptions and m Lightning Strikes. She can cast the spells in any order and doesn't have to cast all the spells. Kana isn't good at math, so you are going to help her to find out whether it is possible to defeat the dragon.
Input
The first line contains a single integer t (1 β€ t β€ 1000) β the number of test cases.
The next t lines describe test cases. For each test case the only line contains three integers x, n, m (1β€ x β€ 10^5, 0β€ n,mβ€30) β the dragon's intitial hit point, the maximum number of Void Absorptions and Lightning Strikes Kana can cast respectively.
Output
If it is possible to defeat the dragon, print "YES" (without quotes). Otherwise, print "NO" (without quotes).
You can print each letter in any case (upper or lower).
Example
Input
7
100 3 4
189 3 4
64 2 3
63 2 3
30 27 7
10 9 1
69117 21 2
Output
YES
NO
NO
YES
YES
YES
YES
Note
One possible casting sequence of the first test case is shown below:
* Void Absorption \leftβ 100/2 \rightβ + 10=60.
* Lightning Strike 60-10=50.
* Void Absorption \leftβ 50/2 \rightβ + 10=35.
* Void Absorption \leftβ 35/2 \rightβ + 10=27.
* Lightning Strike 27-10=17.
* Lightning Strike 17-10=7.
* Lightning Strike 7-10=-3. | instruction | 0 | 50,642 | 2 | 101,284 |
Tags: greedy, implementation, math
Correct Solution:
```
t = int(input())
for _ in range(t):
a, b, c = map(int, input().split())
for i in range(b):
if a <= c * 10:
break
a = a // 2 + 10
a -= c * 10
if a <= 0:
print('YES')
else:
print('NO')
``` | output | 1 | 50,642 | 2 | 101,285 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Kana was just an ordinary high school girl before a talent scout discovered her. Then, she became an idol. But different from the stereotype, she is also a gameholic.
One day Kana gets interested in a new adventure game called Dragon Quest. In this game, her quest is to beat a dragon.
<image>
The dragon has a hit point of x initially. When its hit point goes to 0 or under 0, it will be defeated. In order to defeat the dragon, Kana can cast the two following types of spells.
* Void Absorption
Assume that the dragon's current hit point is h, after casting this spell its hit point will become \leftβ h/2 \rightβ + 10. Here \leftβ h/2 \rightβ denotes h divided by two, rounded down.
* Lightning Strike
This spell will decrease the dragon's hit point by 10. Assume that the dragon's current hit point is h, after casting this spell its hit point will be lowered to h-10.
Due to some reasons Kana can only cast no more than n Void Absorptions and m Lightning Strikes. She can cast the spells in any order and doesn't have to cast all the spells. Kana isn't good at math, so you are going to help her to find out whether it is possible to defeat the dragon.
Input
The first line contains a single integer t (1 β€ t β€ 1000) β the number of test cases.
The next t lines describe test cases. For each test case the only line contains three integers x, n, m (1β€ x β€ 10^5, 0β€ n,mβ€30) β the dragon's intitial hit point, the maximum number of Void Absorptions and Lightning Strikes Kana can cast respectively.
Output
If it is possible to defeat the dragon, print "YES" (without quotes). Otherwise, print "NO" (without quotes).
You can print each letter in any case (upper or lower).
Example
Input
7
100 3 4
189 3 4
64 2 3
63 2 3
30 27 7
10 9 1
69117 21 2
Output
YES
NO
NO
YES
YES
YES
YES
Note
One possible casting sequence of the first test case is shown below:
* Void Absorption \leftβ 100/2 \rightβ + 10=60.
* Lightning Strike 60-10=50.
* Void Absorption \leftβ 50/2 \rightβ + 10=35.
* Void Absorption \leftβ 35/2 \rightβ + 10=27.
* Lightning Strike 27-10=17.
* Lightning Strike 17-10=7.
* Lightning Strike 7-10=-3.
Submitted Solution:
```
# cook your dish here
import math
def main():
for q in range(int(input())):
x,n,m = map(int,input().split())
for i in range(n):
if 10 > x - (x//2):
break
x = (x//2) + 10
for i in range(m):
x -= 10
print("YES" if x<=0 else "NO")
if __name__ == "__main__":
main()
``` | instruction | 0 | 50,643 | 2 | 101,286 |
Yes | output | 1 | 50,643 | 2 | 101,287 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Kana was just an ordinary high school girl before a talent scout discovered her. Then, she became an idol. But different from the stereotype, she is also a gameholic.
One day Kana gets interested in a new adventure game called Dragon Quest. In this game, her quest is to beat a dragon.
<image>
The dragon has a hit point of x initially. When its hit point goes to 0 or under 0, it will be defeated. In order to defeat the dragon, Kana can cast the two following types of spells.
* Void Absorption
Assume that the dragon's current hit point is h, after casting this spell its hit point will become \leftβ h/2 \rightβ + 10. Here \leftβ h/2 \rightβ denotes h divided by two, rounded down.
* Lightning Strike
This spell will decrease the dragon's hit point by 10. Assume that the dragon's current hit point is h, after casting this spell its hit point will be lowered to h-10.
Due to some reasons Kana can only cast no more than n Void Absorptions and m Lightning Strikes. She can cast the spells in any order and doesn't have to cast all the spells. Kana isn't good at math, so you are going to help her to find out whether it is possible to defeat the dragon.
Input
The first line contains a single integer t (1 β€ t β€ 1000) β the number of test cases.
The next t lines describe test cases. For each test case the only line contains three integers x, n, m (1β€ x β€ 10^5, 0β€ n,mβ€30) β the dragon's intitial hit point, the maximum number of Void Absorptions and Lightning Strikes Kana can cast respectively.
Output
If it is possible to defeat the dragon, print "YES" (without quotes). Otherwise, print "NO" (without quotes).
You can print each letter in any case (upper or lower).
Example
Input
7
100 3 4
189 3 4
64 2 3
63 2 3
30 27 7
10 9 1
69117 21 2
Output
YES
NO
NO
YES
YES
YES
YES
Note
One possible casting sequence of the first test case is shown below:
* Void Absorption \leftβ 100/2 \rightβ + 10=60.
* Lightning Strike 60-10=50.
* Void Absorption \leftβ 50/2 \rightβ + 10=35.
* Void Absorption \leftβ 35/2 \rightβ + 10=27.
* Lightning Strike 27-10=17.
* Lightning Strike 17-10=7.
* Lightning Strike 7-10=-3.
Submitted Solution:
```
import math
t = int(input())
for _ in range(t):
h, n, m = map(int, input().split())
count = 0
while(h > 0 and n > 0 and (h//2+10) < h):
n-=1
h = h//2 + 10
if h <= m*10:
print('YES')
else:
print('NO')
``` | instruction | 0 | 50,644 | 2 | 101,288 |
Yes | output | 1 | 50,644 | 2 | 101,289 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Kana was just an ordinary high school girl before a talent scout discovered her. Then, she became an idol. But different from the stereotype, she is also a gameholic.
One day Kana gets interested in a new adventure game called Dragon Quest. In this game, her quest is to beat a dragon.
<image>
The dragon has a hit point of x initially. When its hit point goes to 0 or under 0, it will be defeated. In order to defeat the dragon, Kana can cast the two following types of spells.
* Void Absorption
Assume that the dragon's current hit point is h, after casting this spell its hit point will become \leftβ h/2 \rightβ + 10. Here \leftβ h/2 \rightβ denotes h divided by two, rounded down.
* Lightning Strike
This spell will decrease the dragon's hit point by 10. Assume that the dragon's current hit point is h, after casting this spell its hit point will be lowered to h-10.
Due to some reasons Kana can only cast no more than n Void Absorptions and m Lightning Strikes. She can cast the spells in any order and doesn't have to cast all the spells. Kana isn't good at math, so you are going to help her to find out whether it is possible to defeat the dragon.
Input
The first line contains a single integer t (1 β€ t β€ 1000) β the number of test cases.
The next t lines describe test cases. For each test case the only line contains three integers x, n, m (1β€ x β€ 10^5, 0β€ n,mβ€30) β the dragon's intitial hit point, the maximum number of Void Absorptions and Lightning Strikes Kana can cast respectively.
Output
If it is possible to defeat the dragon, print "YES" (without quotes). Otherwise, print "NO" (without quotes).
You can print each letter in any case (upper or lower).
Example
Input
7
100 3 4
189 3 4
64 2 3
63 2 3
30 27 7
10 9 1
69117 21 2
Output
YES
NO
NO
YES
YES
YES
YES
Note
One possible casting sequence of the first test case is shown below:
* Void Absorption \leftβ 100/2 \rightβ + 10=60.
* Lightning Strike 60-10=50.
* Void Absorption \leftβ 50/2 \rightβ + 10=35.
* Void Absorption \leftβ 35/2 \rightβ + 10=27.
* Lightning Strike 27-10=17.
* Lightning Strike 17-10=7.
* Lightning Strike 7-10=-3.
Submitted Solution:
```
from math import *
def _i():
return [int(i) for i in input().split()]
def _f():
return [int(i) for i in input().split()]
for zz in range(int(input())):
x, n, m = _i()
ans = 0
while (x//2 + 10 < x) and n > 0:
ans += 1
x = x//2 + 10
n -= 1
while (x > 0) and m > 0:
x -= 10
m -= 1
if (x <= 0):
print("YES")
else:
print("NO")
``` | instruction | 0 | 50,645 | 2 | 101,290 |
Yes | output | 1 | 50,645 | 2 | 101,291 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Kana was just an ordinary high school girl before a talent scout discovered her. Then, she became an idol. But different from the stereotype, she is also a gameholic.
One day Kana gets interested in a new adventure game called Dragon Quest. In this game, her quest is to beat a dragon.
<image>
The dragon has a hit point of x initially. When its hit point goes to 0 or under 0, it will be defeated. In order to defeat the dragon, Kana can cast the two following types of spells.
* Void Absorption
Assume that the dragon's current hit point is h, after casting this spell its hit point will become \leftβ h/2 \rightβ + 10. Here \leftβ h/2 \rightβ denotes h divided by two, rounded down.
* Lightning Strike
This spell will decrease the dragon's hit point by 10. Assume that the dragon's current hit point is h, after casting this spell its hit point will be lowered to h-10.
Due to some reasons Kana can only cast no more than n Void Absorptions and m Lightning Strikes. She can cast the spells in any order and doesn't have to cast all the spells. Kana isn't good at math, so you are going to help her to find out whether it is possible to defeat the dragon.
Input
The first line contains a single integer t (1 β€ t β€ 1000) β the number of test cases.
The next t lines describe test cases. For each test case the only line contains three integers x, n, m (1β€ x β€ 10^5, 0β€ n,mβ€30) β the dragon's intitial hit point, the maximum number of Void Absorptions and Lightning Strikes Kana can cast respectively.
Output
If it is possible to defeat the dragon, print "YES" (without quotes). Otherwise, print "NO" (without quotes).
You can print each letter in any case (upper or lower).
Example
Input
7
100 3 4
189 3 4
64 2 3
63 2 3
30 27 7
10 9 1
69117 21 2
Output
YES
NO
NO
YES
YES
YES
YES
Note
One possible casting sequence of the first test case is shown below:
* Void Absorption \leftβ 100/2 \rightβ + 10=60.
* Lightning Strike 60-10=50.
* Void Absorption \leftβ 50/2 \rightβ + 10=35.
* Void Absorption \leftβ 35/2 \rightβ + 10=27.
* Lightning Strike 27-10=17.
* Lightning Strike 17-10=7.
* Lightning Strike 7-10=-3.
Submitted Solution:
```
for _ in range(int(input())):
h, n, m = map(int, input().split())
if(m==0):
print("NO")
else:
for i in range(n):
if(h<=20):
break
h=h//2+10
if(h<=m*10):
print("YES")
else:
print("NO")
``` | instruction | 0 | 50,646 | 2 | 101,292 |
Yes | output | 1 | 50,646 | 2 | 101,293 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Kana was just an ordinary high school girl before a talent scout discovered her. Then, she became an idol. But different from the stereotype, she is also a gameholic.
One day Kana gets interested in a new adventure game called Dragon Quest. In this game, her quest is to beat a dragon.
<image>
The dragon has a hit point of x initially. When its hit point goes to 0 or under 0, it will be defeated. In order to defeat the dragon, Kana can cast the two following types of spells.
* Void Absorption
Assume that the dragon's current hit point is h, after casting this spell its hit point will become \leftβ h/2 \rightβ + 10. Here \leftβ h/2 \rightβ denotes h divided by two, rounded down.
* Lightning Strike
This spell will decrease the dragon's hit point by 10. Assume that the dragon's current hit point is h, after casting this spell its hit point will be lowered to h-10.
Due to some reasons Kana can only cast no more than n Void Absorptions and m Lightning Strikes. She can cast the spells in any order and doesn't have to cast all the spells. Kana isn't good at math, so you are going to help her to find out whether it is possible to defeat the dragon.
Input
The first line contains a single integer t (1 β€ t β€ 1000) β the number of test cases.
The next t lines describe test cases. For each test case the only line contains three integers x, n, m (1β€ x β€ 10^5, 0β€ n,mβ€30) β the dragon's intitial hit point, the maximum number of Void Absorptions and Lightning Strikes Kana can cast respectively.
Output
If it is possible to defeat the dragon, print "YES" (without quotes). Otherwise, print "NO" (without quotes).
You can print each letter in any case (upper or lower).
Example
Input
7
100 3 4
189 3 4
64 2 3
63 2 3
30 27 7
10 9 1
69117 21 2
Output
YES
NO
NO
YES
YES
YES
YES
Note
One possible casting sequence of the first test case is shown below:
* Void Absorption \leftβ 100/2 \rightβ + 10=60.
* Lightning Strike 60-10=50.
* Void Absorption \leftβ 50/2 \rightβ + 10=35.
* Void Absorption \leftβ 35/2 \rightβ + 10=27.
* Lightning Strike 27-10=17.
* Lightning Strike 17-10=7.
* Lightning Strike 7-10=-3.
Submitted Solution:
```
import math
t = int(input())
for _ in range(t):
h, n, m = map(int, input().split())
count = 0
flag = True
while(h > 0):
if n == 0 and m == 0:
break
if (h//2+10) < (h-10) and n > 0:
h = (h//2+10)
n -= 1
elif (h//2+10) > (h-10) and m > 0:
h -= 10
m -= 1
else:
h -= 10
if n > 0 and n > m: n-=1
else: m-=1
if h <= 0 and not (n < 0 and m < 0):
print('YES')
else:
print('NO')
``` | instruction | 0 | 50,647 | 2 | 101,294 |
No | output | 1 | 50,647 | 2 | 101,295 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Kana was just an ordinary high school girl before a talent scout discovered her. Then, she became an idol. But different from the stereotype, she is also a gameholic.
One day Kana gets interested in a new adventure game called Dragon Quest. In this game, her quest is to beat a dragon.
<image>
The dragon has a hit point of x initially. When its hit point goes to 0 or under 0, it will be defeated. In order to defeat the dragon, Kana can cast the two following types of spells.
* Void Absorption
Assume that the dragon's current hit point is h, after casting this spell its hit point will become \leftβ h/2 \rightβ + 10. Here \leftβ h/2 \rightβ denotes h divided by two, rounded down.
* Lightning Strike
This spell will decrease the dragon's hit point by 10. Assume that the dragon's current hit point is h, after casting this spell its hit point will be lowered to h-10.
Due to some reasons Kana can only cast no more than n Void Absorptions and m Lightning Strikes. She can cast the spells in any order and doesn't have to cast all the spells. Kana isn't good at math, so you are going to help her to find out whether it is possible to defeat the dragon.
Input
The first line contains a single integer t (1 β€ t β€ 1000) β the number of test cases.
The next t lines describe test cases. For each test case the only line contains three integers x, n, m (1β€ x β€ 10^5, 0β€ n,mβ€30) β the dragon's intitial hit point, the maximum number of Void Absorptions and Lightning Strikes Kana can cast respectively.
Output
If it is possible to defeat the dragon, print "YES" (without quotes). Otherwise, print "NO" (without quotes).
You can print each letter in any case (upper or lower).
Example
Input
7
100 3 4
189 3 4
64 2 3
63 2 3
30 27 7
10 9 1
69117 21 2
Output
YES
NO
NO
YES
YES
YES
YES
Note
One possible casting sequence of the first test case is shown below:
* Void Absorption \leftβ 100/2 \rightβ + 10=60.
* Lightning Strike 60-10=50.
* Void Absorption \leftβ 50/2 \rightβ + 10=35.
* Void Absorption \leftβ 35/2 \rightβ + 10=27.
* Lightning Strike 27-10=17.
* Lightning Strike 17-10=7.
* Lightning Strike 7-10=-3.
Submitted Solution:
```
import sys
import math
def get_array(): return list(map(int,sys.stdin.readline().strip().split()))
def get_ints(): return map(int,sys.stdin.readline().strip().split())
def input(): return sys.stdin.readline().strip()
for _ in range(int(input())):
a,b,c=get_ints()
if a>=20:
for i in range(b):
ans=a//2+10
a=ans
if ans<=0:
break
if ans>0:
for j in range(c):
ans=ans-10
if ans<=0:
break
else:
for j in range(c):
a=a-10
if a<=0:
break
if a>0:
for i in range(b):
ans=a//2+10
a=ans
if ans<=0:
break
if ans<=0:
print("YES")
else:
print("NO")
``` | instruction | 0 | 50,648 | 2 | 101,296 |
No | output | 1 | 50,648 | 2 | 101,297 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Kana was just an ordinary high school girl before a talent scout discovered her. Then, she became an idol. But different from the stereotype, she is also a gameholic.
One day Kana gets interested in a new adventure game called Dragon Quest. In this game, her quest is to beat a dragon.
<image>
The dragon has a hit point of x initially. When its hit point goes to 0 or under 0, it will be defeated. In order to defeat the dragon, Kana can cast the two following types of spells.
* Void Absorption
Assume that the dragon's current hit point is h, after casting this spell its hit point will become \leftβ h/2 \rightβ + 10. Here \leftβ h/2 \rightβ denotes h divided by two, rounded down.
* Lightning Strike
This spell will decrease the dragon's hit point by 10. Assume that the dragon's current hit point is h, after casting this spell its hit point will be lowered to h-10.
Due to some reasons Kana can only cast no more than n Void Absorptions and m Lightning Strikes. She can cast the spells in any order and doesn't have to cast all the spells. Kana isn't good at math, so you are going to help her to find out whether it is possible to defeat the dragon.
Input
The first line contains a single integer t (1 β€ t β€ 1000) β the number of test cases.
The next t lines describe test cases. For each test case the only line contains three integers x, n, m (1β€ x β€ 10^5, 0β€ n,mβ€30) β the dragon's intitial hit point, the maximum number of Void Absorptions and Lightning Strikes Kana can cast respectively.
Output
If it is possible to defeat the dragon, print "YES" (without quotes). Otherwise, print "NO" (without quotes).
You can print each letter in any case (upper or lower).
Example
Input
7
100 3 4
189 3 4
64 2 3
63 2 3
30 27 7
10 9 1
69117 21 2
Output
YES
NO
NO
YES
YES
YES
YES
Note
One possible casting sequence of the first test case is shown below:
* Void Absorption \leftβ 100/2 \rightβ + 10=60.
* Lightning Strike 60-10=50.
* Void Absorption \leftβ 50/2 \rightβ + 10=35.
* Void Absorption \leftβ 35/2 \rightβ + 10=27.
* Lightning Strike 27-10=17.
* Lightning Strike 17-10=7.
* Lightning Strike 7-10=-3.
Submitted Solution:
```
def dragon(h,n,m):
while(h>20):
h = h//2 + 10
n -=1
if n==0:
break
if h - 10*m > 0:
return False
return True
n = int(input())
for _ in range(n):
inp = input().split()
if dragon(int(inp[0]), int(inp[1]), int(inp[2])):
print("YES", flush=True)
else:
print("NO", flush=True)
``` | instruction | 0 | 50,649 | 2 | 101,298 |
No | output | 1 | 50,649 | 2 | 101,299 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Kana was just an ordinary high school girl before a talent scout discovered her. Then, she became an idol. But different from the stereotype, she is also a gameholic.
One day Kana gets interested in a new adventure game called Dragon Quest. In this game, her quest is to beat a dragon.
<image>
The dragon has a hit point of x initially. When its hit point goes to 0 or under 0, it will be defeated. In order to defeat the dragon, Kana can cast the two following types of spells.
* Void Absorption
Assume that the dragon's current hit point is h, after casting this spell its hit point will become \leftβ h/2 \rightβ + 10. Here \leftβ h/2 \rightβ denotes h divided by two, rounded down.
* Lightning Strike
This spell will decrease the dragon's hit point by 10. Assume that the dragon's current hit point is h, after casting this spell its hit point will be lowered to h-10.
Due to some reasons Kana can only cast no more than n Void Absorptions and m Lightning Strikes. She can cast the spells in any order and doesn't have to cast all the spells. Kana isn't good at math, so you are going to help her to find out whether it is possible to defeat the dragon.
Input
The first line contains a single integer t (1 β€ t β€ 1000) β the number of test cases.
The next t lines describe test cases. For each test case the only line contains three integers x, n, m (1β€ x β€ 10^5, 0β€ n,mβ€30) β the dragon's intitial hit point, the maximum number of Void Absorptions and Lightning Strikes Kana can cast respectively.
Output
If it is possible to defeat the dragon, print "YES" (without quotes). Otherwise, print "NO" (without quotes).
You can print each letter in any case (upper or lower).
Example
Input
7
100 3 4
189 3 4
64 2 3
63 2 3
30 27 7
10 9 1
69117 21 2
Output
YES
NO
NO
YES
YES
YES
YES
Note
One possible casting sequence of the first test case is shown below:
* Void Absorption \leftβ 100/2 \rightβ + 10=60.
* Lightning Strike 60-10=50.
* Void Absorption \leftβ 50/2 \rightβ + 10=35.
* Void Absorption \leftβ 35/2 \rightβ + 10=27.
* Lightning Strike 27-10=17.
* Lightning Strike 17-10=7.
* Lightning Strike 7-10=-3.
Submitted Solution:
```
import math
testin = int(input())
# print(testin)
for _ in range(testin):
point, n, m = list(map(int, input().split(' ')))
# print(point, n, m)
while n != 0 and point > 40:
point = math.floor(point/2)+10
# print(point)
n -= 1
if m*10 >= point:
point -= m*10
if point > 0:
print("NO")
else:
print("YES")
``` | instruction | 0 | 50,650 | 2 | 101,300 |
No | output | 1 | 50,650 | 2 | 101,301 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are an adventurer currently journeying inside an evil temple. After defeating a couple of weak zombies, you arrived at a square room consisting of tiles forming an n Γ n grid. The rows are numbered 1 through n from top to bottom, and the columns are numbered 1 through n from left to right. At the far side of the room lies a door locked with evil magical forces. The following inscriptions are written on the door:
The cleaning of all evil will awaken the door!
Being a very senior adventurer, you immediately realize what this means. You notice that every single cell in the grid are initially evil. You should purify all of these cells.
The only method of tile purification known to you is by casting the "Purification" spell. You cast this spell on a single tile β then, all cells that are located in the same row and all cells that are located in the same column as the selected tile become purified (including the selected tile)! It is allowed to purify a cell more than once.
You would like to purify all n Γ n cells while minimizing the number of times you cast the "Purification" spell. This sounds very easy, but you just noticed that some tiles are particularly more evil than the other tiles. You cannot cast the "Purification" spell on those particularly more evil tiles, not even after they have been purified. They can still be purified if a cell sharing the same row or the same column gets selected by the "Purification" spell.
Please find some way to purify all the cells with the minimum number of spells cast. Print -1 if there is no such way.
Input
The first line will contain a single integer n (1 β€ n β€ 100). Then, n lines follows, each contains n characters. The j-th character in the i-th row represents the cell located at row i and column j. It will be the character 'E' if it is a particularly more evil cell, and '.' otherwise.
Output
If there exists no way to purify all the cells, output -1. Otherwise, if your solution casts x "Purification" spells (where x is the minimum possible number of spells), output x lines. Each line should consist of two integers denoting the row and column numbers of the cell on which you should cast the "Purification" spell.
Examples
Input
3
.E.
E.E
.E.
Output
1 1
2 2
3 3
Input
3
EEE
E..
E.E
Output
-1
Input
5
EE.EE
E.EE.
E...E
.EE.E
EE.EE
Output
3 3
1 3
2 2
4 4
5 3
Note
The first example is illustrated as follows. Purple tiles are evil tiles that have not yet been purified. Red tile is the tile on which "Purification" is cast. Yellow tiles are the tiles being purified as a result of the current "Purification" spell. Green tiles are tiles that have been purified previously.
<image>
In the second example, it is impossible to purify the cell located at row 1 and column 1.
For the third example:
<image> | instruction | 0 | 51,639 | 2 | 103,278 |
Tags: constructive algorithms, greedy
Correct Solution:
```
n = int(input())
inp = [input() for i in range(n)]
A = [[0 for j in range(n)] for i in range(n)]
for i in range(n):
for j in range(n):
if inp[i][j] == 'E':
A[i][j] = 1
k = 0
for i in A:
if sum(i) == n:
k += 1
c = 0
for j in range(n):
s = 0
for i in range(n):
s += A[i][j]
if s == n:
c += 1
if k > 0 and c > 0:
print(-1)
exit(0)
if c > 0:
for i in range(n):
for j in range(n):
if A[i][j] == 0:
print(i + 1, j + 1)
break
else:
for j in range(n):
for i in range(n):
if A[i][j] == 0:
print(i + 1, j + 1)
break
``` | output | 1 | 51,639 | 2 | 103,279 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are an adventurer currently journeying inside an evil temple. After defeating a couple of weak zombies, you arrived at a square room consisting of tiles forming an n Γ n grid. The rows are numbered 1 through n from top to bottom, and the columns are numbered 1 through n from left to right. At the far side of the room lies a door locked with evil magical forces. The following inscriptions are written on the door:
The cleaning of all evil will awaken the door!
Being a very senior adventurer, you immediately realize what this means. You notice that every single cell in the grid are initially evil. You should purify all of these cells.
The only method of tile purification known to you is by casting the "Purification" spell. You cast this spell on a single tile β then, all cells that are located in the same row and all cells that are located in the same column as the selected tile become purified (including the selected tile)! It is allowed to purify a cell more than once.
You would like to purify all n Γ n cells while minimizing the number of times you cast the "Purification" spell. This sounds very easy, but you just noticed that some tiles are particularly more evil than the other tiles. You cannot cast the "Purification" spell on those particularly more evil tiles, not even after they have been purified. They can still be purified if a cell sharing the same row or the same column gets selected by the "Purification" spell.
Please find some way to purify all the cells with the minimum number of spells cast. Print -1 if there is no such way.
Input
The first line will contain a single integer n (1 β€ n β€ 100). Then, n lines follows, each contains n characters. The j-th character in the i-th row represents the cell located at row i and column j. It will be the character 'E' if it is a particularly more evil cell, and '.' otherwise.
Output
If there exists no way to purify all the cells, output -1. Otherwise, if your solution casts x "Purification" spells (where x is the minimum possible number of spells), output x lines. Each line should consist of two integers denoting the row and column numbers of the cell on which you should cast the "Purification" spell.
Examples
Input
3
.E.
E.E
.E.
Output
1 1
2 2
3 3
Input
3
EEE
E..
E.E
Output
-1
Input
5
EE.EE
E.EE.
E...E
.EE.E
EE.EE
Output
3 3
1 3
2 2
4 4
5 3
Note
The first example is illustrated as follows. Purple tiles are evil tiles that have not yet been purified. Red tile is the tile on which "Purification" is cast. Yellow tiles are the tiles being purified as a result of the current "Purification" spell. Green tiles are tiles that have been purified previously.
<image>
In the second example, it is impossible to purify the cell located at row 1 and column 1.
For the third example:
<image> | instruction | 0 | 51,640 | 2 | 103,280 |
Tags: constructive algorithms, greedy
Correct Solution:
```
n = int(input())
a = []
for i in range(n):
a.append(input())
if 'E' * n in a and ('E',) * n in zip(*a):
print(-1)
elif 'E' * n in a:
for j, s in enumerate(map(lambda x: ''.join(x), zip(*a))):
for i, c in enumerate(s):
if c == '.':
print(i + 1, j + 1)
break
else:
for i, s in enumerate(a):
for j, c in enumerate(s):
if c == '.':
print(i + 1, j + 1)
break
# Made By Mostafa_Khaled
``` | output | 1 | 51,640 | 2 | 103,281 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are an adventurer currently journeying inside an evil temple. After defeating a couple of weak zombies, you arrived at a square room consisting of tiles forming an n Γ n grid. The rows are numbered 1 through n from top to bottom, and the columns are numbered 1 through n from left to right. At the far side of the room lies a door locked with evil magical forces. The following inscriptions are written on the door:
The cleaning of all evil will awaken the door!
Being a very senior adventurer, you immediately realize what this means. You notice that every single cell in the grid are initially evil. You should purify all of these cells.
The only method of tile purification known to you is by casting the "Purification" spell. You cast this spell on a single tile β then, all cells that are located in the same row and all cells that are located in the same column as the selected tile become purified (including the selected tile)! It is allowed to purify a cell more than once.
You would like to purify all n Γ n cells while minimizing the number of times you cast the "Purification" spell. This sounds very easy, but you just noticed that some tiles are particularly more evil than the other tiles. You cannot cast the "Purification" spell on those particularly more evil tiles, not even after they have been purified. They can still be purified if a cell sharing the same row or the same column gets selected by the "Purification" spell.
Please find some way to purify all the cells with the minimum number of spells cast. Print -1 if there is no such way.
Input
The first line will contain a single integer n (1 β€ n β€ 100). Then, n lines follows, each contains n characters. The j-th character in the i-th row represents the cell located at row i and column j. It will be the character 'E' if it is a particularly more evil cell, and '.' otherwise.
Output
If there exists no way to purify all the cells, output -1. Otherwise, if your solution casts x "Purification" spells (where x is the minimum possible number of spells), output x lines. Each line should consist of two integers denoting the row and column numbers of the cell on which you should cast the "Purification" spell.
Examples
Input
3
.E.
E.E
.E.
Output
1 1
2 2
3 3
Input
3
EEE
E..
E.E
Output
-1
Input
5
EE.EE
E.EE.
E...E
.EE.E
EE.EE
Output
3 3
1 3
2 2
4 4
5 3
Note
The first example is illustrated as follows. Purple tiles are evil tiles that have not yet been purified. Red tile is the tile on which "Purification" is cast. Yellow tiles are the tiles being purified as a result of the current "Purification" spell. Green tiles are tiles that have been purified previously.
<image>
In the second example, it is impossible to purify the cell located at row 1 and column 1.
For the third example:
<image> | instruction | 0 | 51,641 | 2 | 103,282 |
Tags: constructive algorithms, greedy
Correct Solution:
```
class Solver(object):
def read_input(self):
n = int(input())
grid = []
for i in range(n):
l = list(input())
grid.append(l)
self.n = n
self.grid = grid
def solve_line(self):
pos = []
for i in range(self.n):
res = False
for j in range(self.n):
if self.grid[i][j]==".":
res = True
pos.append((i,j))
if res==True:
break
if res==True:
continue
else:
pos = -1
break
self.pos = pos
return pos
def solve_column(self):
pos = []
for j in range(self.n):
res = False
for i in range(self.n):
if self.grid[i][j]==".":
res = True
pos.append((i,j))
if res==True:
break
if res==True:
continue
else:
pos = -1
break
self.pos = pos
return pos
def print_solution(self):
for i, j in self.pos:
print(i+1, j+1)
def solve(self):
lines = self.solve_line()
if lines != -1:
self.print_solution()
else:
cols = self.solve_column()
if cols == -1:
print(-1)
else:
self.print_solution()
S = Solver()
S.read_input()
S.solve()
``` | output | 1 | 51,641 | 2 | 103,283 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are an adventurer currently journeying inside an evil temple. After defeating a couple of weak zombies, you arrived at a square room consisting of tiles forming an n Γ n grid. The rows are numbered 1 through n from top to bottom, and the columns are numbered 1 through n from left to right. At the far side of the room lies a door locked with evil magical forces. The following inscriptions are written on the door:
The cleaning of all evil will awaken the door!
Being a very senior adventurer, you immediately realize what this means. You notice that every single cell in the grid are initially evil. You should purify all of these cells.
The only method of tile purification known to you is by casting the "Purification" spell. You cast this spell on a single tile β then, all cells that are located in the same row and all cells that are located in the same column as the selected tile become purified (including the selected tile)! It is allowed to purify a cell more than once.
You would like to purify all n Γ n cells while minimizing the number of times you cast the "Purification" spell. This sounds very easy, but you just noticed that some tiles are particularly more evil than the other tiles. You cannot cast the "Purification" spell on those particularly more evil tiles, not even after they have been purified. They can still be purified if a cell sharing the same row or the same column gets selected by the "Purification" spell.
Please find some way to purify all the cells with the minimum number of spells cast. Print -1 if there is no such way.
Input
The first line will contain a single integer n (1 β€ n β€ 100). Then, n lines follows, each contains n characters. The j-th character in the i-th row represents the cell located at row i and column j. It will be the character 'E' if it is a particularly more evil cell, and '.' otherwise.
Output
If there exists no way to purify all the cells, output -1. Otherwise, if your solution casts x "Purification" spells (where x is the minimum possible number of spells), output x lines. Each line should consist of two integers denoting the row and column numbers of the cell on which you should cast the "Purification" spell.
Examples
Input
3
.E.
E.E
.E.
Output
1 1
2 2
3 3
Input
3
EEE
E..
E.E
Output
-1
Input
5
EE.EE
E.EE.
E...E
.EE.E
EE.EE
Output
3 3
1 3
2 2
4 4
5 3
Note
The first example is illustrated as follows. Purple tiles are evil tiles that have not yet been purified. Red tile is the tile on which "Purification" is cast. Yellow tiles are the tiles being purified as a result of the current "Purification" spell. Green tiles are tiles that have been purified previously.
<image>
In the second example, it is impossible to purify the cell located at row 1 and column 1.
For the third example:
<image> | instruction | 0 | 51,642 | 2 | 103,284 |
Tags: constructive algorithms, greedy
Correct Solution:
```
from sys import stdin
__author__ = 'artyom'
def solve(x):
a = []
for s in x:
dot_pos = s.find('.')
if dot_pos < 0:
return None
a.append(dot_pos + 1)
return a
def rotate(x, n):
y = []
for i in range(n):
y.append([])
for j in range(n):
y[i].append(x[j][i])
return map(lambda b: ''.join(b), y)
n = int(stdin.readline().strip())
x = []
for _ in range(n):
x.append(stdin.readline().strip())
a = solve(x)
if a:
for i in range(n):
print(i + 1, a[i])
else:
a = solve(rotate(x, n))
if a:
for i in range(n):
print(a[i], i + 1)
else:
print(-1)
``` | output | 1 | 51,642 | 2 | 103,285 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are an adventurer currently journeying inside an evil temple. After defeating a couple of weak zombies, you arrived at a square room consisting of tiles forming an n Γ n grid. The rows are numbered 1 through n from top to bottom, and the columns are numbered 1 through n from left to right. At the far side of the room lies a door locked with evil magical forces. The following inscriptions are written on the door:
The cleaning of all evil will awaken the door!
Being a very senior adventurer, you immediately realize what this means. You notice that every single cell in the grid are initially evil. You should purify all of these cells.
The only method of tile purification known to you is by casting the "Purification" spell. You cast this spell on a single tile β then, all cells that are located in the same row and all cells that are located in the same column as the selected tile become purified (including the selected tile)! It is allowed to purify a cell more than once.
You would like to purify all n Γ n cells while minimizing the number of times you cast the "Purification" spell. This sounds very easy, but you just noticed that some tiles are particularly more evil than the other tiles. You cannot cast the "Purification" spell on those particularly more evil tiles, not even after they have been purified. They can still be purified if a cell sharing the same row or the same column gets selected by the "Purification" spell.
Please find some way to purify all the cells with the minimum number of spells cast. Print -1 if there is no such way.
Input
The first line will contain a single integer n (1 β€ n β€ 100). Then, n lines follows, each contains n characters. The j-th character in the i-th row represents the cell located at row i and column j. It will be the character 'E' if it is a particularly more evil cell, and '.' otherwise.
Output
If there exists no way to purify all the cells, output -1. Otherwise, if your solution casts x "Purification" spells (where x is the minimum possible number of spells), output x lines. Each line should consist of two integers denoting the row and column numbers of the cell on which you should cast the "Purification" spell.
Examples
Input
3
.E.
E.E
.E.
Output
1 1
2 2
3 3
Input
3
EEE
E..
E.E
Output
-1
Input
5
EE.EE
E.EE.
E...E
.EE.E
EE.EE
Output
3 3
1 3
2 2
4 4
5 3
Note
The first example is illustrated as follows. Purple tiles are evil tiles that have not yet been purified. Red tile is the tile on which "Purification" is cast. Yellow tiles are the tiles being purified as a result of the current "Purification" spell. Green tiles are tiles that have been purified previously.
<image>
In the second example, it is impossible to purify the cell located at row 1 and column 1.
For the third example:
<image> | instruction | 0 | 51,643 | 2 | 103,286 |
Tags: constructive algorithms, greedy
Correct Solution:
```
def main():
n = int(input())
l = [input() for _ in range(n)]
res = []
for y, s in enumerate(l):
for x, c in enumerate(s):
if c == '.':
res.append((x, y))
break
if len(res) < n:
res = []
for x in range(n):
for y in range(n):
if l[y][x] == '.':
res.append((x, y))
break
if len(res) < n:
print(-1)
return
for x, y in res:
print(y + 1, x + 1)
if __name__ == '__main__':
main()
``` | output | 1 | 51,643 | 2 | 103,287 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are an adventurer currently journeying inside an evil temple. After defeating a couple of weak zombies, you arrived at a square room consisting of tiles forming an n Γ n grid. The rows are numbered 1 through n from top to bottom, and the columns are numbered 1 through n from left to right. At the far side of the room lies a door locked with evil magical forces. The following inscriptions are written on the door:
The cleaning of all evil will awaken the door!
Being a very senior adventurer, you immediately realize what this means. You notice that every single cell in the grid are initially evil. You should purify all of these cells.
The only method of tile purification known to you is by casting the "Purification" spell. You cast this spell on a single tile β then, all cells that are located in the same row and all cells that are located in the same column as the selected tile become purified (including the selected tile)! It is allowed to purify a cell more than once.
You would like to purify all n Γ n cells while minimizing the number of times you cast the "Purification" spell. This sounds very easy, but you just noticed that some tiles are particularly more evil than the other tiles. You cannot cast the "Purification" spell on those particularly more evil tiles, not even after they have been purified. They can still be purified if a cell sharing the same row or the same column gets selected by the "Purification" spell.
Please find some way to purify all the cells with the minimum number of spells cast. Print -1 if there is no such way.
Input
The first line will contain a single integer n (1 β€ n β€ 100). Then, n lines follows, each contains n characters. The j-th character in the i-th row represents the cell located at row i and column j. It will be the character 'E' if it is a particularly more evil cell, and '.' otherwise.
Output
If there exists no way to purify all the cells, output -1. Otherwise, if your solution casts x "Purification" spells (where x is the minimum possible number of spells), output x lines. Each line should consist of two integers denoting the row and column numbers of the cell on which you should cast the "Purification" spell.
Examples
Input
3
.E.
E.E
.E.
Output
1 1
2 2
3 3
Input
3
EEE
E..
E.E
Output
-1
Input
5
EE.EE
E.EE.
E...E
.EE.E
EE.EE
Output
3 3
1 3
2 2
4 4
5 3
Note
The first example is illustrated as follows. Purple tiles are evil tiles that have not yet been purified. Red tile is the tile on which "Purification" is cast. Yellow tiles are the tiles being purified as a result of the current "Purification" spell. Green tiles are tiles that have been purified previously.
<image>
In the second example, it is impossible to purify the cell located at row 1 and column 1.
For the third example:
<image> | instruction | 0 | 51,644 | 2 | 103,288 |
Tags: constructive algorithms, greedy
Correct Solution:
```
import traceback
import math
from collections import defaultdict
from functools import lru_cache
def main():
N = int(input())
grid = []
for _ in range(N):
s = input()
grid.append(s)
if all('.' in [grid[i][j] for j in range(N)] for i in range(N)):
for i in range(N):
for j in range(N):
if grid[i][j] == '.':
print(i+1, j+1)
break
elif all('.' in [grid[i][j] for i in range(N)] for j in range(N)):
for j in range(N):
for i in range(N):
if grid[i][j] == '.':
print(i+1, j+1)
break
else:
print(-1)
try:
ans = main()
# print(ans)
except Exception as e:
traceback.print_exc()
``` | output | 1 | 51,644 | 2 | 103,289 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are an adventurer currently journeying inside an evil temple. After defeating a couple of weak zombies, you arrived at a square room consisting of tiles forming an n Γ n grid. The rows are numbered 1 through n from top to bottom, and the columns are numbered 1 through n from left to right. At the far side of the room lies a door locked with evil magical forces. The following inscriptions are written on the door:
The cleaning of all evil will awaken the door!
Being a very senior adventurer, you immediately realize what this means. You notice that every single cell in the grid are initially evil. You should purify all of these cells.
The only method of tile purification known to you is by casting the "Purification" spell. You cast this spell on a single tile β then, all cells that are located in the same row and all cells that are located in the same column as the selected tile become purified (including the selected tile)! It is allowed to purify a cell more than once.
You would like to purify all n Γ n cells while minimizing the number of times you cast the "Purification" spell. This sounds very easy, but you just noticed that some tiles are particularly more evil than the other tiles. You cannot cast the "Purification" spell on those particularly more evil tiles, not even after they have been purified. They can still be purified if a cell sharing the same row or the same column gets selected by the "Purification" spell.
Please find some way to purify all the cells with the minimum number of spells cast. Print -1 if there is no such way.
Input
The first line will contain a single integer n (1 β€ n β€ 100). Then, n lines follows, each contains n characters. The j-th character in the i-th row represents the cell located at row i and column j. It will be the character 'E' if it is a particularly more evil cell, and '.' otherwise.
Output
If there exists no way to purify all the cells, output -1. Otherwise, if your solution casts x "Purification" spells (where x is the minimum possible number of spells), output x lines. Each line should consist of two integers denoting the row and column numbers of the cell on which you should cast the "Purification" spell.
Examples
Input
3
.E.
E.E
.E.
Output
1 1
2 2
3 3
Input
3
EEE
E..
E.E
Output
-1
Input
5
EE.EE
E.EE.
E...E
.EE.E
EE.EE
Output
3 3
1 3
2 2
4 4
5 3
Note
The first example is illustrated as follows. Purple tiles are evil tiles that have not yet been purified. Red tile is the tile on which "Purification" is cast. Yellow tiles are the tiles being purified as a result of the current "Purification" spell. Green tiles are tiles that have been purified previously.
<image>
In the second example, it is impossible to purify the cell located at row 1 and column 1.
For the third example:
<image> | instruction | 0 | 51,645 | 2 | 103,290 |
Tags: constructive algorithms, greedy
Correct Solution:
```
n = int(input())
a = [input() for i in range(n)]
def checkRows():
for str in a:
if '.' not in str:
return False
return True
def solveRows():
i = 1
for str in a:
print(i, str.find('.') + 1)
i += 1
def checkColumns():
for j in range(n):
str = ''.join(a[i][j] for i in range(n))
if '.' not in str:
return False
return True
def solveColumns():
i = 1
for j in range(n):
str = ''.join(a[i][j] for i in range(n))
print (str.find('.') + 1, i)
i += 1
if checkRows():
solveRows()
elif checkColumns():
solveColumns()
else:
print('-1')
``` | output | 1 | 51,645 | 2 | 103,291 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are an adventurer currently journeying inside an evil temple. After defeating a couple of weak zombies, you arrived at a square room consisting of tiles forming an n Γ n grid. The rows are numbered 1 through n from top to bottom, and the columns are numbered 1 through n from left to right. At the far side of the room lies a door locked with evil magical forces. The following inscriptions are written on the door:
The cleaning of all evil will awaken the door!
Being a very senior adventurer, you immediately realize what this means. You notice that every single cell in the grid are initially evil. You should purify all of these cells.
The only method of tile purification known to you is by casting the "Purification" spell. You cast this spell on a single tile β then, all cells that are located in the same row and all cells that are located in the same column as the selected tile become purified (including the selected tile)! It is allowed to purify a cell more than once.
You would like to purify all n Γ n cells while minimizing the number of times you cast the "Purification" spell. This sounds very easy, but you just noticed that some tiles are particularly more evil than the other tiles. You cannot cast the "Purification" spell on those particularly more evil tiles, not even after they have been purified. They can still be purified if a cell sharing the same row or the same column gets selected by the "Purification" spell.
Please find some way to purify all the cells with the minimum number of spells cast. Print -1 if there is no such way.
Input
The first line will contain a single integer n (1 β€ n β€ 100). Then, n lines follows, each contains n characters. The j-th character in the i-th row represents the cell located at row i and column j. It will be the character 'E' if it is a particularly more evil cell, and '.' otherwise.
Output
If there exists no way to purify all the cells, output -1. Otherwise, if your solution casts x "Purification" spells (where x is the minimum possible number of spells), output x lines. Each line should consist of two integers denoting the row and column numbers of the cell on which you should cast the "Purification" spell.
Examples
Input
3
.E.
E.E
.E.
Output
1 1
2 2
3 3
Input
3
EEE
E..
E.E
Output
-1
Input
5
EE.EE
E.EE.
E...E
.EE.E
EE.EE
Output
3 3
1 3
2 2
4 4
5 3
Note
The first example is illustrated as follows. Purple tiles are evil tiles that have not yet been purified. Red tile is the tile on which "Purification" is cast. Yellow tiles are the tiles being purified as a result of the current "Purification" spell. Green tiles are tiles that have been purified previously.
<image>
In the second example, it is impossible to purify the cell located at row 1 and column 1.
For the third example:
<image> | instruction | 0 | 51,646 | 2 | 103,292 |
Tags: constructive algorithms, greedy
Correct Solution:
```
n=int(input())
arr=[]
flag=True
for _ in range(n):
s=input()
if s=='E'*n:
flag=False
arr.append(s)
if flag:
for i in range(n):
for j in range(n):
if arr[i][j]=='.':
print(i+1,j+1)
break
else:
sf=True
for i in range(n):
temp=''
for j in range(n):
temp+=arr[j][i]
if temp=='E'*n:
sf=False
break
if sf==False:
print('-1')
else:
for i in range(n):
for j in range(n):
if arr[j][i]=='.':
print(j+1,i+1)
break
``` | output | 1 | 51,646 | 2 | 103,293 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are an adventurer currently journeying inside an evil temple. After defeating a couple of weak zombies, you arrived at a square room consisting of tiles forming an n Γ n grid. The rows are numbered 1 through n from top to bottom, and the columns are numbered 1 through n from left to right. At the far side of the room lies a door locked with evil magical forces. The following inscriptions are written on the door:
The cleaning of all evil will awaken the door!
Being a very senior adventurer, you immediately realize what this means. You notice that every single cell in the grid are initially evil. You should purify all of these cells.
The only method of tile purification known to you is by casting the "Purification" spell. You cast this spell on a single tile β then, all cells that are located in the same row and all cells that are located in the same column as the selected tile become purified (including the selected tile)! It is allowed to purify a cell more than once.
You would like to purify all n Γ n cells while minimizing the number of times you cast the "Purification" spell. This sounds very easy, but you just noticed that some tiles are particularly more evil than the other tiles. You cannot cast the "Purification" spell on those particularly more evil tiles, not even after they have been purified. They can still be purified if a cell sharing the same row or the same column gets selected by the "Purification" spell.
Please find some way to purify all the cells with the minimum number of spells cast. Print -1 if there is no such way.
Input
The first line will contain a single integer n (1 β€ n β€ 100). Then, n lines follows, each contains n characters. The j-th character in the i-th row represents the cell located at row i and column j. It will be the character 'E' if it is a particularly more evil cell, and '.' otherwise.
Output
If there exists no way to purify all the cells, output -1. Otherwise, if your solution casts x "Purification" spells (where x is the minimum possible number of spells), output x lines. Each line should consist of two integers denoting the row and column numbers of the cell on which you should cast the "Purification" spell.
Examples
Input
3
.E.
E.E
.E.
Output
1 1
2 2
3 3
Input
3
EEE
E..
E.E
Output
-1
Input
5
EE.EE
E.EE.
E...E
.EE.E
EE.EE
Output
3 3
1 3
2 2
4 4
5 3
Note
The first example is illustrated as follows. Purple tiles are evil tiles that have not yet been purified. Red tile is the tile on which "Purification" is cast. Yellow tiles are the tiles being purified as a result of the current "Purification" spell. Green tiles are tiles that have been purified previously.
<image>
In the second example, it is impossible to purify the cell located at row 1 and column 1.
For the third example:
<image>
Submitted Solution:
```
from collections import *
def get_str_col(arr, i):
return ''.join([row[i] for row in arr])
def check():
r, c = 0, 0
for i in range(n):
if tile[i].count('E') == n:
r = 1
break
for i in range(n):
if get_str_col(tile, i).count('E') == n:
c = 1
break
if r == c == 1:
exit(print(-1))
return r, c
n = int(input())
tile, extra, ans, row, col = [input() for i in range(n)], 0, [], defaultdict(int,
{i: n for i in range(n)}), defaultdict(int,
{
i: n
for
i
in
range(
n)})
r, c = check()
if r == c == 0 or r == 1:
for i in range(n):
for j in range(n):
if tile[i][j] == '.':
if col[j]:
extra += 1
ans.append([i + 1, j + 1])
col[j] = 0
else:
for i in range(n):
for j in range(n):
if tile[i][j] == '.':
if row[i]:
extra += 1
ans.append([i + 1, j + 1])
row[i] = 0
for i in range(n):
print(*ans[i])
``` | instruction | 0 | 51,647 | 2 | 103,294 |
Yes | output | 1 | 51,647 | 2 | 103,295 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are an adventurer currently journeying inside an evil temple. After defeating a couple of weak zombies, you arrived at a square room consisting of tiles forming an n Γ n grid. The rows are numbered 1 through n from top to bottom, and the columns are numbered 1 through n from left to right. At the far side of the room lies a door locked with evil magical forces. The following inscriptions are written on the door:
The cleaning of all evil will awaken the door!
Being a very senior adventurer, you immediately realize what this means. You notice that every single cell in the grid are initially evil. You should purify all of these cells.
The only method of tile purification known to you is by casting the "Purification" spell. You cast this spell on a single tile β then, all cells that are located in the same row and all cells that are located in the same column as the selected tile become purified (including the selected tile)! It is allowed to purify a cell more than once.
You would like to purify all n Γ n cells while minimizing the number of times you cast the "Purification" spell. This sounds very easy, but you just noticed that some tiles are particularly more evil than the other tiles. You cannot cast the "Purification" spell on those particularly more evil tiles, not even after they have been purified. They can still be purified if a cell sharing the same row or the same column gets selected by the "Purification" spell.
Please find some way to purify all the cells with the minimum number of spells cast. Print -1 if there is no such way.
Input
The first line will contain a single integer n (1 β€ n β€ 100). Then, n lines follows, each contains n characters. The j-th character in the i-th row represents the cell located at row i and column j. It will be the character 'E' if it is a particularly more evil cell, and '.' otherwise.
Output
If there exists no way to purify all the cells, output -1. Otherwise, if your solution casts x "Purification" spells (where x is the minimum possible number of spells), output x lines. Each line should consist of two integers denoting the row and column numbers of the cell on which you should cast the "Purification" spell.
Examples
Input
3
.E.
E.E
.E.
Output
1 1
2 2
3 3
Input
3
EEE
E..
E.E
Output
-1
Input
5
EE.EE
E.EE.
E...E
.EE.E
EE.EE
Output
3 3
1 3
2 2
4 4
5 3
Note
The first example is illustrated as follows. Purple tiles are evil tiles that have not yet been purified. Red tile is the tile on which "Purification" is cast. Yellow tiles are the tiles being purified as a result of the current "Purification" spell. Green tiles are tiles that have been purified previously.
<image>
In the second example, it is impossible to purify the cell located at row 1 and column 1.
For the third example:
<image>
Submitted Solution:
```
n = int(input())
maze = [input().strip() for _ in range(n)]
def go(x):
global maze
maze = list(zip(*maze))
check = True
for i in range(n):
if '.' not in maze[i]:
check = False
if check:
for i in range(n):
for j in range(n):
if maze[i][j] == '.':
print(i + 1, j + 1) if x else print(j + 1, i + 1)
break
return check
if not go(0) and not go(1):
print(-1)
``` | instruction | 0 | 51,648 | 2 | 103,296 |
Yes | output | 1 | 51,648 | 2 | 103,297 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.