output_description stringlengths 15 956 | submission_id stringlengths 10 10 | status stringclasses 3 values | problem_id stringlengths 6 6 | input_description stringlengths 9 2.55k | attempt stringlengths 1 13.7k | problem_description stringlengths 7 5.24k | samples stringlengths 2 2.72k |
|---|---|---|---|---|---|---|---|
Print the maximum number of divisors that can be chosen to satisfy the
condition.
* * * | s608175784 | Wrong Answer | p02900 | Input is given from Standard Input in the following format:
A B | ##D - Disjoint Set of Common Divisors
A, B = map(int, input().split())
from fractions import gcd
vPrime = gcd(A, B)
box = []
for i in range(1, vPrime + 1, 2):
if vPrime % (i) == 0:
box.append(i)
check = []
for x in box:
for y in box:
if x < y: # or (x != y and x % y == 0):
break
elif x > y:
if x % y == 0:
break
else: # x == y
check.append(x)
print(len(check))
| Statement
Given are positive integers A and B.
Let us choose some number of positive common divisors of A and B.
Here, any two of the chosen divisors must be coprime.
At most, how many divisors can we choose?
Definition of common divisor
An integer d is said to be a common divisor of integers x and y when d divides
both x and y.
Definition of being coprime
Integers x and y are said to be coprime when x and y have no positive common
divisors other than 1.
Definition of dividing
An integer x is said to divide another integer y when there exists an integer
\alpha such that y = \alpha x. | [{"input": "12 18", "output": "3\n \n\n12 and 18 have the following positive common divisors: 1, 2, 3, and 6.\n\n1 and 2 are coprime, 2 and 3 are coprime, and 3 and 1 are coprime, so we can\nchoose 1, 2, and 3, which achieve the maximum result.\n\n* * *"}, {"input": "420 660", "output": "4\n \n\n* * *"}, {"input": "1 2019", "output": "1\n \n\n1 and 2019 have no positive common divisors other than 1."}] |
Print the maximum number of divisors that can be chosen to satisfy the
condition.
* * * | s887564510 | Wrong Answer | p02900 | Input is given from Standard Input in the following format:
A B | a, b = map(int, input().split())
c_li = []
for i in range(1, max(a, b)):
if a % i == 0 and b % i == 0:
c_li.append(i)
for i in range(1, len(c_li)):
for j in range(2, c_li[i]):
if c_li[i] % j == 0:
c_li[i] = 0
break
cnt = 0
for i in range(len(c_li)):
if c_li[i] != 0:
cnt += 1
print(cnt)
| Statement
Given are positive integers A and B.
Let us choose some number of positive common divisors of A and B.
Here, any two of the chosen divisors must be coprime.
At most, how many divisors can we choose?
Definition of common divisor
An integer d is said to be a common divisor of integers x and y when d divides
both x and y.
Definition of being coprime
Integers x and y are said to be coprime when x and y have no positive common
divisors other than 1.
Definition of dividing
An integer x is said to divide another integer y when there exists an integer
\alpha such that y = \alpha x. | [{"input": "12 18", "output": "3\n \n\n12 and 18 have the following positive common divisors: 1, 2, 3, and 6.\n\n1 and 2 are coprime, 2 and 3 are coprime, and 3 and 1 are coprime, so we can\nchoose 1, 2, and 3, which achieve the maximum result.\n\n* * *"}, {"input": "420 660", "output": "4\n \n\n* * *"}, {"input": "1 2019", "output": "1\n \n\n1 and 2019 have no positive common divisors other than 1."}] |
Print the maximum number of divisors that can be chosen to satisfy the
condition.
* * * | s740641762 | Wrong Answer | p02900 | Input is given from Standard Input in the following format:
A B | A, B = map(int, input().split())
n = 1
m = min([A, B])
ls = [1]
t = 2
while n < m // 2:
tf = True
for i in ls[1:]:
if t % i == 0:
tf = False
# n *= 2
break
if tf:
if A % t == 0 and B % t == 0:
ls.append(t)
n *= t
t += ls[max([0, len(ls) - 2])] - 1
t += 1
print(len(ls))
| Statement
Given are positive integers A and B.
Let us choose some number of positive common divisors of A and B.
Here, any two of the chosen divisors must be coprime.
At most, how many divisors can we choose?
Definition of common divisor
An integer d is said to be a common divisor of integers x and y when d divides
both x and y.
Definition of being coprime
Integers x and y are said to be coprime when x and y have no positive common
divisors other than 1.
Definition of dividing
An integer x is said to divide another integer y when there exists an integer
\alpha such that y = \alpha x. | [{"input": "12 18", "output": "3\n \n\n12 and 18 have the following positive common divisors: 1, 2, 3, and 6.\n\n1 and 2 are coprime, 2 and 3 are coprime, and 3 and 1 are coprime, so we can\nchoose 1, 2, and 3, which achieve the maximum result.\n\n* * *"}, {"input": "420 660", "output": "4\n \n\n* * *"}, {"input": "1 2019", "output": "1\n \n\n1 and 2019 have no positive common divisors other than 1."}] |
Print the maximum number of divisors that can be chosen to satisfy the
condition.
* * * | s343225424 | Accepted | p02900 | Input is given from Standard Input in the following format:
A B | A, B = map(int, input().split())
prime_A = set()
prime_B = set()
curr = 2
while A > 1:
if A % curr == 0:
prime_A.add(curr)
A = A // curr
elif curr * curr >= A:
prime_A.add(A)
A = 1
else:
curr += 1
curr = 2
while B > 1:
if B % curr == 0:
prime_B.add(curr)
B = B // curr
elif curr * curr >= B:
prime_B.add(B)
B /= B
else:
curr += 1
print(len(prime_A & prime_B) + 1)
| Statement
Given are positive integers A and B.
Let us choose some number of positive common divisors of A and B.
Here, any two of the chosen divisors must be coprime.
At most, how many divisors can we choose?
Definition of common divisor
An integer d is said to be a common divisor of integers x and y when d divides
both x and y.
Definition of being coprime
Integers x and y are said to be coprime when x and y have no positive common
divisors other than 1.
Definition of dividing
An integer x is said to divide another integer y when there exists an integer
\alpha such that y = \alpha x. | [{"input": "12 18", "output": "3\n \n\n12 and 18 have the following positive common divisors: 1, 2, 3, and 6.\n\n1 and 2 are coprime, 2 and 3 are coprime, and 3 and 1 are coprime, so we can\nchoose 1, 2, and 3, which achieve the maximum result.\n\n* * *"}, {"input": "420 660", "output": "4\n \n\n* * *"}, {"input": "1 2019", "output": "1\n \n\n1 and 2019 have no positive common divisors other than 1."}] |
Print the maximum number of divisors that can be chosen to satisfy the
condition.
* * * | s177458071 | Runtime Error | p02900 | Input is given from Standard Input in the following format:
A B | n = int(input())
a = list(map(int, input().split()))
b = list()
for i in range(n + 1):
if i == 0:
continue
else:
c = a.index(i)
c = c + 1
b.append(c)
for j in b:
print(j, end=" ")
| Statement
Given are positive integers A and B.
Let us choose some number of positive common divisors of A and B.
Here, any two of the chosen divisors must be coprime.
At most, how many divisors can we choose?
Definition of common divisor
An integer d is said to be a common divisor of integers x and y when d divides
both x and y.
Definition of being coprime
Integers x and y are said to be coprime when x and y have no positive common
divisors other than 1.
Definition of dividing
An integer x is said to divide another integer y when there exists an integer
\alpha such that y = \alpha x. | [{"input": "12 18", "output": "3\n \n\n12 and 18 have the following positive common divisors: 1, 2, 3, and 6.\n\n1 and 2 are coprime, 2 and 3 are coprime, and 3 and 1 are coprime, so we can\nchoose 1, 2, and 3, which achieve the maximum result.\n\n* * *"}, {"input": "420 660", "output": "4\n \n\n* * *"}, {"input": "1 2019", "output": "1\n \n\n1 and 2019 have no positive common divisors other than 1."}] |
Print the maximum number of divisors that can be chosen to satisfy the
condition.
* * * | s340797539 | Accepted | p02900 | Input is given from Standard Input in the following format:
A B | from collections import defaultdict as dd
A, B = map(int, input().split())
def get_p(n):
th = round(n**0.5)
ans = (n, 1)
for i in range(2, th + 1):
if n % i == 0:
ans = (i, n // i)
break
return ans
def get_yakusu(n):
flag = 1
pn_dic = dd(lambda: 0)
while flag:
yaku, red = get_p(n)
if yaku == n:
pn_dic[str(yaku)] += 1
flag = 0
else:
pn_dic[str(yaku)] += 1
n = red
return pn_dic
apn_dic = get_yakusu(A)
apn_dic["1"] += 1
bpn_dic = get_yakusu(B)
bpn_dic["1"] += 1
# print("Adic:",apn_dic)
# print("Bdic:",bpn_dic)
kouyaku_dic = dd(lambda: 0)
wa_key = list(set(apn_dic.keys()) & set(bpn_dic.keys()))
for key in wa_key:
kouyaku_dic[key] = min(apn_dic[key], bpn_dic[key])
# print("kouyaku:",kouyaku_dic)
m = len(wa_key)
print(m)
| Statement
Given are positive integers A and B.
Let us choose some number of positive common divisors of A and B.
Here, any two of the chosen divisors must be coprime.
At most, how many divisors can we choose?
Definition of common divisor
An integer d is said to be a common divisor of integers x and y when d divides
both x and y.
Definition of being coprime
Integers x and y are said to be coprime when x and y have no positive common
divisors other than 1.
Definition of dividing
An integer x is said to divide another integer y when there exists an integer
\alpha such that y = \alpha x. | [{"input": "12 18", "output": "3\n \n\n12 and 18 have the following positive common divisors: 1, 2, 3, and 6.\n\n1 and 2 are coprime, 2 and 3 are coprime, and 3 and 1 are coprime, so we can\nchoose 1, 2, and 3, which achieve the maximum result.\n\n* * *"}, {"input": "420 660", "output": "4\n \n\n* * *"}, {"input": "1 2019", "output": "1\n \n\n1 and 2019 have no positive common divisors other than 1."}] |
Print the maximum number of divisors that can be chosen to satisfy the
condition.
* * * | s236172111 | Runtime Error | p02900 | Input is given from Standard Input in the following format:
A B | if __name__ == "__main__":
x1, x2 = map(int, input().split())
if x1 >= x2 > 1:
x1 = x1 - x2
elif x1 > 1:
x2 = x2 - x1
cf = []
# print("{}, {}".format(x1, x2))
divisors1 = []
for i in range(1, int(x1**0.5) + 1):
if x1 % i == 0:
divisors1.append(i)
if i != x1 // i:
divisors1.append(x1 // i)
divisors2 = []
for i in range(1, int(x2**0.5) + 1):
if x2 % i == 0:
divisors2.append(i)
if i != x2 // i:
divisors2.append(x2 // i)
koyakusu = set(divisors1) & set(divisors2)
koyakusu.remove(1)
# print(list(koyakusu))
for i in list(koyakusu):
appendable = True
for j in cf:
if i % j == 0:
appendable = False
break
if appendable:
cf.append(i)
# cfは公約数のリスト
# このリストの中で互いに素のものだけを残す
# for i in range(len(cf)):
# fractions.gcd()
# print(cf)
print(len(cf) + 1)
| Statement
Given are positive integers A and B.
Let us choose some number of positive common divisors of A and B.
Here, any two of the chosen divisors must be coprime.
At most, how many divisors can we choose?
Definition of common divisor
An integer d is said to be a common divisor of integers x and y when d divides
both x and y.
Definition of being coprime
Integers x and y are said to be coprime when x and y have no positive common
divisors other than 1.
Definition of dividing
An integer x is said to divide another integer y when there exists an integer
\alpha such that y = \alpha x. | [{"input": "12 18", "output": "3\n \n\n12 and 18 have the following positive common divisors: 1, 2, 3, and 6.\n\n1 and 2 are coprime, 2 and 3 are coprime, and 3 and 1 are coprime, so we can\nchoose 1, 2, and 3, which achieve the maximum result.\n\n* * *"}, {"input": "420 660", "output": "4\n \n\n* * *"}, {"input": "1 2019", "output": "1\n \n\n1 and 2019 have no positive common divisors other than 1."}] |
Print the maximum number of divisors that can be chosen to satisfy the
condition.
* * * | s166517000 | Wrong Answer | p02900 | Input is given from Standard Input in the following format:
A B | def mkou(A, B):
x = A % B
if x == 0:
return B
else:
return mkou(B, x)
def prime_F(k):
a = [
1,
]
end = int(pow(k, 0.5))
if k % 2 == 0:
k /= 2
a.append(2)
k = int(k)
for x in range(3, end, 1):
if k % x == 0:
while k % x == 0:
k /= x
a.append(x)
if k == 1:
break
if k != 1:
a.append(k)
return a
A, B = map(int, input().split())
divA_array = []
divB_array = []
if A < B:
A, B = B, A
kouyaku = mkou(A, B)
soinsu = prime_F(kouyaku)
print(len(soinsu))
| Statement
Given are positive integers A and B.
Let us choose some number of positive common divisors of A and B.
Here, any two of the chosen divisors must be coprime.
At most, how many divisors can we choose?
Definition of common divisor
An integer d is said to be a common divisor of integers x and y when d divides
both x and y.
Definition of being coprime
Integers x and y are said to be coprime when x and y have no positive common
divisors other than 1.
Definition of dividing
An integer x is said to divide another integer y when there exists an integer
\alpha such that y = \alpha x. | [{"input": "12 18", "output": "3\n \n\n12 and 18 have the following positive common divisors: 1, 2, 3, and 6.\n\n1 and 2 are coprime, 2 and 3 are coprime, and 3 and 1 are coprime, so we can\nchoose 1, 2, and 3, which achieve the maximum result.\n\n* * *"}, {"input": "420 660", "output": "4\n \n\n* * *"}, {"input": "1 2019", "output": "1\n \n\n1 and 2019 have no positive common divisors other than 1."}] |
For each data set in the input, your program should write the number of the
top card after the shuffle. Assume that at the beginning the cards are
numbered from 1 to _n_ , from the bottom to the top. Each number should be
written in a separate line without any superfluous characters such as leading
or following spaces. | s539260602 | Wrong Answer | p00710 | The input consists of multiple data sets. Each data set starts with a line
containing two positive integers _n_ (1 <= _n_ <= 50) and _r_ (1 <= _r_ <=
50); _n_ and _r_ are the number of cards in the deck and the number of cutting
operations, respectively.
There are _r_ more lines in the data set, each of which represents a cutting
operation. These cutting operations are performed in the listed order. Each
line contains two positive integers _p_ and _c_ (_p_ \+ _c_ <= _n_ \+ 1).
Starting from the _p_ -th card from the top of the deck, _c_ cards should be
pulled out and put on the top.
The end of the input is indicated by a line which contains two zeros.
Each input line contains exactly two integers separated by a space character.
There are no other characters in the line. | # hanafuda
N, r = (int(i) for i in input().split())
H = [int(i) for i in range(N)]
for i in range(N):
p, c = (int(i) for i in input().split())
T = []
for j in range(p, p + c - 1):
T.append(H[p])
H.pop(p)
H = T + H
print(H[0])
| Problem A: Hanafuda Shuffle
There are a number of ways to shuffle a deck of cards. Hanafuda shuffling for
Japanese card game 'Hanafuda' is one such example. The following is how to
perform Hanafuda shuffling.
There is a deck of _n_ cards. Starting from the _p_ -th card from the top of
the deck, _c_ cards are pulled out and put on the top of the deck, as shown in
Figure 1. This operation, called a cutting operation, is repeated.
Write a program that simulates Hanafuda shuffling and answers which card will
be finally placed on the top of the deck.

---
Figure 1: Cutting operation | [{"input": "2\n 3 1\n 3 1\n 10 3\n 1 10\n 10 1\n 8 3\n 0 0", "output": "4"}] |
For each data set in the input, your program should write the number of the
top card after the shuffle. Assume that at the beginning the cards are
numbered from 1 to _n_ , from the bottom to the top. Each number should be
written in a separate line without any superfluous characters such as leading
or following spaces. | s521395404 | Wrong Answer | p00710 | The input consists of multiple data sets. Each data set starts with a line
containing two positive integers _n_ (1 <= _n_ <= 50) and _r_ (1 <= _r_ <=
50); _n_ and _r_ are the number of cards in the deck and the number of cutting
operations, respectively.
There are _r_ more lines in the data set, each of which represents a cutting
operation. These cutting operations are performed in the listed order. Each
line contains two positive integers _p_ and _c_ (_p_ \+ _c_ <= _n_ \+ 1).
Starting from the _p_ -th card from the top of the deck, _c_ cards should be
pulled out and put on the top.
The end of the input is indicated by a line which contains two zeros.
Each input line contains exactly two integers separated by a space character.
There are no other characters in the line. | first = input().split()
n = int(first[0])
r = int(first[1])
while n != 0 or r != 0:
i = 0
card = list(range(1, n + 1))[::-1]
while i < r:
sh = input().split()
p, c = list(map(int, sh))
card = card[p - 1 : p + c - 1] + card[: p - 1] + card[p + c - 1 :]
i = i + 1
print(card)
next = input().split()
n, r = list(map(int, next))
| Problem A: Hanafuda Shuffle
There are a number of ways to shuffle a deck of cards. Hanafuda shuffling for
Japanese card game 'Hanafuda' is one such example. The following is how to
perform Hanafuda shuffling.
There is a deck of _n_ cards. Starting from the _p_ -th card from the top of
the deck, _c_ cards are pulled out and put on the top of the deck, as shown in
Figure 1. This operation, called a cutting operation, is repeated.
Write a program that simulates Hanafuda shuffling and answers which card will
be finally placed on the top of the deck.

---
Figure 1: Cutting operation | [{"input": "2\n 3 1\n 3 1\n 10 3\n 1 10\n 10 1\n 8 3\n 0 0", "output": "4"}] |
For each data set in the input, your program should write the number of the
top card after the shuffle. Assume that at the beginning the cards are
numbered from 1 to _n_ , from the bottom to the top. Each number should be
written in a separate line without any superfluous characters such as leading
or following spaces. | s576542628 | Accepted | p00710 | The input consists of multiple data sets. Each data set starts with a line
containing two positive integers _n_ (1 <= _n_ <= 50) and _r_ (1 <= _r_ <=
50); _n_ and _r_ are the number of cards in the deck and the number of cutting
operations, respectively.
There are _r_ more lines in the data set, each of which represents a cutting
operation. These cutting operations are performed in the listed order. Each
line contains two positive integers _p_ and _c_ (_p_ \+ _c_ <= _n_ \+ 1).
Starting from the _p_ -th card from the top of the deck, _c_ cards should be
pulled out and put on the top.
The end of the input is indicated by a line which contains two zeros.
Each input line contains exactly two integers separated by a space character.
There are no other characters in the line. | # encoding: utf-8
def create_deck(deck_size):
deck = []
for i in range(0, deck_size):
deck.append(i + 1)
return deck
def shuffle_deck(deck, start, cut_size):
after = []
cut_cards = []
b = len(deck) - cut_size - start
for i in range(0, len(deck)):
if b >= i:
after.append(deck[i])
continue
if (b + cut_size) >= i:
cut_cards.append(deck[i])
continue
after.append(deck[i])
after.extend(cut_cards)
return after
while True:
data = input().split()
deck_size, shuffle_count = int(data[0]), int(data[1])
if deck_size == shuffle_count == 0:
break
deck = create_deck(deck_size)
for i in range(0, shuffle_count):
cut_info = data = input().split()
start, cut_size = int(cut_info[0]), int(cut_info[1])
deck = shuffle_deck(deck, start, cut_size)
print(deck[len(deck) - 1])
| Problem A: Hanafuda Shuffle
There are a number of ways to shuffle a deck of cards. Hanafuda shuffling for
Japanese card game 'Hanafuda' is one such example. The following is how to
perform Hanafuda shuffling.
There is a deck of _n_ cards. Starting from the _p_ -th card from the top of
the deck, _c_ cards are pulled out and put on the top of the deck, as shown in
Figure 1. This operation, called a cutting operation, is repeated.
Write a program that simulates Hanafuda shuffling and answers which card will
be finally placed on the top of the deck.

---
Figure 1: Cutting operation | [{"input": "2\n 3 1\n 3 1\n 10 3\n 1 10\n 10 1\n 8 3\n 0 0", "output": "4"}] |
For each data set in the input, your program should write the number of the
top card after the shuffle. Assume that at the beginning the cards are
numbered from 1 to _n_ , from the bottom to the top. Each number should be
written in a separate line without any superfluous characters such as leading
or following spaces. | s392634933 | Accepted | p00710 | The input consists of multiple data sets. Each data set starts with a line
containing two positive integers _n_ (1 <= _n_ <= 50) and _r_ (1 <= _r_ <=
50); _n_ and _r_ are the number of cards in the deck and the number of cutting
operations, respectively.
There are _r_ more lines in the data set, each of which represents a cutting
operation. These cutting operations are performed in the listed order. Each
line contains two positive integers _p_ and _c_ (_p_ \+ _c_ <= _n_ \+ 1).
Starting from the _p_ -th card from the top of the deck, _c_ cards should be
pulled out and put on the top.
The end of the input is indicated by a line which contains two zeros.
Each input line contains exactly two integers separated by a space character.
There are no other characters in the line. | while 1:
count, times = [int(a) for a in input().split()]
hanahuda = [i + 1 for i in range(count)]
if count == times == 0:
break
for i in [0] * times:
p, c = [int(i) for i in input().split()]
for i in [0] * c:
hanahuda.append(hanahuda.pop(count - (p + c) + 1))
print(hanahuda.pop())
| Problem A: Hanafuda Shuffle
There are a number of ways to shuffle a deck of cards. Hanafuda shuffling for
Japanese card game 'Hanafuda' is one such example. The following is how to
perform Hanafuda shuffling.
There is a deck of _n_ cards. Starting from the _p_ -th card from the top of
the deck, _c_ cards are pulled out and put on the top of the deck, as shown in
Figure 1. This operation, called a cutting operation, is repeated.
Write a program that simulates Hanafuda shuffling and answers which card will
be finally placed on the top of the deck.

---
Figure 1: Cutting operation | [{"input": "2\n 3 1\n 3 1\n 10 3\n 1 10\n 10 1\n 8 3\n 0 0", "output": "4"}] |
Print `Yes` if it is possible to meet the conditions by properly writing
integers into all remaining cells. Otherwise, print `No`.
* * * | s065960158 | Runtime Error | p03995 | The input is given from Standard Input in the following format:
R C
N
r_1 c_1 a_1
r_2 c_2 a_2
:
r_N c_N a_N | from collections import defaultdict
import copy
def readInput():
return [int(i) for i in input().split(" ")]
(R, C) = readInput()
N = int(input())
rowIdx = set()
cover = set()
grid = defaultdict(lambda:None)
rowGrid = defaultdict(set)
for i in range(N):
(r, c, a) = readInput()
r -= 1
c -= 1
rowGrid[r].add(c)
grid[(r, c)] = a
rowIdx.add(r)
pairIdx = copy.copy(rowIdx)
for i in rowIdx:
tempRow = rowGrid[i]
tempRow.difference_update(cover)
if (len(tempRow) is 0):
continue
pairIdx.remove(i)
for j in pairIdx:
tempPair = rowGrid[j]
mark = 1
for k in tempRow:
if (grid[(j, k)] is now None):
diff = grid[(i, k)] - grid[(j, k)]
mark = 0
break
if (mark is 1):
continue
for m in tempRow:
anchor = grid[(i, m)]
anchorP = grid[(j, m)]
if (anchorP is None and anchor < diff):
print('No')
exit()
elif (anchorP is not None and anchor - anchorP != diff):
print('No')
exit()
for n in tempPair:
anchor = grid[(j, n)]
anchorP = grid[(i, n)]
if (anchorP is None and anchor < -diff):
print('No')
exit()
cover &= tempRow
if (len(cover) is C):
break
print('Yes') | Statement
There is a grid with R rows and C columns. We call the cell in the r-th row
and c-th column (r,c).
Mr. Takahashi wrote non-negative integers into N of the cells, that is, he
wrote a non-negative integer a_i into (r_i,c_i) for each i (1≤i≤N). After that
he fell asleep.
Mr. Aoki found the grid and tries to surprise Mr. Takahashi by writing
integers into all remaining cells. The grid must meet the following conditions
to really surprise Mr. Takahashi.
* Condition 1: Each cell contains a non-negative integer.
* Condition 2: For any 2×2 square formed by cells on the grid, the sum of the top left and bottom right integers must always equal to the sum of the top right and bottom left integers.
Determine whether it is possible to meet those conditions by properly writing
integers into all remaining cells. | [{"input": "2 2\n 3\n 1 1 0\n 1 2 10\n 2 1 20", "output": "Yes\n \n\nYou can write integers as follows.\n\n\n\n* * *"}, {"input": "2 3\n 5\n 1 1 0\n 1 2 10\n 1 3 20\n 2 1 30\n 2 3 40", "output": "No\n \n\nThere are two 2\u00d72 squares on the grid, formed by the following cells:\n\n * Cells (1\uff0c1), (1\uff0c2), (2\uff0c1) and (2\uff0c2)\n * Cells (1\uff0c2), (1\uff0c3), (2\uff0c2) and (2\uff0c3)\n\nYou have to write 40 into the empty cell to meet the condition on the left\nsquare, but then it does not satisfy the condition on the right square.\n\n\n\n* * *"}, {"input": "2 2\n 3\n 1 1 20\n 1 2 10\n 2 1 0", "output": "No\n \n\nYou have to write -10 into the empty cell to meet condition 2, but then it\ndoes not satisfy condition 1.\n\n\n\n* * *"}, {"input": "3 3\n 4\n 1 1 0\n 1 3 10\n 3 1 10\n 3 3 20", "output": "Yes\n \n\nYou can write integers as follows.\n\n\n\n* * *"}, {"input": "2 2\n 4\n 1 1 0\n 1 2 10\n 2 1 30\n 2 2 20", "output": "No\n \n\nAll cells already contain a integer and condition 2 is not satisfied.\n\n"}] |
Print `Yes` if it is possible to meet the conditions by properly writing
integers into all remaining cells. Otherwise, print `No`.
* * * | s388293619 | Wrong Answer | p03995 | The input is given from Standard Input in the following format:
R C
N
r_1 c_1 a_1
r_2 c_2 a_2
:
r_N c_N a_N | print("Yes")
| Statement
There is a grid with R rows and C columns. We call the cell in the r-th row
and c-th column (r,c).
Mr. Takahashi wrote non-negative integers into N of the cells, that is, he
wrote a non-negative integer a_i into (r_i,c_i) for each i (1≤i≤N). After that
he fell asleep.
Mr. Aoki found the grid and tries to surprise Mr. Takahashi by writing
integers into all remaining cells. The grid must meet the following conditions
to really surprise Mr. Takahashi.
* Condition 1: Each cell contains a non-negative integer.
* Condition 2: For any 2×2 square formed by cells on the grid, the sum of the top left and bottom right integers must always equal to the sum of the top right and bottom left integers.
Determine whether it is possible to meet those conditions by properly writing
integers into all remaining cells. | [{"input": "2 2\n 3\n 1 1 0\n 1 2 10\n 2 1 20", "output": "Yes\n \n\nYou can write integers as follows.\n\n\n\n* * *"}, {"input": "2 3\n 5\n 1 1 0\n 1 2 10\n 1 3 20\n 2 1 30\n 2 3 40", "output": "No\n \n\nThere are two 2\u00d72 squares on the grid, formed by the following cells:\n\n * Cells (1\uff0c1), (1\uff0c2), (2\uff0c1) and (2\uff0c2)\n * Cells (1\uff0c2), (1\uff0c3), (2\uff0c2) and (2\uff0c3)\n\nYou have to write 40 into the empty cell to meet the condition on the left\nsquare, but then it does not satisfy the condition on the right square.\n\n\n\n* * *"}, {"input": "2 2\n 3\n 1 1 20\n 1 2 10\n 2 1 0", "output": "No\n \n\nYou have to write -10 into the empty cell to meet condition 2, but then it\ndoes not satisfy condition 1.\n\n\n\n* * *"}, {"input": "3 3\n 4\n 1 1 0\n 1 3 10\n 3 1 10\n 3 3 20", "output": "Yes\n \n\nYou can write integers as follows.\n\n\n\n* * *"}, {"input": "2 2\n 4\n 1 1 0\n 1 2 10\n 2 1 30\n 2 2 20", "output": "No\n \n\nAll cells already contain a integer and condition 2 is not satisfied.\n\n"}] |
Print `Yes` if it is possible to meet the conditions by properly writing
integers into all remaining cells. Otherwise, print `No`.
* * * | s671116043 | Wrong Answer | p03995 | The input is given from Standard Input in the following format:
R C
N
r_1 c_1 a_1
r_2 c_2 a_2
:
r_N c_N a_N | R, C = map(int, input().split())
N = int(input())
n = 0
Is = []
while n < N:
Is.append(list(map(int, input().split())))
n += 1
# matrix = [None] * (R * C)
# for i in Is:
# r, c, a = i
# serial = (r - 1) * C + c
# matrix[serial] = [a]
# for row in range(1, R):
# nums = [i for i in matrix[row * C: (row + 1) * C - 1] if i is not None]
# for compare_row in range(row):
# compare_nums = [i for i in matrix[compare_row * C: (compare_row + 1) * C - 1] if i is not None]
print("Yes")
| Statement
There is a grid with R rows and C columns. We call the cell in the r-th row
and c-th column (r,c).
Mr. Takahashi wrote non-negative integers into N of the cells, that is, he
wrote a non-negative integer a_i into (r_i,c_i) for each i (1≤i≤N). After that
he fell asleep.
Mr. Aoki found the grid and tries to surprise Mr. Takahashi by writing
integers into all remaining cells. The grid must meet the following conditions
to really surprise Mr. Takahashi.
* Condition 1: Each cell contains a non-negative integer.
* Condition 2: For any 2×2 square formed by cells on the grid, the sum of the top left and bottom right integers must always equal to the sum of the top right and bottom left integers.
Determine whether it is possible to meet those conditions by properly writing
integers into all remaining cells. | [{"input": "2 2\n 3\n 1 1 0\n 1 2 10\n 2 1 20", "output": "Yes\n \n\nYou can write integers as follows.\n\n\n\n* * *"}, {"input": "2 3\n 5\n 1 1 0\n 1 2 10\n 1 3 20\n 2 1 30\n 2 3 40", "output": "No\n \n\nThere are two 2\u00d72 squares on the grid, formed by the following cells:\n\n * Cells (1\uff0c1), (1\uff0c2), (2\uff0c1) and (2\uff0c2)\n * Cells (1\uff0c2), (1\uff0c3), (2\uff0c2) and (2\uff0c3)\n\nYou have to write 40 into the empty cell to meet the condition on the left\nsquare, but then it does not satisfy the condition on the right square.\n\n\n\n* * *"}, {"input": "2 2\n 3\n 1 1 20\n 1 2 10\n 2 1 0", "output": "No\n \n\nYou have to write -10 into the empty cell to meet condition 2, but then it\ndoes not satisfy condition 1.\n\n\n\n* * *"}, {"input": "3 3\n 4\n 1 1 0\n 1 3 10\n 3 1 10\n 3 3 20", "output": "Yes\n \n\nYou can write integers as follows.\n\n\n\n* * *"}, {"input": "2 2\n 4\n 1 1 0\n 1 2 10\n 2 1 30\n 2 2 20", "output": "No\n \n\nAll cells already contain a integer and condition 2 is not satisfied.\n\n"}] |
Print `Yes` if it is possible to meet the conditions by properly writing
integers into all remaining cells. Otherwise, print `No`.
* * * | s001853994 | Runtime Error | p03995 | The input is given from Standard Input in the following format:
R C
N
r_1 c_1 a_1
r_2 c_2 a_2
:
r_N c_N a_N | c,r = map(int, input().split())
N=int(input())
list=[[-1] * r for i in range(c)]
for i in range(N):
i1,i1,x=map(int, input().split()))
list[i1][i2]=x
print('Yes') | Statement
There is a grid with R rows and C columns. We call the cell in the r-th row
and c-th column (r,c).
Mr. Takahashi wrote non-negative integers into N of the cells, that is, he
wrote a non-negative integer a_i into (r_i,c_i) for each i (1≤i≤N). After that
he fell asleep.
Mr. Aoki found the grid and tries to surprise Mr. Takahashi by writing
integers into all remaining cells. The grid must meet the following conditions
to really surprise Mr. Takahashi.
* Condition 1: Each cell contains a non-negative integer.
* Condition 2: For any 2×2 square formed by cells on the grid, the sum of the top left and bottom right integers must always equal to the sum of the top right and bottom left integers.
Determine whether it is possible to meet those conditions by properly writing
integers into all remaining cells. | [{"input": "2 2\n 3\n 1 1 0\n 1 2 10\n 2 1 20", "output": "Yes\n \n\nYou can write integers as follows.\n\n\n\n* * *"}, {"input": "2 3\n 5\n 1 1 0\n 1 2 10\n 1 3 20\n 2 1 30\n 2 3 40", "output": "No\n \n\nThere are two 2\u00d72 squares on the grid, formed by the following cells:\n\n * Cells (1\uff0c1), (1\uff0c2), (2\uff0c1) and (2\uff0c2)\n * Cells (1\uff0c2), (1\uff0c3), (2\uff0c2) and (2\uff0c3)\n\nYou have to write 40 into the empty cell to meet the condition on the left\nsquare, but then it does not satisfy the condition on the right square.\n\n\n\n* * *"}, {"input": "2 2\n 3\n 1 1 20\n 1 2 10\n 2 1 0", "output": "No\n \n\nYou have to write -10 into the empty cell to meet condition 2, but then it\ndoes not satisfy condition 1.\n\n\n\n* * *"}, {"input": "3 3\n 4\n 1 1 0\n 1 3 10\n 3 1 10\n 3 3 20", "output": "Yes\n \n\nYou can write integers as follows.\n\n\n\n* * *"}, {"input": "2 2\n 4\n 1 1 0\n 1 2 10\n 2 1 30\n 2 2 20", "output": "No\n \n\nAll cells already contain a integer and condition 2 is not satisfied.\n\n"}] |
Print `Yes` if it is possible to meet the conditions by properly writing
integers into all remaining cells. Otherwise, print `No`.
* * * | s291999751 | Wrong Answer | p03995 | The input is given from Standard Input in the following format:
R C
N
r_1 c_1 a_1
r_2 c_2 a_2
:
r_N c_N a_N | """難しいすぎるよぅ..."""
def solve():
R, C = list(map(int, input().split()))
N = int(input())
row = [[] for _ in range(R)]
field = {}
for _ in range(N):
r, c, a = list(map(int, input().split()))
r, c = r - 1, c - 1
row[r].append((c, a))
field[(r, c)] = a
row = [sorted(r) for r in row]
for rn, r in enumerate(row):
for i, e1 in enumerate(r):
for e2 in r[i + 1 :]:
n = e2[0] - e1[0]
print(r, e1, e2, n)
if n > C:
break
a = field.get((rn + n, e1[0]), None)
b = field.get((rn + n, e2[0]), None)
if a is None and b is None:
continue
if a is None:
if e1[1] + b - e2[1] < 0:
return False
elif b is None:
if e2[1] + a - e1[1] < 0:
return False
else:
if e1[1] + b == e2[1] + a:
return False
return True
print("Yes" if solve() else "No")
| Statement
There is a grid with R rows and C columns. We call the cell in the r-th row
and c-th column (r,c).
Mr. Takahashi wrote non-negative integers into N of the cells, that is, he
wrote a non-negative integer a_i into (r_i,c_i) for each i (1≤i≤N). After that
he fell asleep.
Mr. Aoki found the grid and tries to surprise Mr. Takahashi by writing
integers into all remaining cells. The grid must meet the following conditions
to really surprise Mr. Takahashi.
* Condition 1: Each cell contains a non-negative integer.
* Condition 2: For any 2×2 square formed by cells on the grid, the sum of the top left and bottom right integers must always equal to the sum of the top right and bottom left integers.
Determine whether it is possible to meet those conditions by properly writing
integers into all remaining cells. | [{"input": "2 2\n 3\n 1 1 0\n 1 2 10\n 2 1 20", "output": "Yes\n \n\nYou can write integers as follows.\n\n\n\n* * *"}, {"input": "2 3\n 5\n 1 1 0\n 1 2 10\n 1 3 20\n 2 1 30\n 2 3 40", "output": "No\n \n\nThere are two 2\u00d72 squares on the grid, formed by the following cells:\n\n * Cells (1\uff0c1), (1\uff0c2), (2\uff0c1) and (2\uff0c2)\n * Cells (1\uff0c2), (1\uff0c3), (2\uff0c2) and (2\uff0c3)\n\nYou have to write 40 into the empty cell to meet the condition on the left\nsquare, but then it does not satisfy the condition on the right square.\n\n\n\n* * *"}, {"input": "2 2\n 3\n 1 1 20\n 1 2 10\n 2 1 0", "output": "No\n \n\nYou have to write -10 into the empty cell to meet condition 2, but then it\ndoes not satisfy condition 1.\n\n\n\n* * *"}, {"input": "3 3\n 4\n 1 1 0\n 1 3 10\n 3 1 10\n 3 3 20", "output": "Yes\n \n\nYou can write integers as follows.\n\n\n\n* * *"}, {"input": "2 2\n 4\n 1 1 0\n 1 2 10\n 2 1 30\n 2 2 20", "output": "No\n \n\nAll cells already contain a integer and condition 2 is not satisfied.\n\n"}] |
Print `Yes` if it is possible to meet the conditions by properly writing
integers into all remaining cells. Otherwise, print `No`.
* * * | s262618156 | Wrong Answer | p03995 | The input is given from Standard Input in the following format:
R C
N
r_1 c_1 a_1
r_2 c_2 a_2
:
r_N c_N a_N | # -*- coding: utf-8 -*-
"""
Created on Sat Sep 24 21:51:15 2016
@author: dotha
"""
def clear():
pass
def squarecheck(square):
# 明らかなところがあれば埋める
if None not in square:
return (square[0] + square[2] == square[1] + square[3], square, False)
elif square.count(None) == 1:
if square[0] == None:
square[0] = square[1] + square[3] - square[2]
if square[0] < 0:
return (False, square, False)
elif square[1] == None:
square[1] = square[0] + square[2] - square[3]
if square[1] < 0:
return (False, square, False)
elif square[2] == None:
square[2] = square[1] + square[3] - square[0]
if square[2] < 0:
return (False, square, False)
else:
square[3] = square[0] + square[2] - square[1]
if square[3] < 0:
return (False, square, False)
return (True, square, True)
else:
return (True, square)
def clearcheck(table, R, C):
Done = False
somethinghappened = False
for tate in range(R - 1):
for yoko in range(C - 1):
(ccheck, square, Done) = squarecheck(
[
table[tate][yoko],
table[tate][yoko + 1],
table[tate + 1][yoko + 1],
table[tate + 1][yoko],
]
)
if Done:
somethinghappened == True
if ccheck == False:
return False, table, False
table[tate][yoko] = square[0]
table[tate][yoko + 1] = square[1]
table[tate + 1][yoko + 1] = square[2]
table[tate + 1][yoko] = square[3]
return True, table, somethinghappened
def main():
R, C = tuple(map(int, input().split()))
N = int(input())
if N == R * C:
print("No")
return
else:
table = [[None for i in range(C)] for j in range(R)]
for i in range(N):
r, c, a = tuple(map(int, input().split()))
table[r - 1][c - 1] = a
while True:
success, table, done = clearcheck(table, R, C)
if success == False:
print("No")
return
if done == False:
break
print("Yes")
if __name__ == "__main__":
main()
| Statement
There is a grid with R rows and C columns. We call the cell in the r-th row
and c-th column (r,c).
Mr. Takahashi wrote non-negative integers into N of the cells, that is, he
wrote a non-negative integer a_i into (r_i,c_i) for each i (1≤i≤N). After that
he fell asleep.
Mr. Aoki found the grid and tries to surprise Mr. Takahashi by writing
integers into all remaining cells. The grid must meet the following conditions
to really surprise Mr. Takahashi.
* Condition 1: Each cell contains a non-negative integer.
* Condition 2: For any 2×2 square formed by cells on the grid, the sum of the top left and bottom right integers must always equal to the sum of the top right and bottom left integers.
Determine whether it is possible to meet those conditions by properly writing
integers into all remaining cells. | [{"input": "2 2\n 3\n 1 1 0\n 1 2 10\n 2 1 20", "output": "Yes\n \n\nYou can write integers as follows.\n\n\n\n* * *"}, {"input": "2 3\n 5\n 1 1 0\n 1 2 10\n 1 3 20\n 2 1 30\n 2 3 40", "output": "No\n \n\nThere are two 2\u00d72 squares on the grid, formed by the following cells:\n\n * Cells (1\uff0c1), (1\uff0c2), (2\uff0c1) and (2\uff0c2)\n * Cells (1\uff0c2), (1\uff0c3), (2\uff0c2) and (2\uff0c3)\n\nYou have to write 40 into the empty cell to meet the condition on the left\nsquare, but then it does not satisfy the condition on the right square.\n\n\n\n* * *"}, {"input": "2 2\n 3\n 1 1 20\n 1 2 10\n 2 1 0", "output": "No\n \n\nYou have to write -10 into the empty cell to meet condition 2, but then it\ndoes not satisfy condition 1.\n\n\n\n* * *"}, {"input": "3 3\n 4\n 1 1 0\n 1 3 10\n 3 1 10\n 3 3 20", "output": "Yes\n \n\nYou can write integers as follows.\n\n\n\n* * *"}, {"input": "2 2\n 4\n 1 1 0\n 1 2 10\n 2 1 30\n 2 2 20", "output": "No\n \n\nAll cells already contain a integer and condition 2 is not satisfied.\n\n"}] |
Print `Yes` if it is possible to meet the conditions by properly writing
integers into all remaining cells. Otherwise, print `No`.
* * * | s299362035 | Accepted | p03995 | The input is given from Standard Input in the following format:
R C
N
r_1 c_1 a_1
r_2 c_2 a_2
:
r_N c_N a_N | import sys
readline = sys.stdin.readline
class UFP:
def __init__(self, num):
self.par = [-1] * num
self.dist = [0] * num
def find(self, x):
if self.par[x] < 0:
return x
else:
res = 0
xo = x
while self.par[x] >= 0:
res += self.dist[x]
x = self.par[x]
self.dist[xo] = res
self.par[xo] = x
return x
def union(self, x, y, d):
rx = self.find(x)
ry = self.find(y)
if rx != ry:
if self.par[rx] > self.par[ry]:
rx, ry = ry, rx
x, y = y, x
d = -d
self.par[rx] += self.par[ry]
self.par[ry] = rx
self.dist[ry] = d + self.dist[x] - self.dist[y]
return True
else:
if d + self.dist[x] - self.dist[y]:
return False
return True
INF = 3 * 10**9
def check():
H, W = map(int, readline().split())
N = int(readline())
Hm = [INF] * H
Wm = [INF] * W
HP = [[] for _ in range(H)]
WP = [[] for _ in range(W)]
for _ in range(N):
h, w, a = map(int, readline().split())
h -= 1
w -= 1
Hm[h] = min(Hm[h], a)
Wm[w] = min(Wm[w], a)
HP[h].append((w, a))
WP[w].append((h, a))
Th = UFP(H)
Tw = UFP(W)
for h in range(H):
L = len(HP[h])
if L > 1:
HP[h].sort()
for i in range(L - 1):
wp, ap = HP[h][i]
wn, an = HP[h][i + 1]
if not Tw.union(wp, wn, an - ap):
return False
for w in range(W):
L = len(WP[w])
if L > 1:
WP[w].sort()
for i in range(L - 1):
hp, ap = WP[w][i]
hn, an = WP[w][i + 1]
if not Th.union(hp, hn, an - ap):
return False
cmh = [INF] * H
for h in range(H):
rh = Th.find(h)
cmh[rh] = min(cmh[rh], Th.dist[h])
cmw = [INF] * W
for w in range(W):
rw = Tw.find(w)
cmw[rw] = min(cmw[rw], Tw.dist[w])
for h in range(H):
if Hm[h] - Th.dist[h] + cmh[Th.find(h)] < 0:
return False
for w in range(W):
if Wm[w] - Tw.dist[w] + cmw[Tw.find(w)] < 0:
return False
return True
print("Yes" if check() else "No")
| Statement
There is a grid with R rows and C columns. We call the cell in the r-th row
and c-th column (r,c).
Mr. Takahashi wrote non-negative integers into N of the cells, that is, he
wrote a non-negative integer a_i into (r_i,c_i) for each i (1≤i≤N). After that
he fell asleep.
Mr. Aoki found the grid and tries to surprise Mr. Takahashi by writing
integers into all remaining cells. The grid must meet the following conditions
to really surprise Mr. Takahashi.
* Condition 1: Each cell contains a non-negative integer.
* Condition 2: For any 2×2 square formed by cells on the grid, the sum of the top left and bottom right integers must always equal to the sum of the top right and bottom left integers.
Determine whether it is possible to meet those conditions by properly writing
integers into all remaining cells. | [{"input": "2 2\n 3\n 1 1 0\n 1 2 10\n 2 1 20", "output": "Yes\n \n\nYou can write integers as follows.\n\n\n\n* * *"}, {"input": "2 3\n 5\n 1 1 0\n 1 2 10\n 1 3 20\n 2 1 30\n 2 3 40", "output": "No\n \n\nThere are two 2\u00d72 squares on the grid, formed by the following cells:\n\n * Cells (1\uff0c1), (1\uff0c2), (2\uff0c1) and (2\uff0c2)\n * Cells (1\uff0c2), (1\uff0c3), (2\uff0c2) and (2\uff0c3)\n\nYou have to write 40 into the empty cell to meet the condition on the left\nsquare, but then it does not satisfy the condition on the right square.\n\n\n\n* * *"}, {"input": "2 2\n 3\n 1 1 20\n 1 2 10\n 2 1 0", "output": "No\n \n\nYou have to write -10 into the empty cell to meet condition 2, but then it\ndoes not satisfy condition 1.\n\n\n\n* * *"}, {"input": "3 3\n 4\n 1 1 0\n 1 3 10\n 3 1 10\n 3 3 20", "output": "Yes\n \n\nYou can write integers as follows.\n\n\n\n* * *"}, {"input": "2 2\n 4\n 1 1 0\n 1 2 10\n 2 1 30\n 2 2 20", "output": "No\n \n\nAll cells already contain a integer and condition 2 is not satisfied.\n\n"}] |
Print `Yes` if it is possible to meet the conditions by properly writing
integers into all remaining cells. Otherwise, print `No`.
* * * | s158706636 | Wrong Answer | p03995 | The input is given from Standard Input in the following format:
R C
N
r_1 c_1 a_1
r_2 c_2 a_2
:
r_N c_N a_N | from collections import defaultdict, deque
import sys, heapq, bisect, math, itertools, string, queue, datetime
sys.setrecursionlimit(10**8)
INF = float("inf")
mod = 10**9 + 7
eps = 10**-7
def inpl():
return list(map(int, input().split()))
def inpl_s():
return list(input().split())
def find(x): # xの根を返す
global table
global diff_weight
if table[x] == x:
return x
else:
root = find(table[x])
diff_weight[x] += diff_weight[table[x]] # 親の更新に伴う 重みの更新
table[x] = root # 親の更新(根を直接親にして参照距離を短く)
return table[x]
def union(x, y, w): # xとyを diff(x,y)=w で繋げる
w = w - weight(y) + weight(x)
x = find(x)
y = find(y)
if x == y:
return
if rank[x] < rank[y]:
x, y = y, x
w = -w
table[y] = x
diff_weight[y] = w
if rank[x] == rank[y]:
rank[y] += 1
def check(x, y): # xとyか繋がっているか -> return bool
if find(x) == find(y):
return True
else:
return False
def weight(x):
find(x) # 経路圧縮
return diff_weight[x]
def diff(x, y): # weight(y)-weight(x) (繋がってる前提)
return weight(y) - weight(x)
H, W = inpl()
N = int(input())
lines = defaultdict(set)
table = [i for i in range(W)] # 木の親 table[x] == x なら根
rank = [1 for i in range(W)] # 木の長さ
diff_weight = [0 for i in range(W)]
for _ in range(N):
y, x, a = inpl()
x, y = x - 1, y - 1
lines[y].add((x, a))
for y in range(H):
for i, [x, c] in enumerate(lines[y]):
if i == 0:
bx, bc = x, c
continue
else:
if check(x, bx):
if diff(x, bx) != c - bc:
print("No")
sys.exit()
else:
if c > bc:
union(x, bx, c - bc)
else:
union(bx, x, bc - c)
bx, bc = x, c
MAX = max(diff_weight)
for y in range(H):
for x, c in lines[y]:
if c - (MAX - diff_weight[x]) < 0:
print("No")
sys.exit()
print("Yes")
| Statement
There is a grid with R rows and C columns. We call the cell in the r-th row
and c-th column (r,c).
Mr. Takahashi wrote non-negative integers into N of the cells, that is, he
wrote a non-negative integer a_i into (r_i,c_i) for each i (1≤i≤N). After that
he fell asleep.
Mr. Aoki found the grid and tries to surprise Mr. Takahashi by writing
integers into all remaining cells. The grid must meet the following conditions
to really surprise Mr. Takahashi.
* Condition 1: Each cell contains a non-negative integer.
* Condition 2: For any 2×2 square formed by cells on the grid, the sum of the top left and bottom right integers must always equal to the sum of the top right and bottom left integers.
Determine whether it is possible to meet those conditions by properly writing
integers into all remaining cells. | [{"input": "2 2\n 3\n 1 1 0\n 1 2 10\n 2 1 20", "output": "Yes\n \n\nYou can write integers as follows.\n\n\n\n* * *"}, {"input": "2 3\n 5\n 1 1 0\n 1 2 10\n 1 3 20\n 2 1 30\n 2 3 40", "output": "No\n \n\nThere are two 2\u00d72 squares on the grid, formed by the following cells:\n\n * Cells (1\uff0c1), (1\uff0c2), (2\uff0c1) and (2\uff0c2)\n * Cells (1\uff0c2), (1\uff0c3), (2\uff0c2) and (2\uff0c3)\n\nYou have to write 40 into the empty cell to meet the condition on the left\nsquare, but then it does not satisfy the condition on the right square.\n\n\n\n* * *"}, {"input": "2 2\n 3\n 1 1 20\n 1 2 10\n 2 1 0", "output": "No\n \n\nYou have to write -10 into the empty cell to meet condition 2, but then it\ndoes not satisfy condition 1.\n\n\n\n* * *"}, {"input": "3 3\n 4\n 1 1 0\n 1 3 10\n 3 1 10\n 3 3 20", "output": "Yes\n \n\nYou can write integers as follows.\n\n\n\n* * *"}, {"input": "2 2\n 4\n 1 1 0\n 1 2 10\n 2 1 30\n 2 2 20", "output": "No\n \n\nAll cells already contain a integer and condition 2 is not satisfied.\n\n"}] |
Print the string representing the type of the contest held this week.
* * * | s091168682 | Accepted | p02687 | Input is given from Standard Input in the following format:
S | print(["ABC", "ARC"][str(input()) == "ABC"])
| Statement
AtCoder Inc. holds a contest every Saturday.
There are two types of contests called ABC and ARC, and just one of them is
held at a time.
The company holds these two types of contests alternately: an ARC follows an
ABC and vice versa.
Given a string S representing the type of the contest held last week, print
the string representing the type of the contest held this week. | [{"input": "ABC", "output": "ARC\n \n\nThey held an ABC last week, so they will hold an ARC this week."}] |
Print the string representing the type of the contest held this week.
* * * | s929162633 | Accepted | p02687 | Input is given from Standard Input in the following format:
S | print("ARC" if "ABC" == input() else "ABC")
| Statement
AtCoder Inc. holds a contest every Saturday.
There are two types of contests called ABC and ARC, and just one of them is
held at a time.
The company holds these two types of contests alternately: an ARC follows an
ABC and vice versa.
Given a string S representing the type of the contest held last week, print
the string representing the type of the contest held this week. | [{"input": "ABC", "output": "ARC\n \n\nThey held an ABC last week, so they will hold an ARC this week."}] |
Print the string representing the type of the contest held this week.
* * * | s661051428 | Accepted | p02687 | Input is given from Standard Input in the following format:
S | print('ARC' if input()[1] == "B" else 'ABC') | Statement
AtCoder Inc. holds a contest every Saturday.
There are two types of contests called ABC and ARC, and just one of them is
held at a time.
The company holds these two types of contests alternately: an ARC follows an
ABC and vice versa.
Given a string S representing the type of the contest held last week, print
the string representing the type of the contest held this week. | [{"input": "ABC", "output": "ARC\n \n\nThey held an ABC last week, so they will hold an ARC this week."}] |
Print the string representing the type of the contest held this week.
* * * | s352479539 | Wrong Answer | p02687 | Input is given from Standard Input in the following format:
S | print("ABC" if input()[1] == "B" else "ARC")
| Statement
AtCoder Inc. holds a contest every Saturday.
There are two types of contests called ABC and ARC, and just one of them is
held at a time.
The company holds these two types of contests alternately: an ARC follows an
ABC and vice versa.
Given a string S representing the type of the contest held last week, print
the string representing the type of the contest held this week. | [{"input": "ABC", "output": "ARC\n \n\nThey held an ABC last week, so they will hold an ARC this week."}] |
Print the string representing the type of the contest held this week.
* * * | s204718837 | Wrong Answer | p02687 | Input is given from Standard Input in the following format:
S | print("ABC" if input() == "ABC" else "ARC")
| Statement
AtCoder Inc. holds a contest every Saturday.
There are two types of contests called ABC and ARC, and just one of them is
held at a time.
The company holds these two types of contests alternately: an ARC follows an
ABC and vice versa.
Given a string S representing the type of the contest held last week, print
the string representing the type of the contest held this week. | [{"input": "ABC", "output": "ARC\n \n\nThey held an ABC last week, so they will hold an ARC this week."}] |
Print the string representing the type of the contest held this week.
* * * | s846178826 | Runtime Error | p02687 | Input is given from Standard Input in the following format:
S | for i in range(0, 1):
S = input()
print("ABC")
for i in range(1, 2):
S = input()
print("ARC")
for i in range(2, 3):
S = input()
print("ABC")
for i in range(3, 4):
S = input()
print("ARC")
for i in range(4, 5):
S = input()
print("ABC")
for i in range(5, 6):
S = input()
print("ARC")
for i in range(6, 7):
S = input()
print("ABC")
for i in range(7, 8):
S = input()
print("ARC")
| Statement
AtCoder Inc. holds a contest every Saturday.
There are two types of contests called ABC and ARC, and just one of them is
held at a time.
The company holds these two types of contests alternately: an ARC follows an
ABC and vice versa.
Given a string S representing the type of the contest held last week, print
the string representing the type of the contest held this week. | [{"input": "ABC", "output": "ARC\n \n\nThey held an ABC last week, so they will hold an ARC this week."}] |
Print the string representing the type of the contest held this week.
* * * | s229543510 | Wrong Answer | p02687 | Input is given from Standard Input in the following format:
S | import glob
# 問題ごとのディレクトリのトップからの相対パス
REL_PATH = "ABC\\166\\A"
# テスト用ファイル置き場のトップ
TOP_PATH = "C:\\AtCoder"
class Common:
problem = []
index = 0
def __init__(self, rel_path):
self.rel_path = rel_path
def initialize(self, path):
file = open(path)
self.problem = file.readlines()
self.index = 0
return
def input_data(self):
try:
IS_TEST
self.index += 1
return self.problem[self.index - 1]
except NameError:
return input()
def resolve(self):
pass
def exec_resolve(self):
try:
IS_TEST
for path in glob.glob(TOP_PATH + "\\" + self.rel_path + "/*.txt"):
print("Test: " + path)
self.initialize(path)
self.resolve()
print("\n\n")
except NameError:
self.resolve()
class Solver(Common):
def resolve(self):
S = map(int, self.input_data().split())
if S == "ABC":
print("ARC")
else:
print("ABC")
solver = Solver(REL_PATH)
solver.exec_resolve()
| Statement
AtCoder Inc. holds a contest every Saturday.
There are two types of contests called ABC and ARC, and just one of them is
held at a time.
The company holds these two types of contests alternately: an ARC follows an
ABC and vice versa.
Given a string S representing the type of the contest held last week, print
the string representing the type of the contest held this week. | [{"input": "ABC", "output": "ARC\n \n\nThey held an ABC last week, so they will hold an ARC this week."}] |
Print the string representing the type of the contest held this week.
* * * | s479711050 | Runtime Error | p02687 | Input is given from Standard Input in the following format:
S | x = int(input())
a = 0
b = 0
for i in range(500):
for j in range(-1000, 1000):
if i**5 - j**5 == x:
a = i
b = j
break
print(a, b)
| Statement
AtCoder Inc. holds a contest every Saturday.
There are two types of contests called ABC and ARC, and just one of them is
held at a time.
The company holds these two types of contests alternately: an ARC follows an
ABC and vice versa.
Given a string S representing the type of the contest held last week, print
the string representing the type of the contest held this week. | [{"input": "ABC", "output": "ARC\n \n\nThey held an ABC last week, so they will hold an ARC this week."}] |
Print the string representing the type of the contest held this week.
* * * | s541539457 | Accepted | p02687 | Input is given from Standard Input in the following format:
S | print("AABRCC"[input() == "ABC" :: 2])
| Statement
AtCoder Inc. holds a contest every Saturday.
There are two types of contests called ABC and ARC, and just one of them is
held at a time.
The company holds these two types of contests alternately: an ARC follows an
ABC and vice versa.
Given a string S representing the type of the contest held last week, print
the string representing the type of the contest held this week. | [{"input": "ABC", "output": "ARC\n \n\nThey held an ABC last week, so they will hold an ARC this week."}] |
Print the string representing the type of the contest held this week.
* * * | s399516841 | Accepted | p02687 | Input is given from Standard Input in the following format:
S | a=input().rstrip()
y='ABC'
if(a==y):
y='ARC'
print(y) | Statement
AtCoder Inc. holds a contest every Saturday.
There are two types of contests called ABC and ARC, and just one of them is
held at a time.
The company holds these two types of contests alternately: an ARC follows an
ABC and vice versa.
Given a string S representing the type of the contest held last week, print
the string representing the type of the contest held this week. | [{"input": "ABC", "output": "ARC\n \n\nThey held an ABC last week, so they will hold an ARC this week."}] |
Print the string representing the type of the contest held this week.
* * * | s103091194 | Runtime Error | p02687 | Input is given from Standard Input in the following format:
S | print(f"A{[" b", " R"][input()[1] == " b"]}C")
| Statement
AtCoder Inc. holds a contest every Saturday.
There are two types of contests called ABC and ARC, and just one of them is
held at a time.
The company holds these two types of contests alternately: an ARC follows an
ABC and vice versa.
Given a string S representing the type of the contest held last week, print
the string representing the type of the contest held this week. | [{"input": "ABC", "output": "ARC\n \n\nThey held an ABC last week, so they will hold an ARC this week."}] |
Print the string representing the type of the contest held this week.
* * * | s403010057 | Wrong Answer | p02687 | Input is given from Standard Input in the following format:
S | print("ABRCC"[input() == "ARC" :: 2])
| Statement
AtCoder Inc. holds a contest every Saturday.
There are two types of contests called ABC and ARC, and just one of them is
held at a time.
The company holds these two types of contests alternately: an ARC follows an
ABC and vice versa.
Given a string S representing the type of the contest held last week, print
the string representing the type of the contest held this week. | [{"input": "ABC", "output": "ARC\n \n\nThey held an ABC last week, so they will hold an ARC this week."}] |
Print the string representing the type of the contest held this week.
* * * | s110040892 | Wrong Answer | p02687 | Input is given from Standard Input in the following format:
S | a = ["ABC", "ARC"]
print(a[input() == "ARC"])
| Statement
AtCoder Inc. holds a contest every Saturday.
There are two types of contests called ABC and ARC, and just one of them is
held at a time.
The company holds these two types of contests alternately: an ARC follows an
ABC and vice versa.
Given a string S representing the type of the contest held last week, print
the string representing the type of the contest held this week. | [{"input": "ABC", "output": "ARC\n \n\nThey held an ABC last week, so they will hold an ARC this week."}] |
Print the string representing the type of the contest held this week.
* * * | s050068872 | Accepted | p02687 | Input is given from Standard Input in the following format:
S | contests = ["ABC", "ARC"]
before_contest = input()
print(contests[0] if before_contest == contests[1] else contests[1])
| Statement
AtCoder Inc. holds a contest every Saturday.
There are two types of contests called ABC and ARC, and just one of them is
held at a time.
The company holds these two types of contests alternately: an ARC follows an
ABC and vice versa.
Given a string S representing the type of the contest held last week, print
the string representing the type of the contest held this week. | [{"input": "ABC", "output": "ARC\n \n\nThey held an ABC last week, so they will hold an ARC this week."}] |
Print the string representing the type of the contest held this week.
* * * | s762312202 | Wrong Answer | p02687 | Input is given from Standard Input in the following format:
S | print('A%sC'%'BR'[id(id)%9%2]) | Statement
AtCoder Inc. holds a contest every Saturday.
There are two types of contests called ABC and ARC, and just one of them is
held at a time.
The company holds these two types of contests alternately: an ARC follows an
ABC and vice versa.
Given a string S representing the type of the contest held last week, print
the string representing the type of the contest held this week. | [{"input": "ABC", "output": "ARC\n \n\nThey held an ABC last week, so they will hold an ARC this week."}] |
Print the string representing the type of the contest held this week.
* * * | s299808519 | Wrong Answer | p02687 | Input is given from Standard Input in the following format:
S | s = {input()}
test = {"ABC", "ARC"}
print(test - s)
| Statement
AtCoder Inc. holds a contest every Saturday.
There are two types of contests called ABC and ARC, and just one of them is
held at a time.
The company holds these two types of contests alternately: an ARC follows an
ABC and vice versa.
Given a string S representing the type of the contest held last week, print
the string representing the type of the contest held this week. | [{"input": "ABC", "output": "ARC\n \n\nThey held an ABC last week, so they will hold an ARC this week."}] |
Print the string representing the type of the contest held this week.
* * * | s172199236 | Wrong Answer | p02687 | Input is given from Standard Input in the following format:
S | #!/usr/bin/env python3
| Statement
AtCoder Inc. holds a contest every Saturday.
There are two types of contests called ABC and ARC, and just one of them is
held at a time.
The company holds these two types of contests alternately: an ARC follows an
ABC and vice versa.
Given a string S representing the type of the contest held last week, print
the string representing the type of the contest held this week. | [{"input": "ABC", "output": "ARC\n \n\nThey held an ABC last week, so they will hold an ARC this week."}] |
Print the string representing the type of the contest held this week.
* * * | s524162438 | Accepted | p02687 | Input is given from Standard Input in the following format:
S | p = list(input())
p[1] = "R" if p[1] == "B" else "B"
print("".join(p))
| Statement
AtCoder Inc. holds a contest every Saturday.
There are two types of contests called ABC and ARC, and just one of them is
held at a time.
The company holds these two types of contests alternately: an ARC follows an
ABC and vice versa.
Given a string S representing the type of the contest held last week, print
the string representing the type of the contest held this week. | [{"input": "ABC", "output": "ARC\n \n\nThey held an ABC last week, so they will hold an ARC this week."}] |
Print the string representing the type of the contest held this week.
* * * | s958537215 | Runtime Error | p02687 | Input is given from Standard Input in the following format:
S | def factorization(num):
if num == 1:
return [1]
factor = []
while num > 1:
for i in range(num - 1):
k = i + 2
if num % k == 0:
factor.append(k)
num = int(num / k)
break
return factor
x = int(input())
a = 0
b = 0
a_b = 0
y = factorization(x)
len_y = len(y)
z = set(y)
z = list(z)
# print(z)
for j in range(len(z)):
a_b = z[j]
for k in range(a_b):
a = a_b + k
b = k
if a**5 - b**5 == x:
print("%d %d" % (a, b))
exit()
a = a_b - k
b = 0 - k
if a**5 - b**5 == x:
print("%d %d" % (a, b))
exit()
if len_y > 2:
z = set([])
for l in range(0, len_y - 1):
for m in range(l, len_y):
z = z | set([y[l] * y[m]])
z = list(z)
for j in range(len(z)):
a_b = z[j]
for k in range(a_b):
a = a_b + k
b = k
if a**5 - b**5 == x:
print("%d %d" % (a, b))
exit()
a = a_b - k
b = 0 - k
if a**5 - b**5 == x:
print("%d %d" % (a, b))
exit()
if len_y > 3:
z = set([])
for l in range(0, len_y - 2):
for m in range(l, len_y - 1):
for n in range(m, len_y):
z = z | set([y[l] * y[m] * y[n]])
z = list(z)
for j in range(len(z)):
a_b = z[j]
for k in range(a_b):
a = a_b + k
b = k
if a**5 - b**5 == x:
print("%d %d" % (a, b))
exit()
a = a_b - k
b = 0 - k
if a**5 - b**5 == x:
print("%d %d" % (a, b))
exit()
if len_y > 4:
z = set([])
for l in range(0, len_y - 3):
for m in range(l, len_y - 2):
for n in range(m, len_y - 1):
for p in range(n, len_y):
z = z | set([y[l] * y[m] * y[p]])
z = list(z)
for j in range(len(z)):
a_b = z[j]
for k in range(a_b):
a = a_b + k
b = k
if a**5 - b**5 == x:
print("%d %d" % (a, b))
exit()
a = a_b - k
b = 0 - k
if a**5 - b**5 == x:
print("%d %d" % (a, b))
exit()
if len_y > 5:
z = set([])
for l in range(0, len_y - 4):
for m in range(l, len_y - 3):
for n in range(m, len_y - 2):
for p in range(n, len_y - 1):
for q in range(p, len_y):
z = z | set([y[l] * y[m] * y[p] * y[q]])
z = list(z)
for j in range(len(z)):
a_b = z[j]
for k in range(a_b):
a = a_b + k
b = k
if a**5 - b**5 == x:
print("%d %d" % (a, b))
exit()
a = a_b - k
b = 0 - k
if a**5 - b**5 == x:
print("%d %d" % (a, b))
exit()
| Statement
AtCoder Inc. holds a contest every Saturday.
There are two types of contests called ABC and ARC, and just one of them is
held at a time.
The company holds these two types of contests alternately: an ARC follows an
ABC and vice versa.
Given a string S representing the type of the contest held last week, print
the string representing the type of the contest held this week. | [{"input": "ABC", "output": "ARC\n \n\nThey held an ABC last week, so they will hold an ARC this week."}] |
Print the string representing the type of the contest held this week.
* * * | s550015920 | Accepted | p02687 | Input is given from Standard Input in the following format:
S | print(["ABC", "ARC"][input() == "ABC"])
| Statement
AtCoder Inc. holds a contest every Saturday.
There are two types of contests called ABC and ARC, and just one of them is
held at a time.
The company holds these two types of contests alternately: an ARC follows an
ABC and vice versa.
Given a string S representing the type of the contest held last week, print
the string representing the type of the contest held this week. | [{"input": "ABC", "output": "ARC\n \n\nThey held an ABC last week, so they will hold an ARC this week."}] |
Print the string representing the type of the contest held this week.
* * * | s739679481 | Accepted | p02687 | Input is given from Standard Input in the following format:
S | print(f"{'ABC' if input() == 'ARC' else 'ARC'}")
| Statement
AtCoder Inc. holds a contest every Saturday.
There are two types of contests called ABC and ARC, and just one of them is
held at a time.
The company holds these two types of contests alternately: an ARC follows an
ABC and vice versa.
Given a string S representing the type of the contest held last week, print
the string representing the type of the contest held this week. | [{"input": "ABC", "output": "ARC\n \n\nThey held an ABC last week, so they will hold an ARC this week."}] |
Print the string representing the type of the contest held this week.
* * * | s603416907 | Accepted | p02687 | Input is given from Standard Input in the following format:
S | print("A" + {"B": "R", "R": "B"}[input()[1]] + "C")
| Statement
AtCoder Inc. holds a contest every Saturday.
There are two types of contests called ABC and ARC, and just one of them is
held at a time.
The company holds these two types of contests alternately: an ARC follows an
ABC and vice versa.
Given a string S representing the type of the contest held last week, print
the string representing the type of the contest held this week. | [{"input": "ABC", "output": "ARC\n \n\nThey held an ABC last week, so they will hold an ARC this week."}] |
Print the string representing the type of the contest held this week.
* * * | s755592735 | Accepted | p02687 | Input is given from Standard Input in the following format:
S | str = input()
if str == 'ABC':
print('ARC')
if str == 'ARC':
print('ABC') | Statement
AtCoder Inc. holds a contest every Saturday.
There are two types of contests called ABC and ARC, and just one of them is
held at a time.
The company holds these two types of contests alternately: an ARC follows an
ABC and vice versa.
Given a string S representing the type of the contest held last week, print
the string representing the type of the contest held this week. | [{"input": "ABC", "output": "ARC\n \n\nThey held an ABC last week, so they will hold an ARC this week."}] |
Print the string representing the type of the contest held this week.
* * * | s500208260 | Runtime Error | p02687 | Input is given from Standard Input in the following format:
S | n = input()
l = list(map(int, input().split()))
x = 0
c = list()
for i in range(1, n + 1):
a = i + l[i - 1]
c.append(a)
b = i - l[i - 1]
if b in c:
x = x + c.count(b)
print(x)
| Statement
AtCoder Inc. holds a contest every Saturday.
There are two types of contests called ABC and ARC, and just one of them is
held at a time.
The company holds these two types of contests alternately: an ARC follows an
ABC and vice versa.
Given a string S representing the type of the contest held last week, print
the string representing the type of the contest held this week. | [{"input": "ABC", "output": "ARC\n \n\nThey held an ABC last week, so they will hold an ARC this week."}] |
Print the string representing the type of the contest held this week.
* * * | s868830375 | Accepted | p02687 | Input is given from Standard Input in the following format:
S | print("A" + "BR"[(input() == "ABC")] + "C")
| Statement
AtCoder Inc. holds a contest every Saturday.
There are two types of contests called ABC and ARC, and just one of them is
held at a time.
The company holds these two types of contests alternately: an ARC follows an
ABC and vice versa.
Given a string S representing the type of the contest held last week, print
the string representing the type of the contest held this week. | [{"input": "ABC", "output": "ARC\n \n\nThey held an ABC last week, so they will hold an ARC this week."}] |
Print the string representing the type of the contest held this week.
* * * | s209300928 | Accepted | p02687 | Input is given from Standard Input in the following format:
S | print("ABC" if str(input()) == "ARC" else "ARC")
| Statement
AtCoder Inc. holds a contest every Saturday.
There are two types of contests called ABC and ARC, and just one of them is
held at a time.
The company holds these two types of contests alternately: an ARC follows an
ABC and vice versa.
Given a string S representing the type of the contest held last week, print
the string representing the type of the contest held this week. | [{"input": "ABC", "output": "ARC\n \n\nThey held an ABC last week, so they will hold an ARC this week."}] |
Print the string representing the type of the contest held this week.
* * * | s699320238 | Accepted | p02687 | Input is given from Standard Input in the following format:
S | print("AABRCC"[input()[1] == "B" :: 2])
| Statement
AtCoder Inc. holds a contest every Saturday.
There are two types of contests called ABC and ARC, and just one of them is
held at a time.
The company holds these two types of contests alternately: an ARC follows an
ABC and vice versa.
Given a string S representing the type of the contest held last week, print
the string representing the type of the contest held this week. | [{"input": "ABC", "output": "ARC\n \n\nThey held an ABC last week, so they will hold an ARC this week."}] |
Print the string representing the type of the contest held this week.
* * * | s269131001 | Runtime Error | p02687 | Input is given from Standard Input in the following format:
S | print("ABC") if input() == "ARC" else print("ARC")
| Statement
AtCoder Inc. holds a contest every Saturday.
There are two types of contests called ABC and ARC, and just one of them is
held at a time.
The company holds these two types of contests alternately: an ARC follows an
ABC and vice versa.
Given a string S representing the type of the contest held last week, print
the string representing the type of the contest held this week. | [{"input": "ABC", "output": "ARC\n \n\nThey held an ABC last week, so they will hold an ARC this week."}] |
Print the string representing the type of the contest held this week.
* * * | s662972440 | Runtime Error | p02687 | Input is given from Standard Input in the following format:
S | N, K = map(int, input().split(" "))
flag = [1 for i in range(N)]
for i in range(K):
input()
for j in map(int, input().split(" ")):
flag[j - 1] = 0
sum(flag)
| Statement
AtCoder Inc. holds a contest every Saturday.
There are two types of contests called ABC and ARC, and just one of them is
held at a time.
The company holds these two types of contests alternately: an ARC follows an
ABC and vice versa.
Given a string S representing the type of the contest held last week, print
the string representing the type of the contest held this week. | [{"input": "ABC", "output": "ARC\n \n\nThey held an ABC last week, so they will hold an ARC this week."}] |
Print the string representing the type of the contest held this week.
* * * | s905951791 | Accepted | p02687 | Input is given from Standard Input in the following format:
S | a, b = "ABC", "ARC"
print({a: b, b: a}[input()])
| Statement
AtCoder Inc. holds a contest every Saturday.
There are two types of contests called ABC and ARC, and just one of them is
held at a time.
The company holds these two types of contests alternately: an ARC follows an
ABC and vice versa.
Given a string S representing the type of the contest held last week, print
the string representing the type of the contest held this week. | [{"input": "ABC", "output": "ARC\n \n\nThey held an ABC last week, so they will hold an ARC this week."}] |
Print the string representing the type of the contest held this week.
* * * | s881890842 | Wrong Answer | p02687 | Input is given from Standard Input in the following format:
S | print("ARC" if input() == "ABC" else "ARC")
| Statement
AtCoder Inc. holds a contest every Saturday.
There are two types of contests called ABC and ARC, and just one of them is
held at a time.
The company holds these two types of contests alternately: an ARC follows an
ABC and vice versa.
Given a string S representing the type of the contest held last week, print
the string representing the type of the contest held this week. | [{"input": "ABC", "output": "ARC\n \n\nThey held an ABC last week, so they will hold an ARC this week."}] |
Print the string representing the type of the contest held this week.
* * * | s601472634 | Runtime Error | p02687 | Input is given from Standard Input in the following format:
S | N, M = map(int, input().split())
H = list(map(int, input().split()))
tunagari = [[] for i in range(N)]
for i in range(M):
A, B = map(int, input().split())
tunagari[A - 1] += [B - 1]
tunagari[B - 1] += [A - 1]
nums = [0 for i in range(N)]
t = 0
for i in range(N):
tmpl = tunagari[i]
mini = min(tmpl)
if mini < i:
nums[i] = nums[mini]
continue
nums[i] = t
t += 1
maxn = max(nums)
groups = [[] for i in range(maxn + 1)]
print(maxn + 1)
for i in range(N):
groups[nums[i]] += [i]
ans = 0
for i in range(maxn):
tmpl = groups[i]
tmpl2 = []
for i in tmpl:
tmpl2 += [H[i]]
n = len(tmpl)
if n == 1:
ans += 1
else:
tmpl2.sort()
if tmpl2[-1] != tmpl2[-2]:
ans += 1
| Statement
AtCoder Inc. holds a contest every Saturday.
There are two types of contests called ABC and ARC, and just one of them is
held at a time.
The company holds these two types of contests alternately: an ARC follows an
ABC and vice versa.
Given a string S representing the type of the contest held last week, print
the string representing the type of the contest held this week. | [{"input": "ABC", "output": "ARC\n \n\nThey held an ABC last week, so they will hold an ARC this week."}] |
Print the string representing the type of the contest held this week.
* * * | s243129301 | Wrong Answer | p02687 | Input is given from Standard Input in the following format:
S | a = input()[1]
print(f'A{"B" if a=="B" else "R"}C')
| Statement
AtCoder Inc. holds a contest every Saturday.
There are two types of contests called ABC and ARC, and just one of them is
held at a time.
The company holds these two types of contests alternately: an ARC follows an
ABC and vice versa.
Given a string S representing the type of the contest held last week, print
the string representing the type of the contest held this week. | [{"input": "ABC", "output": "ARC\n \n\nThey held an ABC last week, so they will hold an ARC this week."}] |
Print the string representing the type of the contest held this week.
* * * | s253840541 | Wrong Answer | p02687 | Input is given from Standard Input in the following format:
S | n = list(str(input()))
if n[1] == "B":
n[1] = "R"
elif n[1] == "R":
n[1] == "B"
print("".join(n))
| Statement
AtCoder Inc. holds a contest every Saturday.
There are two types of contests called ABC and ARC, and just one of them is
held at a time.
The company holds these two types of contests alternately: an ARC follows an
ABC and vice versa.
Given a string S representing the type of the contest held last week, print
the string representing the type of the contest held this week. | [{"input": "ABC", "output": "ARC\n \n\nThey held an ABC last week, so they will hold an ARC this week."}] |
Print the string representing the type of the contest held this week.
* * * | s372991787 | Wrong Answer | p02687 | Input is given from Standard Input in the following format:
S | print("ARC") if input() == "ABC" else print("ARC")
| Statement
AtCoder Inc. holds a contest every Saturday.
There are two types of contests called ABC and ARC, and just one of them is
held at a time.
The company holds these two types of contests alternately: an ARC follows an
ABC and vice versa.
Given a string S representing the type of the contest held last week, print
the string representing the type of the contest held this week. | [{"input": "ABC", "output": "ARC\n \n\nThey held an ABC last week, so they will hold an ARC this week."}] |
For each dataset, find the pair with the highest price sum not exceeding the
allowed amount _m_ and output the sum in a line. If the price sum of every
pair of items exceeds _m_ , output `NONE` instead. | s652543490 | Accepted | p01101 | The input consists of multiple datasets, each in the following format.
_n_ _m_
_a_ 1 _a_ 2 ... _a n_
A dataset consists of two lines. In the first line, the number of items _n_
and the maximum payment allowed _m_ are given. _n_ is an integer satisfying 2
≤ _n_ ≤ 1000\. _m_ is an integer satisfying 2 ≤ _m_ ≤ 2,000,000. In the second
line, prices of _n_ items are given. _a i_ (1 ≤ _i_ ≤ _n_) is the price of the
_i_ -th item. This value is an integer greater than or equal to 1 and less
than or equal to 1,000,000.
The end of the input is indicated by a line containing two zeros. The sum of
_n_ 's of all the datasets does not exceed 50,000. | while True:
n, m = map(int, input().strip().split())
if n == 0:
break
a = sorted(list(map(int, input().strip().split())))
ans = 0
pos = n - 1
for i in range(n):
while pos > i and a[i] + a[pos] > m:
pos -= 1
if pos <= i:
break
ans = max(ans, a[i] + a[pos])
print(ans if ans > 0 else "NONE")
| _Taro's Shopping_
Mammy decided to give Taro his first shopping experience. Mammy tells him to
choose any two items he wants from those listed in the shopping catalogue, but
Taro cannot decide which two, as all the items look attractive. Thus he plans
to buy the pair of two items with the highest price sum, not exceeding the
amount Mammy allows. As getting two of the same item is boring, he wants two
different items.
You are asked to help Taro select the two items. The price list for all of the
items is given. Among pairs of two items in the list, find the pair with the
highest price sum not exceeding the allowed amount, and report the sum. Taro
is buying two items, not one, nor three, nor more. Note that, two or more
items in the list may be priced equally. | [{"input": "45\n 10 20 30\n 6 10\n 1 2 5 8 9 11\n 7 100\n 11 34 83 47 59 29 70\n 4 100\n 80 70 60 50\n 4 20\n 10 5 10 16\n 0 0", "output": "10\n 99\n NONE\n 20"}] |
For each dataset, find the pair with the highest price sum not exceeding the
allowed amount _m_ and output the sum in a line. If the price sum of every
pair of items exceeds _m_ , output `NONE` instead. | s181784820 | Wrong Answer | p01101 | The input consists of multiple datasets, each in the following format.
_n_ _m_
_a_ 1 _a_ 2 ... _a n_
A dataset consists of two lines. In the first line, the number of items _n_
and the maximum payment allowed _m_ are given. _n_ is an integer satisfying 2
≤ _n_ ≤ 1000\. _m_ is an integer satisfying 2 ≤ _m_ ≤ 2,000,000. In the second
line, prices of _n_ items are given. _a i_ (1 ≤ _i_ ≤ _n_) is the price of the
_i_ -th item. This value is an integer greater than or equal to 1 and less
than or equal to 1,000,000.
The end of the input is indicated by a line containing two zeros. The sum of
_n_ 's of all the datasets does not exceed 50,000. | n, m = map(int, input().split())
a = [0] * n
a = list(input().split())
for i in range(n):
a[i] = int(a[i])
max = 0
for i in range(n):
for j in range(n):
if i < j:
tmp = a[i] + a[j]
if tmp > max and tmp <= m:
max = tmp
else:
pass
else:
pass
if max == 0:
print("NONE")
else:
print(max)
| _Taro's Shopping_
Mammy decided to give Taro his first shopping experience. Mammy tells him to
choose any two items he wants from those listed in the shopping catalogue, but
Taro cannot decide which two, as all the items look attractive. Thus he plans
to buy the pair of two items with the highest price sum, not exceeding the
amount Mammy allows. As getting two of the same item is boring, he wants two
different items.
You are asked to help Taro select the two items. The price list for all of the
items is given. Among pairs of two items in the list, find the pair with the
highest price sum not exceeding the allowed amount, and report the sum. Taro
is buying two items, not one, nor three, nor more. Note that, two or more
items in the list may be priced equally. | [{"input": "45\n 10 20 30\n 6 10\n 1 2 5 8 9 11\n 7 100\n 11 34 83 47 59 29 70\n 4 100\n 80 70 60 50\n 4 20\n 10 5 10 16\n 0 0", "output": "10\n 99\n NONE\n 20"}] |
Print the number of possible final sequences of colors of the stones, modulo
10^9+7.
* * * | s746712799 | Accepted | p03096 | Input is given from Standard Input in the following format:
N
C_1
:
C_N | n = int(input())
M = pow(10, 9) + 7
import sys
dc = {}
al = [0]
rr = [1]
def search(ss, start, end):
z = al[(start + end) // 2]
nz = al[(start + end) // 2 + 1]
if z <= ss and ss < nz:
return (start + end) // 2
elif ss < z:
return search(ss, start, (start + end) // 2)
else:
return search(ss, (start + end) // 2 + 1, end)
c = 0
cn = 0
for line in sys.stdin:
a = int(line)
if a in dc:
ss = dc[a]
if ss != c - 1:
if ss >= al[cn]:
rr.append((rr[cn] * 2) % M)
else:
i = search(ss, 0, cn)
rr.append((rr[cn] + rr[i]) % M)
al.append(c)
cn += 1
dc[a] = c
c += 1
print(rr[cn] % M)
| Statement
There are N stones arranged in a row. The i-th stone from the left is painted
in the color C_i.
Snuke will perform the following operation zero or more times:
* Choose two stones painted in the same color. Repaint all the stones between them, with the color of the chosen stones.
Find the number of possible final sequences of colors of the stones, modulo
10^9+7. | [{"input": "5\n 1\n 2\n 1\n 2\n 2", "output": "3\n \n\nWe can make three sequences of colors of stones, as follows:\n\n * (1,2,1,2,2), by doing nothing.\n * (1,1,1,2,2), by choosing the first and third stones to perform the operation.\n * (1,2,2,2,2), by choosing the second and fourth stones to perform the operation.\n\n* * *"}, {"input": "6\n 4\n 2\n 5\n 4\n 2\n 4", "output": "5\n \n\n* * *"}, {"input": "7\n 1\n 3\n 1\n 2\n 3\n 3\n 2", "output": "5"}] |
Print the number of possible final sequences of colors of the stones, modulo
10^9+7.
* * * | s655716016 | Runtime Error | p03096 | Input is given from Standard Input in the following format:
N
C_1
:
C_N | n = int(input(""))
mod = 1e9 + 7
x = []
f = []
sum = [0 for j in range(0, n + 1)]
def add(a, b):
s = (a + b) % mod
return s
f.append(1)
x.append(0)
for i in range(1, n + 1):
x.append(int(input()))
if x[i] == x[i - 1]:
f.append(f[i - 1])
else:
f.append(add(f[i - 1], sum[x[i]]))
sum[x[i]] = f[i]
print(int(f[n]))
| Statement
There are N stones arranged in a row. The i-th stone from the left is painted
in the color C_i.
Snuke will perform the following operation zero or more times:
* Choose two stones painted in the same color. Repaint all the stones between them, with the color of the chosen stones.
Find the number of possible final sequences of colors of the stones, modulo
10^9+7. | [{"input": "5\n 1\n 2\n 1\n 2\n 2", "output": "3\n \n\nWe can make three sequences of colors of stones, as follows:\n\n * (1,2,1,2,2), by doing nothing.\n * (1,1,1,2,2), by choosing the first and third stones to perform the operation.\n * (1,2,2,2,2), by choosing the second and fourth stones to perform the operation.\n\n* * *"}, {"input": "6\n 4\n 2\n 5\n 4\n 2\n 4", "output": "5\n \n\n* * *"}, {"input": "7\n 1\n 3\n 1\n 2\n 3\n 3\n 2", "output": "5"}] |
Print the number of possible final sequences of colors of the stones, modulo
10^9+7.
* * * | s737535952 | Accepted | p03096 | Input is given from Standard Input in the following format:
N
C_1
:
C_N | N = int(input())
C = [int(input()) for i in range(N)]
a = [0] * N
p = {}
m = 10**9 + 7
for i, c in enumerate(C):
a[i] = a[i - 1]
if c in p and p[c] < i - 1:
a[i] = (a[i] + a[p[c]] + 1) % m
p[c] = i
print(a[-1] + 1)
| Statement
There are N stones arranged in a row. The i-th stone from the left is painted
in the color C_i.
Snuke will perform the following operation zero or more times:
* Choose two stones painted in the same color. Repaint all the stones between them, with the color of the chosen stones.
Find the number of possible final sequences of colors of the stones, modulo
10^9+7. | [{"input": "5\n 1\n 2\n 1\n 2\n 2", "output": "3\n \n\nWe can make three sequences of colors of stones, as follows:\n\n * (1,2,1,2,2), by doing nothing.\n * (1,1,1,2,2), by choosing the first and third stones to perform the operation.\n * (1,2,2,2,2), by choosing the second and fourth stones to perform the operation.\n\n* * *"}, {"input": "6\n 4\n 2\n 5\n 4\n 2\n 4", "output": "5\n \n\n* * *"}, {"input": "7\n 1\n 3\n 1\n 2\n 3\n 3\n 2", "output": "5"}] |
Print the number of possible final sequences of colors of the stones, modulo
10^9+7.
* * * | s538555839 | Accepted | p03096 | Input is given from Standard Input in the following format:
N
C_1
:
C_N | MOD = 10**9 + 7
class Fp(int):
def __new__(self, x=0):
return super().__new__(self, x % MOD)
def inv(self):
return self.__class__(super().__pow__(MOD - 2, MOD))
def __add__(self, value):
return self.__class__(super().__add__(value))
def __sub__(self, value):
return self.__class__(super().__sub__(value))
def __mul__(self, value):
return self.__class__(super().__mul__(value))
def __floordiv__(self, value):
return self.__class__(self * self.__class__(value).inv())
def __pow__(self, value):
return self.__class__(super().__pow__(value % (MOD - 1), MOD))
__radd__ = __add__
__rmul__ = __mul__
def __rsub__(self, value):
return self.__class__(-super().__sub__(value))
def __rfloordiv__(self, value):
return self.__class__(self.inv() * value)
def __iadd__(self, value):
self = self + value
return self
def __isub__(self, value):
self = self - value
return self
def __imul__(self, value):
self = self * value
return self
def __ifloordiv__(self, value):
self = self // value
return self
def __ipow__(self, value):
self = self**value
return self
def __neg__(self):
return self.__class__(super().__neg__())
def main():
N, *C = map(int, open(0).read().split())
DP = [Fp(1)] * (N + 1)
prev = {}
for i, c in enumerate(C):
d = DP[i]
if c in prev and not (i and C[i - 1] == c):
d += DP[prev[c]]
prev[c] = i + 1
DP[i + 1] = d
print(DP[N])
if __name__ == "__main__":
main()
| Statement
There are N stones arranged in a row. The i-th stone from the left is painted
in the color C_i.
Snuke will perform the following operation zero or more times:
* Choose two stones painted in the same color. Repaint all the stones between them, with the color of the chosen stones.
Find the number of possible final sequences of colors of the stones, modulo
10^9+7. | [{"input": "5\n 1\n 2\n 1\n 2\n 2", "output": "3\n \n\nWe can make three sequences of colors of stones, as follows:\n\n * (1,2,1,2,2), by doing nothing.\n * (1,1,1,2,2), by choosing the first and third stones to perform the operation.\n * (1,2,2,2,2), by choosing the second and fourth stones to perform the operation.\n\n* * *"}, {"input": "6\n 4\n 2\n 5\n 4\n 2\n 4", "output": "5\n \n\n* * *"}, {"input": "7\n 1\n 3\n 1\n 2\n 3\n 3\n 2", "output": "5"}] |
Print the number of possible final sequences of colors of the stones, modulo
10^9+7.
* * * | s292322783 | Accepted | p03096 | Input is given from Standard Input in the following format:
N
C_1
:
C_N | import sys, bisect
sys.setrecursionlimit(10000000)
N = int(input())
C = [int(input()) for _ in range(N)] # color
v = 10**9 + 7
from collections import defaultdict
d = defaultdict(list)
for i, c in enumerate(C):
d[c].append(i)
def guchoku(l):
assert isinstance(l, list)
if len(l) <= 2:
return 1
top_coor = l[0]
if top_coor in l[1:] and l[0] != l[1]:
_index = l[1:].index(top_coor)
return guchoku(l[_index + 1 :]) + guchoku(l[1:])
return guchoku(l[1:])
cache = dict()
cache[N] = 1
cache[N - 1] = 1
cache[N - 2] = 1
def check(i):
index = bisect.bisect_left(d[C[i]], i + 1)
if index == len(d[C[i]]):
return -1
# print(i, d[C[i]] ,d[C[i]][index])
return d[C[i]][index]
def guchoku_i(i):
# print("hoge",i,d[C[i]])
if i < 0:
raise
if i in cache:
return cache[i]
c = check(i)
if C[i] != C[i + 1] and c != -1:
cache[i] = guchoku_i(i + 1) + guchoku_i(c) % v
return cache[i]
cache[i] = guchoku_i(i + 1) % v
return cache[i]
# print(guchoku(C))
print(guchoku_i(0) % v)
| Statement
There are N stones arranged in a row. The i-th stone from the left is painted
in the color C_i.
Snuke will perform the following operation zero or more times:
* Choose two stones painted in the same color. Repaint all the stones between them, with the color of the chosen stones.
Find the number of possible final sequences of colors of the stones, modulo
10^9+7. | [{"input": "5\n 1\n 2\n 1\n 2\n 2", "output": "3\n \n\nWe can make three sequences of colors of stones, as follows:\n\n * (1,2,1,2,2), by doing nothing.\n * (1,1,1,2,2), by choosing the first and third stones to perform the operation.\n * (1,2,2,2,2), by choosing the second and fourth stones to perform the operation.\n\n* * *"}, {"input": "6\n 4\n 2\n 5\n 4\n 2\n 4", "output": "5\n \n\n* * *"}, {"input": "7\n 1\n 3\n 1\n 2\n 3\n 3\n 2", "output": "5"}] |
Print the number of possible final sequences of colors of the stones, modulo
10^9+7.
* * * | s548195843 | Accepted | p03096 | Input is given from Standard Input in the following format:
N
C_1
:
C_N | d = {i: 0 for i in range(1 << 18)}
c = 0
r = 1
for _ in [0] * int(input()):
m = int(input())
r += d[m] * (c != m)
d[m] = r
c = m
print(r % (10**9 + 7))
| Statement
There are N stones arranged in a row. The i-th stone from the left is painted
in the color C_i.
Snuke will perform the following operation zero or more times:
* Choose two stones painted in the same color. Repaint all the stones between them, with the color of the chosen stones.
Find the number of possible final sequences of colors of the stones, modulo
10^9+7. | [{"input": "5\n 1\n 2\n 1\n 2\n 2", "output": "3\n \n\nWe can make three sequences of colors of stones, as follows:\n\n * (1,2,1,2,2), by doing nothing.\n * (1,1,1,2,2), by choosing the first and third stones to perform the operation.\n * (1,2,2,2,2), by choosing the second and fourth stones to perform the operation.\n\n* * *"}, {"input": "6\n 4\n 2\n 5\n 4\n 2\n 4", "output": "5\n \n\n* * *"}, {"input": "7\n 1\n 3\n 1\n 2\n 3\n 3\n 2", "output": "5"}] |
If there exists an equilateral triangle whose sides have lengths A, B and C,
print `Yes`; otherwise, print `No`.
* * * | s795095290 | Accepted | p03079 | Input is given from Standard Input in the following format:
A B C | x = [int(i) for i in input().split(" ")]
y = "Yes" if x[0] ** 3 == x[0] * x[1] * x[2] else "No"
print(y)
| Statement
You are given three integers A, B and C.
Determine if there exists an equilateral triangle whose sides have lengths A,
B and C. | [{"input": "2 2 2", "output": "Yes\n \n\n * There exists an equilateral triangle whose sides have lengths 2, 2 and 2.\n\n* * *"}, {"input": "3 4 5", "output": "No\n \n\n * There is no equilateral triangle whose sides have lengths 3, 4 and 5."}] |
If there exists an equilateral triangle whose sides have lengths A, B and C,
print `Yes`; otherwise, print `No`.
* * * | s826646091 | Accepted | p03079 | Input is given from Standard Input in the following format:
A B C | l = list(map(int, input().split()))
print("Yes" if len(set(l)) == 1 else "No")
| Statement
You are given three integers A, B and C.
Determine if there exists an equilateral triangle whose sides have lengths A,
B and C. | [{"input": "2 2 2", "output": "Yes\n \n\n * There exists an equilateral triangle whose sides have lengths 2, 2 and 2.\n\n* * *"}, {"input": "3 4 5", "output": "No\n \n\n * There is no equilateral triangle whose sides have lengths 3, 4 and 5."}] |
If there exists an equilateral triangle whose sides have lengths A, B and C,
print `Yes`; otherwise, print `No`.
* * * | s790576992 | Accepted | p03079 | Input is given from Standard Input in the following format:
A B C | print("NYoe s"[len(set(input().split())) == 1 :: 2])
| Statement
You are given three integers A, B and C.
Determine if there exists an equilateral triangle whose sides have lengths A,
B and C. | [{"input": "2 2 2", "output": "Yes\n \n\n * There exists an equilateral triangle whose sides have lengths 2, 2 and 2.\n\n* * *"}, {"input": "3 4 5", "output": "No\n \n\n * There is no equilateral triangle whose sides have lengths 3, 4 and 5."}] |
If there exists an equilateral triangle whose sides have lengths A, B and C,
print `Yes`; otherwise, print `No`.
* * * | s010765810 | Runtime Error | p03079 | Input is given from Standard Input in the following format:
A B C | # coding: utf-8
def main():
N, Q = map(int, input().split())
s = input()
ans = N
command = []
# print(char_list)
for i in range(Q):
t, d = input().split()
command.append([t, d])
r = binary_serch_R(command, s, N)
# print(r)
l = binary_serch_L(command, s, N)
# print(l)
ans = ans - (N - r) - (l + 1)
if ans < 0:
ans = 0
print(ans)
def simulation_R(command, s, now, N):
for pair in command:
if pair[0] == s[now]:
if pair[1] == "L":
now -= 1
elif pair[1] == "R":
now += 1
if now < 0:
return False
elif now >= N:
return True
return False
def simulation_L(command, s, now, N):
for pair in command:
if pair[0] == s[now]:
if pair[1] == "L":
now -= 1
elif pair[1] == "R":
now += 1
if now < 0:
return True
elif now >= N:
return False
return False
def binary_serch_R(command, s, N):
left = 0
right = N - 1
if simulation_R(command, s, left, N):
return -1
if simulation_R(command, s, right, N) == False:
return N
while abs(right - left) > 1:
mid = int((left + right) / 2)
# print(mid)
if simulation_R(command, s, mid, N):
right = mid
else:
left = mid
return right
def binary_serch_L(command, s, N):
left = 0
right = N - 1
if simulation_L(command, s, left, N) == False:
return -1
if simulation_L(command, s, right, N):
return N
while abs(right - left) > 1:
mid = int((left + right) / 2)
if simulation_L(command, s, mid, N):
left = mid
else:
right = mid
return left
if __name__ == "__main__":
main()
| Statement
You are given three integers A, B and C.
Determine if there exists an equilateral triangle whose sides have lengths A,
B and C. | [{"input": "2 2 2", "output": "Yes\n \n\n * There exists an equilateral triangle whose sides have lengths 2, 2 and 2.\n\n* * *"}, {"input": "3 4 5", "output": "No\n \n\n * There is no equilateral triangle whose sides have lengths 3, 4 and 5."}] |
If there exists an equilateral triangle whose sides have lengths A, B and C,
print `Yes`; otherwise, print `No`.
* * * | s532702986 | Runtime Error | p03079 | Input is given from Standard Input in the following format:
A B C | def cmb(n, r):
if r < 0 or r > n:
return 0
r = min(r, n - r)
return g1[n] * g2[r] * g2[n - r] % mod
mod = 10**9 + 7 # 出力の制限
N = 2 * 10**5
g1 = [1, 1] # 元テーブル
g2 = [1, 1] # 逆元テーブル
inverse = [0, 1] # 逆元テーブル計算用テーブル
for i in range(2, N + 1):
g1.append((g1[-1] * i) % mod)
inverse.append((-inverse[mod % i] * (mod // i)) % mod)
g2.append((g2[-1] * inverse[-1]) % mod)
b, w = map(int, input().split())
x = 0
y = 0
for i in range(1, b + w + 1):
x = (x * 2 + cmb(i - 2, b - 1)) % mod
y = (y * 2 + cmb(i - 2, w - 1)) % mod
print((mod + pow(2, i - 1, mod) - x + y) * pow(pow(2, i, mod), mod - 2, mod) % mod)
| Statement
You are given three integers A, B and C.
Determine if there exists an equilateral triangle whose sides have lengths A,
B and C. | [{"input": "2 2 2", "output": "Yes\n \n\n * There exists an equilateral triangle whose sides have lengths 2, 2 and 2.\n\n* * *"}, {"input": "3 4 5", "output": "No\n \n\n * There is no equilateral triangle whose sides have lengths 3, 4 and 5."}] |
If there exists an equilateral triangle whose sides have lengths A, B and C,
print `Yes`; otherwise, print `No`.
* * * | s273085532 | Runtime Error | p03079 | Input is given from Standard Input in the following format:
A B C | a = [map(int, input().split())]
print("Yes" if a[0] == a[1] and a[0] == a[2] else "No")
| Statement
You are given three integers A, B and C.
Determine if there exists an equilateral triangle whose sides have lengths A,
B and C. | [{"input": "2 2 2", "output": "Yes\n \n\n * There exists an equilateral triangle whose sides have lengths 2, 2 and 2.\n\n* * *"}, {"input": "3 4 5", "output": "No\n \n\n * There is no equilateral triangle whose sides have lengths 3, 4 and 5."}] |
If there exists an equilateral triangle whose sides have lengths A, B and C,
print `Yes`; otherwise, print `No`.
* * * | s379717330 | Runtime Error | p03079 | Input is given from Standard Input in the following format:
A B C | def main():
N, Q = input().split()
N = int(N)
Q = int(Q)
G = [1] * N
S = input()
for _ in range(Q):
t, d = input().split()
if d == "L":
# for i in range(0,N):
for i in range(0, Q):
if S[i] == t and G[i] > 0:
if i == 0:
G[i] = 0
else:
G[i - 1] = G[i - 1] + G[i]
G[i] = 0
else: # "R"
# for i in range(N-1,-1,-1):
for i in range(N - 1, N - Q - 1, -1):
if S[i] == t and G[i] > 0:
if i == N - 1:
G[i] = 0
else:
G[i + 1] = G[i + 1] + G[i]
G[i] = 0
# print(G)
print(sum(G))
if __name__ == "__main__":
main()
| Statement
You are given three integers A, B and C.
Determine if there exists an equilateral triangle whose sides have lengths A,
B and C. | [{"input": "2 2 2", "output": "Yes\n \n\n * There exists an equilateral triangle whose sides have lengths 2, 2 and 2.\n\n* * *"}, {"input": "3 4 5", "output": "No\n \n\n * There is no equilateral triangle whose sides have lengths 3, 4 and 5."}] |
If there exists an equilateral triangle whose sides have lengths A, B and C,
print `Yes`; otherwise, print `No`.
* * * | s053644175 | Runtime Error | p03079 | Input is given from Standard Input in the following format:
A B C | N, Q = map(int, input().split())
s = list(input())
box = [1] * (N + 2)
for _ in range(Q):
k = 1
t, d = map(str, input().split())
for j in s:
if t == j:
if box[k] > 0:
if d == "L":
box[k - 1] += box[k]
box[k] = 0
else:
box[k + 1] += box[k]
box[k] = 0
k += 1
print(sum(box[1 : N + 1]))
| Statement
You are given three integers A, B and C.
Determine if there exists an equilateral triangle whose sides have lengths A,
B and C. | [{"input": "2 2 2", "output": "Yes\n \n\n * There exists an equilateral triangle whose sides have lengths 2, 2 and 2.\n\n* * *"}, {"input": "3 4 5", "output": "No\n \n\n * There is no equilateral triangle whose sides have lengths 3, 4 and 5."}] |
If there exists an equilateral triangle whose sides have lengths A, B and C,
print `Yes`; otherwise, print `No`.
* * * | s648324038 | Wrong Answer | p03079 | Input is given from Standard Input in the following format:
A B C | a, b, c = [int(x) for x in input().split(" ")]
print("Yes" if a**2 + b**2 == c**2 else "No")
| Statement
You are given three integers A, B and C.
Determine if there exists an equilateral triangle whose sides have lengths A,
B and C. | [{"input": "2 2 2", "output": "Yes\n \n\n * There exists an equilateral triangle whose sides have lengths 2, 2 and 2.\n\n* * *"}, {"input": "3 4 5", "output": "No\n \n\n * There is no equilateral triangle whose sides have lengths 3, 4 and 5."}] |
If there exists an equilateral triangle whose sides have lengths A, B and C,
print `Yes`; otherwise, print `No`.
* * * | s965151446 | Wrong Answer | p03079 | Input is given from Standard Input in the following format:
A B C | hen_list = list(map(int, input().split()))
print(["No", "Yes"][sum(hen_list) - 2 * max(hen_list) > 0])
| Statement
You are given three integers A, B and C.
Determine if there exists an equilateral triangle whose sides have lengths A,
B and C. | [{"input": "2 2 2", "output": "Yes\n \n\n * There exists an equilateral triangle whose sides have lengths 2, 2 and 2.\n\n* * *"}, {"input": "3 4 5", "output": "No\n \n\n * There is no equilateral triangle whose sides have lengths 3, 4 and 5."}] |
If there exists an equilateral triangle whose sides have lengths A, B and C,
print `Yes`; otherwise, print `No`.
* * * | s692179691 | Accepted | p03079 | Input is given from Standard Input in the following format:
A B C | print("No" if ~-len(set(input().split())) else "Yes")
| Statement
You are given three integers A, B and C.
Determine if there exists an equilateral triangle whose sides have lengths A,
B and C. | [{"input": "2 2 2", "output": "Yes\n \n\n * There exists an equilateral triangle whose sides have lengths 2, 2 and 2.\n\n* * *"}, {"input": "3 4 5", "output": "No\n \n\n * There is no equilateral triangle whose sides have lengths 3, 4 and 5."}] |
If there exists an equilateral triangle whose sides have lengths A, B and C,
print `Yes`; otherwise, print `No`.
* * * | s845578214 | Accepted | p03079 | Input is given from Standard Input in the following format:
A B C | print("Yes" if len(set(map(int, input().split()))) == 1 else "No")
| Statement
You are given three integers A, B and C.
Determine if there exists an equilateral triangle whose sides have lengths A,
B and C. | [{"input": "2 2 2", "output": "Yes\n \n\n * There exists an equilateral triangle whose sides have lengths 2, 2 and 2.\n\n* * *"}, {"input": "3 4 5", "output": "No\n \n\n * There is no equilateral triangle whose sides have lengths 3, 4 and 5."}] |
If there exists an equilateral triangle whose sides have lengths A, B and C,
print `Yes`; otherwise, print `No`.
* * * | s599118293 | Accepted | p03079 | Input is given from Standard Input in the following format:
A B C | li = set(map(int, input().split()))
print("Yes" if len(li) == 1 else "No")
| Statement
You are given three integers A, B and C.
Determine if there exists an equilateral triangle whose sides have lengths A,
B and C. | [{"input": "2 2 2", "output": "Yes\n \n\n * There exists an equilateral triangle whose sides have lengths 2, 2 and 2.\n\n* * *"}, {"input": "3 4 5", "output": "No\n \n\n * There is no equilateral triangle whose sides have lengths 3, 4 and 5."}] |
If there exists an equilateral triangle whose sides have lengths A, B and C,
print `Yes`; otherwise, print `No`.
* * * | s331856155 | Wrong Answer | p03079 | Input is given from Standard Input in the following format:
A B C | print("a")
| Statement
You are given three integers A, B and C.
Determine if there exists an equilateral triangle whose sides have lengths A,
B and C. | [{"input": "2 2 2", "output": "Yes\n \n\n * There exists an equilateral triangle whose sides have lengths 2, 2 and 2.\n\n* * *"}, {"input": "3 4 5", "output": "No\n \n\n * There is no equilateral triangle whose sides have lengths 3, 4 and 5."}] |
If there exists an equilateral triangle whose sides have lengths A, B and C,
print `Yes`; otherwise, print `No`.
* * * | s482863654 | Wrong Answer | p03079 | Input is given from Standard Input in the following format:
A B C | a, b, c = map(int, input().split())
is1 = a + b > c
is2 = b + c > a
is3 = c + a > b
ans = "Yes" if is1 & is2 & is3 else "No"
print(ans)
| Statement
You are given three integers A, B and C.
Determine if there exists an equilateral triangle whose sides have lengths A,
B and C. | [{"input": "2 2 2", "output": "Yes\n \n\n * There exists an equilateral triangle whose sides have lengths 2, 2 and 2.\n\n* * *"}, {"input": "3 4 5", "output": "No\n \n\n * There is no equilateral triangle whose sides have lengths 3, 4 and 5."}] |
If there exists an equilateral triangle whose sides have lengths A, B and C,
print `Yes`; otherwise, print `No`.
* * * | s690400989 | Wrong Answer | p03079 | Input is given from Standard Input in the following format:
A B C | length = list(map(int, input().split()))
if length[0] == length[1] and length[1] == length[2]:
print(True)
else:
print(False)
| Statement
You are given three integers A, B and C.
Determine if there exists an equilateral triangle whose sides have lengths A,
B and C. | [{"input": "2 2 2", "output": "Yes\n \n\n * There exists an equilateral triangle whose sides have lengths 2, 2 and 2.\n\n* * *"}, {"input": "3 4 5", "output": "No\n \n\n * There is no equilateral triangle whose sides have lengths 3, 4 and 5."}] |
If it is impossible to place all the tiles, print `NO`. Otherwise, print the
following:
YES
c_{11}...c_{1M}
:
c_{N1}...c_{NM}
Here, c_{ij} must be one of the following characters: `.`, `<`, `>`, `^` and
`v`. Represent an arrangement by using each of these characters as follows:
* When c_{ij} is `.`, it indicates that the square at the i-th row and j-th column is empty;
* When c_{ij} is `<`, it indicates that the square at the i-th row and j-th column is covered by the left half of a 1 \times 2 tile;
* When c_{ij} is `>`, it indicates that the square at the i-th row and j-th column is covered by the right half of a 1 \times 2 tile;
* When c_{ij} is `^`, it indicates that the square at the i-th row and j-th column is covered by the top half of a 2 \times 1 tile;
* When c_{ij} is `v`, it indicates that the square at the i-th row and j-th column is covered by the bottom half of a 2 \times 1 tile.
* * * | s827027315 | Wrong Answer | p03429 | Input is given from Standard Input in the following format:
N M A B | import sys
input = sys.stdin.readline
import numpy as np
N, M, A, B = map(int, input().split())
def solve(N, M, A, B):
grid = np.full((N, M), ".", dtype="U1")
put_row = np.full((N, M - 1), 10**9, dtype=np.int32)
if N % 2 == 0:
for n in range(0, M // 2):
put_row[:, n + n] = np.arange(N * n, N * (n + 1))
elif M % 2 == 0:
# N-1行目を埋めたあと、2個ずつ
put_row[-1, ::2] = np.arange(M // 2)
x = M // 2
for n in range(M // 2):
put_row[:-1, n + n] = np.arange(x, x + N - 1)
x += N - 1
else:
# N-1行目を右優先で埋めたあと、左上から
put_row[-1, 1::2] = np.arange(M // 2)
x = M // 2
for n in range(M // 2):
put_row[:-1, n + n] = np.arange(x, x + N - 1)
x += N - 1
# 置くべき優先度を定義し終わった
x, y = np.where(put_row < A)
if len(x) != A:
print("NO")
return
grid[x, y] = "<"
grid[x, y + 1] = ">"
# 空きます
put_col = grid == "."
# 下も空いている(上側としておける)
put_col[:-1] &= put_col[1:]
put_col[-1] = 0
for n in range(1, N):
# ひとつ上から置けるならやめる
put_col[n] &= ~put_col[n - 1]
x, y = np.where(put_col)
x = x[:B]
y = y[:B]
if len(x) != B:
print("NO")
return
grid[x, y] = "^"
grid[x + 1, y] = "v"
print("YES")
print("\n".join("".join(row) for row in grid))
return
solve(N, M, A, B)
| Statement
Takahashi has an N \times M grid, with N horizontal rows and M vertical
columns. Determine if we can place A 1 \times 2 tiles (1 vertical, 2
horizontal) and B 2 \times 1 tiles (2 vertical, 1 horizontal) satisfying the
following conditions, and construct one arrangement of the tiles if it is
possible:
* All the tiles must be placed on the grid.
* Tiles must not stick out of the grid, and no two different tiles may intersect.
* Neither the grid nor the tiles may be rotated.
* Every tile completely covers exactly two squares. | [{"input": "3 4 4 2", "output": "YES\n <><>\n ^<>^\n v<>v\n \n\nThis is one example of a way to place four 1 \\times 2 tiles and three 2 \\times\n1 tiles on a 3 \\times 4 grid.\n\n* * *"}, {"input": "4 5 5 3", "output": "YES\n <>..^\n ^.<>v\n v<>.^\n <><>v\n \n\n* * *"}, {"input": "7 9 20 20", "output": "NO"}] |
Print "Yes" or "No" in a line. | s284358055 | Wrong Answer | p02392 | Three integers a, b and c separated by a single space are given in a line. | print((lambda a, b, c: a > b > c)(*map(int, input().split())))
| Range
Write a program which reads three integers a, b and c, and prints "Yes" if a <
b < c, otherwise "No". | [{"input": "1 3 8", "output": "Yes"}, {"input": "3 8 1", "output": "No"}] |
Print "Yes" or "No" in a line. | s779152276 | Accepted | p02392 | Three integers a, b and c separated by a single space are given in a line. | input_line = list(input().split())
print(
"Yes" if input_line[0] < input_line[1] and input_line[1] < input_line[2] else "No"
)
| Range
Write a program which reads three integers a, b and c, and prints "Yes" if a <
b < c, otherwise "No". | [{"input": "1 3 8", "output": "Yes"}, {"input": "3 8 1", "output": "No"}] |
Print "Yes" or "No" in a line. | s635523227 | Wrong Answer | p02392 | Three integers a, b and c separated by a single space are given in a line. | A = map(int, input().split())
set_A = set(A)
print(sorted(set_A))
| Range
Write a program which reads three integers a, b and c, and prints "Yes" if a <
b < c, otherwise "No". | [{"input": "1 3 8", "output": "Yes"}, {"input": "3 8 1", "output": "No"}] |
Print "Yes" or "No" in a line. | s982373851 | Runtime Error | p02392 | Three integers a, b and c separated by a single space are given in a line. | a, b, c = int(input().split())
| Range
Write a program which reads three integers a, b and c, and prints "Yes" if a <
b < c, otherwise "No". | [{"input": "1 3 8", "output": "Yes"}, {"input": "3 8 1", "output": "No"}] |
Print the number, modulo (10^9 + 7), of sequences with the property: if used
in the game, there is always a way for Takahashi to sort the sequence in
ascending order regardless of Snuke's operations.
* * * | s806075687 | Wrong Answer | p02668 | Input is given from Standard Input in the following format:
N M | input()
print(1)
| Statement
Takahashi and Snuke came up with a game that uses a number sequence, as
follows:
* Prepare a sequence of length M consisting of integers between 0 and 2^N-1 (inclusive): a = a_1, a_2, \ldots, a_M.
* Snuke first does the operation below as many times as he likes:
* Choose a positive integer d, and for each i (1 \leq i \leq M), in binary, set the d-th least significant bit of a_i to 0. (Here the least significant bit is considered the 1-st least significant bit.)
* After Snuke finishes doing operations, Takahashi tries to sort a in ascending order by doing the operation below some number of times. Here a is said to be in ascending order when a_i \leq a_{i + 1} for all i (1 \leq i \leq M - 1).
* Choose two adjacent elements of a: a_i and a_{i + 1}. If, in binary, these numbers differ in exactly one bit, swap a_i and a_{i + 1}.
There are 2^{NM} different sequences of length M consisting of integers
between 0 and 2^N-1 that can be used in the game.
How many among them have the following property: if used in the game, there is
always a way for Takahashi to sort the sequence in ascending order regardless
of Snuke's operations? Find the count modulo (10^9 + 7). | [{"input": "2 5", "output": "352\n \n\nConsider the case a = 1, 3, 1, 3, 1 for example.\n\n * When the least significant bit of each element of a is set to 0, a = 0, 2, 0, 2, 0;\n * When the second least significant bit of each element of a is set to 0, a = 1, 1, 1, 1, 1;\n * When the least two significant bits of each element of a are set to 0, a = 0, 0, 0, 0, 0.\n\nIn all of the cases above and the case when Snuke does no operation to change\na, we can sort the sequence by repeatedly swapping adjacent elements that\ndiffer in exactly one bit. Thus, this sequence has the property: if used in\nthe game, there is always a way for Takahashi to sort the sequence in\nascending order regardless of Snuke's operations.\n\n* * *"}, {"input": "2020 530", "output": "823277409"}] |
Print the number, modulo (10^9 + 7), of sequences with the property: if used
in the game, there is always a way for Takahashi to sort the sequence in
ascending order regardless of Snuke's operations.
* * * | s269548620 | Runtime Error | p02668 | Input is given from Standard Input in the following format:
N M | import itertools
N = int(input())
A = [int(_) for _ in input().split()]
if A[0] != 0:
if N == 0 and A[0] == 1:
print(1)
else:
print(-1)
exit()
ans = 1
n = 1
if A[0] > 1:
print(-1)
exit()
cumr = list(itertools.accumulate(A[::-1]))[::-1]
for i in range(1, N + 1):
n = min(2 * (n - A[i - 1]), cumr[i])
ans += n
if n < 0:
print(-1)
exit()
print(ans)
| Statement
Takahashi and Snuke came up with a game that uses a number sequence, as
follows:
* Prepare a sequence of length M consisting of integers between 0 and 2^N-1 (inclusive): a = a_1, a_2, \ldots, a_M.
* Snuke first does the operation below as many times as he likes:
* Choose a positive integer d, and for each i (1 \leq i \leq M), in binary, set the d-th least significant bit of a_i to 0. (Here the least significant bit is considered the 1-st least significant bit.)
* After Snuke finishes doing operations, Takahashi tries to sort a in ascending order by doing the operation below some number of times. Here a is said to be in ascending order when a_i \leq a_{i + 1} for all i (1 \leq i \leq M - 1).
* Choose two adjacent elements of a: a_i and a_{i + 1}. If, in binary, these numbers differ in exactly one bit, swap a_i and a_{i + 1}.
There are 2^{NM} different sequences of length M consisting of integers
between 0 and 2^N-1 that can be used in the game.
How many among them have the following property: if used in the game, there is
always a way for Takahashi to sort the sequence in ascending order regardless
of Snuke's operations? Find the count modulo (10^9 + 7). | [{"input": "2 5", "output": "352\n \n\nConsider the case a = 1, 3, 1, 3, 1 for example.\n\n * When the least significant bit of each element of a is set to 0, a = 0, 2, 0, 2, 0;\n * When the second least significant bit of each element of a is set to 0, a = 1, 1, 1, 1, 1;\n * When the least two significant bits of each element of a are set to 0, a = 0, 0, 0, 0, 0.\n\nIn all of the cases above and the case when Snuke does no operation to change\na, we can sort the sequence by repeatedly swapping adjacent elements that\ndiffer in exactly one bit. Thus, this sequence has the property: if used in\nthe game, there is always a way for Takahashi to sort the sequence in\nascending order regardless of Snuke's operations.\n\n* * *"}, {"input": "2020 530", "output": "823277409"}] |
Print the number, modulo (10^9 + 7), of sequences with the property: if used
in the game, there is always a way for Takahashi to sort the sequence in
ascending order regardless of Snuke's operations.
* * * | s490111833 | Wrong Answer | p02668 | Input is given from Standard Input in the following format:
N M | class comb:
F = [1, 1]
Fi = [1, 1]
I = [0, 1]
def __init__(self, num, mod):
self.MOD = mod
for i in range(2, num + 1):
self.F.append((self.F[-1] * i) % mod)
self.I.append(mod - self.I[mod % i] * (mod // i) % mod)
self.Fi.append(self.Fi[-1] * self.I[i] % mod)
def com(self, n, k):
if n < k:
return 0
if n < 0 or k < 0:
return 0
return self.F[n] * (self.Fi[k] * self.Fi[n - k] % self.MOD) % self.MOD
M, N = list(map(int, input().split()))
MOD = 10**9 + 7
DP = [[[0] * 2 for i in range(M + 1)] for _ in range(N)]
com = comb(M + 1, MOD)
L = [0] * (M + 1)
for i in range(M + 1):
L[i] = com.com(M, i)
for i in range(M + 1):
DP[0][i][0] = 1
for i in range(1, N):
for j in range(M + 1):
if j != 0:
DP[i][j][0] += (DP[i - 1][j - 1][0] + DP[i - 1][j - 1][1]) * L[j - 1] % MOD
DP[i][j][0] += DP[i - 1][j][0] * L[j] % MOD
DP[i][j][0] %= MOD
if j != M:
DP[i][j][1] += (DP[i - 1][j + 1][0]) * L[j + 1] % MOD
DP[i][j][1] += DP[i - 1][j][1] * L[j] % MOD
ans = 0
for i in range(M + 1):
ans = (ans + DP[-1][i][0] + DP[-1][i][1]) % MOD
print(ans)
| Statement
Takahashi and Snuke came up with a game that uses a number sequence, as
follows:
* Prepare a sequence of length M consisting of integers between 0 and 2^N-1 (inclusive): a = a_1, a_2, \ldots, a_M.
* Snuke first does the operation below as many times as he likes:
* Choose a positive integer d, and for each i (1 \leq i \leq M), in binary, set the d-th least significant bit of a_i to 0. (Here the least significant bit is considered the 1-st least significant bit.)
* After Snuke finishes doing operations, Takahashi tries to sort a in ascending order by doing the operation below some number of times. Here a is said to be in ascending order when a_i \leq a_{i + 1} for all i (1 \leq i \leq M - 1).
* Choose two adjacent elements of a: a_i and a_{i + 1}. If, in binary, these numbers differ in exactly one bit, swap a_i and a_{i + 1}.
There are 2^{NM} different sequences of length M consisting of integers
between 0 and 2^N-1 that can be used in the game.
How many among them have the following property: if used in the game, there is
always a way for Takahashi to sort the sequence in ascending order regardless
of Snuke's operations? Find the count modulo (10^9 + 7). | [{"input": "2 5", "output": "352\n \n\nConsider the case a = 1, 3, 1, 3, 1 for example.\n\n * When the least significant bit of each element of a is set to 0, a = 0, 2, 0, 2, 0;\n * When the second least significant bit of each element of a is set to 0, a = 1, 1, 1, 1, 1;\n * When the least two significant bits of each element of a are set to 0, a = 0, 0, 0, 0, 0.\n\nIn all of the cases above and the case when Snuke does no operation to change\na, we can sort the sequence by repeatedly swapping adjacent elements that\ndiffer in exactly one bit. Thus, this sequence has the property: if used in\nthe game, there is always a way for Takahashi to sort the sequence in\nascending order regardless of Snuke's operations.\n\n* * *"}, {"input": "2020 530", "output": "823277409"}] |
For each vertex, print $id$, $d$ and $f$ separated by a space character in a
line. $id$ is ID of the vertex, $d$ and $f$ is the discover time and the
finish time respectively. Print in order of vertex IDs. | s585573243 | Accepted | p02238 | In the first line, an integer $n$ denoting the number of vertices of $G$ is
given. In the next $n$ lines, adjacency lists of $u$ are given in the
following format:
$u$ $k$ $v_1$ $v_2$ ... $v_k$
$u$ is ID of the vertex and $k$ denotes its degree. $v_i$ are IDs of vertices
adjacent to $u$. |
def dfs(node_id):
global current_time #書かないとローカル変数扱いされる
go_time[node_id] = current_time
current_time += 1
for next_node in G[node_id]:
if visited[next_node] == True:
continue
visited[next_node] = True
dfs(next_node)
back_time[node_id] = current_time
current_time += 1
V = int(input())
G = [[] for i in range(V)]
visited = [False]*V
go_time = [0]*V
back_time = [0]*V
for loop in range(V):
node_id,num,*tmp_adj = list(map(int,input().split()))
node_id -= 1
for i in range(num):
G[node_id].append(tmp_adj[i]-1)
current_time = 1
for i in range(V):
if visited[i] == True:
continue
visited[i] = True
dfs(i)
for i in range(V):
print("%d %d %d"%(i+1,go_time[i],back_time[i]))
| Depth First Search
Depth-first search (DFS) follows the strategy to search ”deeper” in the graph
whenever possible. In DFS, edges are recursively explored out of the most
recently discovered vertex $v$ that still has unexplored edges leaving it.
When all of $v$'s edges have been explored, the search ”backtracks” to explore
edges leaving the vertex from which $v$ was discovered.
This process continues until all the vertices that are reachable from the
original source vertex have been discovered. If any undiscovered vertices
remain, then one of them is selected as a new source and the search is
repeated from that source.
DFS timestamps each vertex as follows:
* $d[v]$ records when $v$ is first discovered.
* $f[v]$ records when the search finishes examining $v$’s adjacency list.
Write a program which reads a directed graph $G = (V, E)$ and demonstrates DFS
on the graph based on the following rules:
* $G$ is given in an adjacency-list. Vertices are identified by IDs $1, 2,... n$ respectively.
* IDs in the adjacency list are arranged in ascending order.
* The program should report the discover time and the finish time for each vertex.
* When there are several candidates to visit during DFS, the algorithm should select the vertex with the smallest ID.
* The timestamp starts with 1. | [{"input": "4\n 1 1 2\n 2 1 4\n 3 0\n 4 1 3", "output": "1 1 8\n 2 2 7\n 3 4 5\n 4 3 6"}, {"input": "6\n 1 2 2 3\n 2 2 3 4\n 3 1 5\n 4 1 6\n 5 1 6\n 6 0", "output": "1 1 12\n 2 2 11\n 3 3 8\n 4 9 10\n 5 4 7\n 6 5 6\n \n\n\n\nThis is example for Sample Input 2 (discover/finish)"}] |
For each vertex, print $id$, $d$ and $f$ separated by a space character in a
line. $id$ is ID of the vertex, $d$ and $f$ is the discover time and the
finish time respectively. Print in order of vertex IDs. | s138985555 | Wrong Answer | p02238 | In the first line, an integer $n$ denoting the number of vertices of $G$ is
given. In the next $n$ lines, adjacency lists of $u$ are given in the
following format:
$u$ $k$ $v_1$ $v_2$ ... $v_k$
$u$ is ID of the vertex and $k$ denotes its degree. $v_i$ are IDs of vertices
adjacent to $u$. | def DPS(graph,vertex,dis_time,fin_time,tmp_time):
dis_time[vertex]=tmp_time[0]
for i in range(len(graph[0])):
if(graph[vertex][i] !=0 and dis_time[i]==0):#枝先の頂点が探索済みでなかったら、
tmp_time[0]+=1
DPS(graph,i,dis_time,fin_time,tmp_time)
if(dis_time[vertex]==tmp_time[0]):#vertexから、どの頂点に対しても調査が進まなかったら
tmp_time[0]+=1
fin_time[vertex]=tmp_time[0]
tmp_time[0]+=1
#グラフの作成
n=int(input())
graph=[[0]*n for loop in range(n)]
for loop in range(n):
tmp_ope=list(map(int,input().split()))
for j in range(tmp_ope[1]):
graph[tmp_ope[0]-1][tmp_ope[j+2]-1]=1
dis_time=[0]*n
fin_time=[0]*n
tmp_time=[1]
for i in range(n):
if(dis_time[i]==0):
DPS(graph,i,dis_time,fin_time,tmp_time)
for i in range(n):
print(f"{i+1} {dis_time[i]} {fin_time[i]}")
| Depth First Search
Depth-first search (DFS) follows the strategy to search ”deeper” in the graph
whenever possible. In DFS, edges are recursively explored out of the most
recently discovered vertex $v$ that still has unexplored edges leaving it.
When all of $v$'s edges have been explored, the search ”backtracks” to explore
edges leaving the vertex from which $v$ was discovered.
This process continues until all the vertices that are reachable from the
original source vertex have been discovered. If any undiscovered vertices
remain, then one of them is selected as a new source and the search is
repeated from that source.
DFS timestamps each vertex as follows:
* $d[v]$ records when $v$ is first discovered.
* $f[v]$ records when the search finishes examining $v$’s adjacency list.
Write a program which reads a directed graph $G = (V, E)$ and demonstrates DFS
on the graph based on the following rules:
* $G$ is given in an adjacency-list. Vertices are identified by IDs $1, 2,... n$ respectively.
* IDs in the adjacency list are arranged in ascending order.
* The program should report the discover time and the finish time for each vertex.
* When there are several candidates to visit during DFS, the algorithm should select the vertex with the smallest ID.
* The timestamp starts with 1. | [{"input": "4\n 1 1 2\n 2 1 4\n 3 0\n 4 1 3", "output": "1 1 8\n 2 2 7\n 3 4 5\n 4 3 6"}, {"input": "6\n 1 2 2 3\n 2 2 3 4\n 3 1 5\n 4 1 6\n 5 1 6\n 6 0", "output": "1 1 12\n 2 2 11\n 3 3 8\n 4 9 10\n 5 4 7\n 6 5 6\n \n\n\n\nThis is example for Sample Input 2 (discover/finish)"}] |
For each vertex, print $id$, $d$ and $f$ separated by a space character in a
line. $id$ is ID of the vertex, $d$ and $f$ is the discover time and the
finish time respectively. Print in order of vertex IDs. | s268709699 | Wrong Answer | p02238 | In the first line, an integer $n$ denoting the number of vertices of $G$ is
given. In the next $n$ lines, adjacency lists of $u$ are given in the
following format:
$u$ $k$ $v_1$ $v_2$ ... $v_k$
$u$ is ID of the vertex and $k$ denotes its degree. $v_i$ are IDs of vertices
adjacent to $u$. | import abc
class AdjacentGraph:
"""Implementation adjacency-list Graph.
Beware ids are between 1 and size.
"""
def __init__(self, size):
self.size = size
self._nodes = [[0] * (size + 1) for _ in range(size + 1)]
def set_adj_node(self, id_, adj_id):
self._nodes[id_][adj_id] = 1
def __iter__(self):
self._id = 0
return self
def __next__(self):
if self._id < self.size:
self._id += 1
return (self._id, self._nodes[self._id][1:])
raise StopIteration()
def dfs(self, handler=None):
stack = [(1, 0)]
visited = []
while len(stack) > 0:
i, j = stack.pop()
if j == 0:
if handler:
handler.visit(i)
visited.append(i)
yield i
try:
j = self._nodes[i].index(1, j + 1)
stack.append((i, j))
if j not in visited:
stack.append((j, 0))
except ValueError:
if handler:
handler.leave(i)
class EventHandler(abc.ABC):
@abc.abstractmethod
def visit(self, i):
pass
@abc.abstractmethod
def leave(self, i):
pass
class Logger(EventHandler):
def __init__(self, n):
self.log = [(0, 0)] * n
self.step = 0
def visit(self, i):
self.step += 1
self.log[i - 1] = (self.step, 0)
def leave(self, i):
self.step += 1
(n, m) = self.log[i - 1]
self.log[i - 1] = (n, self.step)
def by_node(self):
i = 1
for discover, finish in self.log:
yield (i, discover, finish)
i += 1
def run():
n = int(input())
g = AdjacentGraph(n)
log = Logger(n)
for i in range(n):
id_, c, *links = [int(x) for x in input().split()]
for n in links:
g.set_adj_node(id_, n)
for i in g.dfs(log):
pass
for node in log.by_node():
print(" ".join([str(i) for i in node]))
if __name__ == "__main__":
run()
| Depth First Search
Depth-first search (DFS) follows the strategy to search ”deeper” in the graph
whenever possible. In DFS, edges are recursively explored out of the most
recently discovered vertex $v$ that still has unexplored edges leaving it.
When all of $v$'s edges have been explored, the search ”backtracks” to explore
edges leaving the vertex from which $v$ was discovered.
This process continues until all the vertices that are reachable from the
original source vertex have been discovered. If any undiscovered vertices
remain, then one of them is selected as a new source and the search is
repeated from that source.
DFS timestamps each vertex as follows:
* $d[v]$ records when $v$ is first discovered.
* $f[v]$ records when the search finishes examining $v$’s adjacency list.
Write a program which reads a directed graph $G = (V, E)$ and demonstrates DFS
on the graph based on the following rules:
* $G$ is given in an adjacency-list. Vertices are identified by IDs $1, 2,... n$ respectively.
* IDs in the adjacency list are arranged in ascending order.
* The program should report the discover time and the finish time for each vertex.
* When there are several candidates to visit during DFS, the algorithm should select the vertex with the smallest ID.
* The timestamp starts with 1. | [{"input": "4\n 1 1 2\n 2 1 4\n 3 0\n 4 1 3", "output": "1 1 8\n 2 2 7\n 3 4 5\n 4 3 6"}, {"input": "6\n 1 2 2 3\n 2 2 3 4\n 3 1 5\n 4 1 6\n 5 1 6\n 6 0", "output": "1 1 12\n 2 2 11\n 3 3 8\n 4 9 10\n 5 4 7\n 6 5 6\n \n\n\n\nThis is example for Sample Input 2 (discover/finish)"}] |
For each vertex, print $id$, $d$ and $f$ separated by a space character in a
line. $id$ is ID of the vertex, $d$ and $f$ is the discover time and the
finish time respectively. Print in order of vertex IDs. | s691265963 | Accepted | p02238 | In the first line, an integer $n$ denoting the number of vertices of $G$ is
given. In the next $n$ lines, adjacency lists of $u$ are given in the
following format:
$u$ $k$ $v_1$ $v_2$ ... $v_k$
$u$ is ID of the vertex and $k$ denotes its degree. $v_i$ are IDs of vertices
adjacent to $u$. | def dfs(v, k):
if ans[v][1] == 0:
ans[v][1] = k
else:
return k - 1
for i in d[v]:
k = dfs(i, k + 1)
k += 1
if ans[v][2] == 0:
ans[v][2] = k
return k
G = int(input())
vlst = [list(map(int, input().split())) for _ in range(G)]
d = [[] for _ in range(G)]
for i in range(G):
for j in range(vlst[i][1]):
d[i].append(vlst[i][2 + j] - 1)
ans = [[_, 0, 0] for _ in range(G)]
k = 1
for i in range(G):
k = dfs(i, k) + 1
for i in ans:
print(i[0] + 1, i[1], i[2])
| Depth First Search
Depth-first search (DFS) follows the strategy to search ”deeper” in the graph
whenever possible. In DFS, edges are recursively explored out of the most
recently discovered vertex $v$ that still has unexplored edges leaving it.
When all of $v$'s edges have been explored, the search ”backtracks” to explore
edges leaving the vertex from which $v$ was discovered.
This process continues until all the vertices that are reachable from the
original source vertex have been discovered. If any undiscovered vertices
remain, then one of them is selected as a new source and the search is
repeated from that source.
DFS timestamps each vertex as follows:
* $d[v]$ records when $v$ is first discovered.
* $f[v]$ records when the search finishes examining $v$’s adjacency list.
Write a program which reads a directed graph $G = (V, E)$ and demonstrates DFS
on the graph based on the following rules:
* $G$ is given in an adjacency-list. Vertices are identified by IDs $1, 2,... n$ respectively.
* IDs in the adjacency list are arranged in ascending order.
* The program should report the discover time and the finish time for each vertex.
* When there are several candidates to visit during DFS, the algorithm should select the vertex with the smallest ID.
* The timestamp starts with 1. | [{"input": "4\n 1 1 2\n 2 1 4\n 3 0\n 4 1 3", "output": "1 1 8\n 2 2 7\n 3 4 5\n 4 3 6"}, {"input": "6\n 1 2 2 3\n 2 2 3 4\n 3 1 5\n 4 1 6\n 5 1 6\n 6 0", "output": "1 1 12\n 2 2 11\n 3 3 8\n 4 9 10\n 5 4 7\n 6 5 6\n \n\n\n\nThis is example for Sample Input 2 (discover/finish)"}] |
For each vertex, print $id$, $d$ and $f$ separated by a space character in a
line. $id$ is ID of the vertex, $d$ and $f$ is the discover time and the
finish time respectively. Print in order of vertex IDs. | s113220048 | Accepted | p02238 | In the first line, an integer $n$ denoting the number of vertices of $G$ is
given. In the next $n$ lines, adjacency lists of $u$ are given in the
following format:
$u$ $k$ $v_1$ $v_2$ ... $v_k$
$u$ is ID of the vertex and $k$ denotes its degree. $v_i$ are IDs of vertices
adjacent to $u$. | class Node:
def __init__(self, v):
self.d = 0
self.f = 0
self.v = v
def __repr__(self):
return "Node({},{},{})".format(self.d, self.f, self.v)
def read_node():
n = int(input())
adj_list = [[] for _ in range(n + 1)]
for _ in range(n):
id, _, *v = [int(x) for x in input().split()]
adj_list[id] = Node(v)
return adj_list
def depth_first_search(adj_list):
def dfs(id):
nonlocal adj_list, timestamp
adj_list[id].d = timestamp
for adj_id in adj_list[id].v:
if adj_list[adj_id].d == 0:
timestamp += 1
dfs(adj_id)
timestamp += 1
adj_list[id].f = timestamp
timestamp = 1
for id in range(1, len(adj_list)):
if adj_list[id].d == 0:
dfs(id)
timestamp += 1
def print_result(adj_list):
for id in range(1, len(adj_list)):
print(id, adj_list[id].d, adj_list[id].f)
def main():
adj_list = read_node()
depth_first_search(adj_list)
print_result(adj_list)
if __name__ == "__main__":
main()
| Depth First Search
Depth-first search (DFS) follows the strategy to search ”deeper” in the graph
whenever possible. In DFS, edges are recursively explored out of the most
recently discovered vertex $v$ that still has unexplored edges leaving it.
When all of $v$'s edges have been explored, the search ”backtracks” to explore
edges leaving the vertex from which $v$ was discovered.
This process continues until all the vertices that are reachable from the
original source vertex have been discovered. If any undiscovered vertices
remain, then one of them is selected as a new source and the search is
repeated from that source.
DFS timestamps each vertex as follows:
* $d[v]$ records when $v$ is first discovered.
* $f[v]$ records when the search finishes examining $v$’s adjacency list.
Write a program which reads a directed graph $G = (V, E)$ and demonstrates DFS
on the graph based on the following rules:
* $G$ is given in an adjacency-list. Vertices are identified by IDs $1, 2,... n$ respectively.
* IDs in the adjacency list are arranged in ascending order.
* The program should report the discover time and the finish time for each vertex.
* When there are several candidates to visit during DFS, the algorithm should select the vertex with the smallest ID.
* The timestamp starts with 1. | [{"input": "4\n 1 1 2\n 2 1 4\n 3 0\n 4 1 3", "output": "1 1 8\n 2 2 7\n 3 4 5\n 4 3 6"}, {"input": "6\n 1 2 2 3\n 2 2 3 4\n 3 1 5\n 4 1 6\n 5 1 6\n 6 0", "output": "1 1 12\n 2 2 11\n 3 3 8\n 4 9 10\n 5 4 7\n 6 5 6\n \n\n\n\nThis is example for Sample Input 2 (discover/finish)"}] |
For each vertex, print $id$, $d$ and $f$ separated by a space character in a
line. $id$ is ID of the vertex, $d$ and $f$ is the discover time and the
finish time respectively. Print in order of vertex IDs. | s132902986 | Wrong Answer | p02238 | In the first line, an integer $n$ denoting the number of vertices of $G$ is
given. In the next $n$ lines, adjacency lists of $u$ are given in the
following format:
$u$ $k$ $v_1$ $v_2$ ... $v_k$
$u$ is ID of the vertex and $k$ denotes its degree. $v_i$ are IDs of vertices
adjacent to $u$. | import sys
u = []
k = []
v = []
time = 0
n = int(sys.stdin.readline().strip())
yattayatu = [False for i in range(n)]
s = [0 for i in range(n)]
f = [0 for i in range(n)]
for i in range(n):
inp = sys.stdin.readline().strip().split(" ")
inp = list(map(lambda x: int(x), inp))
u.append(inp[0])
k.append(inp[1])
v.append(inp[2:])
def func(nodeid):
global time
if yattayatu[nodeid - 1] == True:
return
time += 1
s[nodeid - 1] = time
for i in range(k[nodeid - 1]):
func(v[nodeid - 1][i])
time += 1
f[nodeid - 1] = time
yattayatu[nodeid - 1] = True
func(1)
for i in range(n):
print(str(i + 1) + " " + str(s[i]) + " " + str(f[i]))
| Depth First Search
Depth-first search (DFS) follows the strategy to search ”deeper” in the graph
whenever possible. In DFS, edges are recursively explored out of the most
recently discovered vertex $v$ that still has unexplored edges leaving it.
When all of $v$'s edges have been explored, the search ”backtracks” to explore
edges leaving the vertex from which $v$ was discovered.
This process continues until all the vertices that are reachable from the
original source vertex have been discovered. If any undiscovered vertices
remain, then one of them is selected as a new source and the search is
repeated from that source.
DFS timestamps each vertex as follows:
* $d[v]$ records when $v$ is first discovered.
* $f[v]$ records when the search finishes examining $v$’s adjacency list.
Write a program which reads a directed graph $G = (V, E)$ and demonstrates DFS
on the graph based on the following rules:
* $G$ is given in an adjacency-list. Vertices are identified by IDs $1, 2,... n$ respectively.
* IDs in the adjacency list are arranged in ascending order.
* The program should report the discover time and the finish time for each vertex.
* When there are several candidates to visit during DFS, the algorithm should select the vertex with the smallest ID.
* The timestamp starts with 1. | [{"input": "4\n 1 1 2\n 2 1 4\n 3 0\n 4 1 3", "output": "1 1 8\n 2 2 7\n 3 4 5\n 4 3 6"}, {"input": "6\n 1 2 2 3\n 2 2 3 4\n 3 1 5\n 4 1 6\n 5 1 6\n 6 0", "output": "1 1 12\n 2 2 11\n 3 3 8\n 4 9 10\n 5 4 7\n 6 5 6\n \n\n\n\nThis is example for Sample Input 2 (discover/finish)"}] |
For each vertex, print $id$, $d$ and $f$ separated by a space character in a
line. $id$ is ID of the vertex, $d$ and $f$ is the discover time and the
finish time respectively. Print in order of vertex IDs. | s054347731 | Accepted | p02238 | In the first line, an integer $n$ denoting the number of vertices of $G$ is
given. In the next $n$ lines, adjacency lists of $u$ are given in the
following format:
$u$ $k$ $v_1$ $v_2$ ... $v_k$
$u$ is ID of the vertex and $k$ denotes its degree. $v_i$ are IDs of vertices
adjacent to $u$. | # http://judge.u-aizu.ac.jp/onlinejudge/review.jsp?rid=4647653#1
import sys
sys.setrecursionlimit(10**8)
input = sys.stdin.readline
class Graph:
def __init__(self, n, dictated=False, decrement=True, edge=[]):
self.n = n
self.dictated = dictated
self.decrement = decrement
self.edge = [set() for _ in range(self.n)]
self.parent = [-1] * self.n
self.info = [-1] * self.n
for x, y in edge:
self.add_edge(x, y)
def add_edge(self, x, y):
if self.decrement:
x -= 1
y -= 1
self.edge[x].add(y)
if self.dictated == False:
self.edge[y].add(x)
def add_adjacent_list(self, i, adjacent_list):
if self.decrement:
self.edge[i] = set(map(lambda x: x - 1, adjacent_list))
else:
self.edge[i] = set(adjacent_list)
def path_detector(self, start=0, time=0):
"""
:param p: スタート地点
:return: 各点までの距離と何番目に発見したかを返す
"""
edge2 = []
for i in range(self.n):
edge2.append(sorted(self.edge[i], reverse=True))
p, t = start, time
self.parent[p] = -2
full_path = [(p + self.decrement, t)]
while True:
if edge2[p]:
q = edge2[p].pop()
if q == self.parent[p] and not self.dictated:
"""逆流した時の処理"""
"""""" """""" """""" ""
continue
if self.parent[q] != -1:
"""サイクルで同一点を訪れた時の処理"""
"""""" """""" """""" ""
continue
self.parent[q] = p
p, t = q, t + 1
full_path.append((p + self.decrement, t))
else:
"""探索完了時の処理"""
full_path.append((p + self.decrement, t))
"""""" """""" """""" ""
if p == start and t == time:
break
p, t = self.parent[p], t - 1
""" 二度目に訪問時の処理 """
"""""" """""" """""" ""
return full_path
def path_list(self):
"""
:return: 探索経路を返す。
"""
self.parent = [-1] * self.n
res = []
for p in range(self.n):
if self.parent[p] == -1:
res.append(self.path_detector(start=p, time=1))
return res
def draw(self):
"""
:return: グラフを可視化
"""
import matplotlib.pyplot as plt
import networkx as nx
if self.dictated:
G = nx.DiGraph()
else:
G = nx.Graph()
for x in range(self.n):
for y in self.edge[x]:
G.add_edge(x + self.decrement, y + self.decrement)
nx.draw_networkx(G)
plt.show()
def make_graph(dictated=False, decrement=True):
"""
自己ループの無いグラフを生成。N>=2
:param dictated: True = 有効グラフ
:param decrement: True = 1-indexed
:return:
"""
import random
N = random.randint(2, 5)
if N > 2:
M_max = (3 * N - 6) * (1 + dictated)
else:
M_max = 1
graph = Graph(N, dictated, decrement)
for _ in range(random.randint(0, M_max)):
graph.add_edge(*random.sample(range(decrement, N + decrement), 2))
return graph
##################################################################
# 入力が隣接リストの場合
##################################################################
N = int(input()) # 頂点数
graph = Graph(N, dictated=True, decrement=True)
for i in range(
N
): # [[頂点1と連結している頂点の集合], [頂点2と連結している頂点の集合],...]
points = list(map(int, input().split()))[2:]
graph.add_adjacent_list(i, points)
data = graph.path_list()
from itertools import chain
data = list(chain.from_iterable(data))
res = [[i + 1, 0, 0] for i in range(N)]
for time, a in enumerate(data, start=1):
i = a[0] - 1
if res[i][1]:
res[i][2] = time
else:
res[i][1] = time
for a in res:
print(*a)
| Depth First Search
Depth-first search (DFS) follows the strategy to search ”deeper” in the graph
whenever possible. In DFS, edges are recursively explored out of the most
recently discovered vertex $v$ that still has unexplored edges leaving it.
When all of $v$'s edges have been explored, the search ”backtracks” to explore
edges leaving the vertex from which $v$ was discovered.
This process continues until all the vertices that are reachable from the
original source vertex have been discovered. If any undiscovered vertices
remain, then one of them is selected as a new source and the search is
repeated from that source.
DFS timestamps each vertex as follows:
* $d[v]$ records when $v$ is first discovered.
* $f[v]$ records when the search finishes examining $v$’s adjacency list.
Write a program which reads a directed graph $G = (V, E)$ and demonstrates DFS
on the graph based on the following rules:
* $G$ is given in an adjacency-list. Vertices are identified by IDs $1, 2,... n$ respectively.
* IDs in the adjacency list are arranged in ascending order.
* The program should report the discover time and the finish time for each vertex.
* When there are several candidates to visit during DFS, the algorithm should select the vertex with the smallest ID.
* The timestamp starts with 1. | [{"input": "4\n 1 1 2\n 2 1 4\n 3 0\n 4 1 3", "output": "1 1 8\n 2 2 7\n 3 4 5\n 4 3 6"}, {"input": "6\n 1 2 2 3\n 2 2 3 4\n 3 1 5\n 4 1 6\n 5 1 6\n 6 0", "output": "1 1 12\n 2 2 11\n 3 3 8\n 4 9 10\n 5 4 7\n 6 5 6\n \n\n\n\nThis is example for Sample Input 2 (discover/finish)"}] |
For each vertex, print $id$, $d$ and $f$ separated by a space character in a
line. $id$ is ID of the vertex, $d$ and $f$ is the discover time and the
finish time respectively. Print in order of vertex IDs. | s254243565 | Wrong Answer | p02238 | In the first line, an integer $n$ denoting the number of vertices of $G$ is
given. In the next $n$ lines, adjacency lists of $u$ are given in the
following format:
$u$ $k$ $v_1$ $v_2$ ... $v_k$
$u$ is ID of the vertex and $k$ denotes its degree. $v_i$ are IDs of vertices
adjacent to $u$. | # ??????????????????????£?????????????deque??????????????????
from collections import deque
class Node:
def __init__(self, no, childs):
self.no = no
self.childs = childs
self.find_time = None
self.finish_time = None
self.visit = False
def get_node_index(nodes, no):
for i in range(len(nodes)):
if nodes[i].no == no:
return i
def get_unvisited(visited, childs):
if childs is None:
return None
for i in range(len(childs)):
if childs[i] not in visited:
return childs[i]
"""
Main??????????????????
"""
# Node??°?????????
N = int(input())
# Node??????????????????????????????
nodes = []
# Node??????????¨????
for i in range(N):
j = list(map(int, input().split())) # ??\??????????§£
no = j[0] # Node??????????????? [2 2 1 4] ->2?????????
childNum = j[1]
if childNum != 0:
childs = j[2:] # ??????????´?????????? [2 2 1 4] ->[1,4]?????????
else:
childs = [] # ??????????´?????????? [2 2 1 4] ->[1,4]?????????
nodes.append(Node(no, childs))
# ??±???????????¢?´¢(DFS)?????????
total_time = 1 # ??¢?´¢??????
stack = deque() # ??¢?´¢???????´?????´?????????????
stack.appendleft(1)
no = get_node_index(nodes, stack[0]) # ?????¨??¢?´¢???????´???????
nodes[no].find_time = total_time
visited = [] # ??¢?´¢??????????´?????´??????????
while stack:
no = get_node_index(nodes, stack[0]) # ?????¨??¢?´¢???????´???????
total_time += 1 # ??¢?´¢??????+1
visited.append(stack[0]) # ??¢?´¢??????????????????????´?
# ?????¢?´¢???????´??????????
unvisited = get_unvisited(visited, nodes[no].childs)
if unvisited is not None:
# ?????¢?´¢???????´??????????????????????????????¢?´¢????´????????????§??????????????????????????????????´???§????????´????????¢?´¢?????\?????????????????????
if nodes[unvisited - 1].visit is False:
nodes[unvisited - 1].visit = True
stack.appendleft(unvisited)
nodes[unvisited - 1].find_time = total_time
else:
stack.popleft()
nodes[no].finish_time = total_time
# ??¨?????????
for i in range(N):
print("{0} {1} {2}".format(nodes[i].no, nodes[i].find_time, nodes[i].finish_time))
| Depth First Search
Depth-first search (DFS) follows the strategy to search ”deeper” in the graph
whenever possible. In DFS, edges are recursively explored out of the most
recently discovered vertex $v$ that still has unexplored edges leaving it.
When all of $v$'s edges have been explored, the search ”backtracks” to explore
edges leaving the vertex from which $v$ was discovered.
This process continues until all the vertices that are reachable from the
original source vertex have been discovered. If any undiscovered vertices
remain, then one of them is selected as a new source and the search is
repeated from that source.
DFS timestamps each vertex as follows:
* $d[v]$ records when $v$ is first discovered.
* $f[v]$ records when the search finishes examining $v$’s adjacency list.
Write a program which reads a directed graph $G = (V, E)$ and demonstrates DFS
on the graph based on the following rules:
* $G$ is given in an adjacency-list. Vertices are identified by IDs $1, 2,... n$ respectively.
* IDs in the adjacency list are arranged in ascending order.
* The program should report the discover time and the finish time for each vertex.
* When there are several candidates to visit during DFS, the algorithm should select the vertex with the smallest ID.
* The timestamp starts with 1. | [{"input": "4\n 1 1 2\n 2 1 4\n 3 0\n 4 1 3", "output": "1 1 8\n 2 2 7\n 3 4 5\n 4 3 6"}, {"input": "6\n 1 2 2 3\n 2 2 3 4\n 3 1 5\n 4 1 6\n 5 1 6\n 6 0", "output": "1 1 12\n 2 2 11\n 3 3 8\n 4 9 10\n 5 4 7\n 6 5 6\n \n\n\n\nThis is example for Sample Input 2 (discover/finish)"}] |
Print the minimum number of explosions that needs to be caused in order to
vanish all the monsters.
* * * | s796173031 | Accepted | p03700 | Input is given from Standard Input in the following format:
N A B
h_1
h_2
:
h_N | # -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from fractions import Fraction
from functools import lru_cache, reduce
from itertools import (
combinations,
combinations_with_replacement,
product,
permutations,
accumulate,
)
from operator import add, mul, sub, itemgetter, attrgetter
import sys
# sys.setrecursionlimit(10**6)
# readline = sys.stdin.buffer.readline
readline = sys.stdin.readline
INF = 2**62 - 1
def read_int():
return int(readline())
def read_int_n():
return list(map(int, readline().split()))
def read_float():
return float(readline())
def read_float_n():
return list(map(float, readline().split()))
def read_str():
return readline().strip()
def read_str_n():
return readline().strip().split()
def ep(*args):
print(*args, file=sys.stderr)
def mt(f):
import time
def wrap(*args, **kwargs):
s = time.perf_counter()
ret = f(*args, **kwargs)
e = time.perf_counter()
ep(e - s, "sec")
return ret
return wrap
class Bisect:
def __init__(self, func):
self.__func = func
def bisect_left(self, x, lo, hi):
while lo < hi:
mid = (lo + hi) // 2
if self.__func(mid) < x:
lo = mid + 1
else:
hi = mid
return lo
def bisect_right(self, x, lo, hi):
while lo < hi:
mid = (lo + hi) // 2
if x < self.__func(mid):
hi = mid
else:
lo = mid + 1
return lo
@mt
def slv(N, A, B, H):
c = A - B
def f(n):
m = n
for h in H:
h -= n * B
if h > 0:
m -= -(-h // c)
return 1 if m >= 0 else 0
return Bisect(f).bisect_left(1, 0, 10**9)
def main():
N, A, B = read_int_n()
H = [read_int() for _ in range(N)]
print(slv(N, A, B, H))
if __name__ == "__main__":
main()
| Statement
You are going out for a walk, when you suddenly encounter N monsters. Each
monster has a parameter called _health_ , and the health of the i-th monster
is h_i at the moment of encounter. A monster will vanish immediately when its
health drops to 0 or below.
Fortunately, you are a skilled magician, capable of causing explosions that
damage monsters. In one explosion, you can damage monsters as follows:
* Select an alive monster, and cause an explosion centered at that monster. The health of the monster at the center of the explosion will decrease by A, and the health of each of the other monsters will decrease by B. Here, A and B are predetermined parameters, and A > B holds.
At least how many explosions do you need to cause in order to vanish all the
monsters? | [{"input": "4 5 3\n 8\n 7\n 4\n 2", "output": "2\n \n\nYou can vanish all the monsters in two explosion, as follows:\n\n * First, cause an explosion centered at the monster with 8 health. The healths of the four monsters become 3, 4, 1 and -1, respectively, and the last monster vanishes.\n * Second, cause an explosion centered at the monster with 4 health remaining. The healths of the three remaining monsters become 0, -1 and -2, respectively, and all the monsters are now vanished.\n\n* * *"}, {"input": "2 10 4\n 20\n 20", "output": "4\n \n\nYou need to cause two explosions centered at each monster, for a total of\nfour.\n\n* * *"}, {"input": "5 2 1\n 900000000\n 900000000\n 1000000000\n 1000000000\n 1000000000", "output": "800000000"}] |
Print the minimum number of explosions that needs to be caused in order to
vanish all the monsters.
* * * | s710032237 | Wrong Answer | p03700 | Input is given from Standard Input in the following format:
N A B
h_1
h_2
:
h_N | import sys
import heapq
import re
from itertools import permutations
from bisect import bisect_left, bisect_right
from collections import Counter, deque
from math import factorial, sqrt, ceil, gcd
from functools import lru_cache, reduce
from decimal import Decimal
from operator import mul
INF = 1 << 60
MOD = 1000000007
sys.setrecursionlimit(10**7)
# UnionFind
class UnionFind:
def __init__(self, n):
self.n = n
self.parents = [-1] * n
def find(self, x):
if self.parents[x] < 0:
return x
else:
self.parents[x] = self.find(self.parents[x])
return self.parents[x]
def union(self, x, y):
x = self.find(x)
y = self.find(y)
if x == y:
return
if self.parents[x] > self.parents[y]:
x, y = y, x
self.parents[x] += self.parents[y]
self.parents[y] = x
def size(self, x):
return -self.parents[self.find(x)]
def same(self, x, y):
return self.find(x) == self.find(y)
def members(self, x):
root = self.find(x)
return [i for i in range(self.n) if self.find(i) == root]
def roots(self):
return [i for i, x in enumerate(self.parents) if x < 0]
def group_count(self):
return len(self.roots())
def all_group_members(self):
return {r: self.members(r) for r in self.roots()}
def __str__(self):
return "\n".join("{}: {}".format(r, self.members(r)) for r in self.roots())
# ダイクストラ
def dijkstra_heap(s, edge, n):
# 始点sから各頂点への最短距離
d = [10**20] * n
used = [True] * n # True:未確定
d[s] = 0
used[s] = False
edgelist = []
for a, b in edge[s]:
heapq.heappush(edgelist, a * (10**6) + b)
while len(edgelist):
minedge = heapq.heappop(edgelist)
# まだ使われてない頂点の中から最小の距離のものを探す
if not used[minedge % (10**6)]:
continue
v = minedge % (10**6)
d[v] = minedge // (10**6)
used[v] = False
for e in edge[v]:
if used[e[1]]:
heapq.heappush(edgelist, (e[0] + d[v]) * (10**6) + e[1])
return d
# 素因数分解
def factorization(n):
arr = []
temp = n
for i in range(2, int(-(-(n**0.5) // 1)) + 1):
if temp % i == 0:
cnt = 0
while temp % i == 0:
cnt += 1
temp //= i
arr.append([i, cnt])
if temp != 1:
arr.append([temp, 1])
if arr == []:
arr.append([n, 1])
return arr
# 組合せnCr
def combinations_count(n, r):
if n < r:
return 0
r = min(r, n - r)
numer = reduce(mul, range(n, n - r, -1), 1)
denom = reduce(mul, range(1, r + 1), 1)
return numer // denom
# 2数の最小公倍数
def lcm(x, y):
return (x * y) // gcd(x, y)
# リストの要素の最小公倍数
def lcm_list(numbers):
return reduce(lcm, numbers, 1)
# リストの要素の最大公約数
def gcd_list(numbers):
return reduce(gcd, numbers)
# 素数判定
def is_prime(n):
if n <= 1:
return False
p = 2
while True:
if p**2 > n:
break
if n % p == 0:
return False
p += 1
return True
# limit以下の素数を列挙
def eratosthenes(limit):
A = [i for i in range(2, limit + 1)]
P = []
while True:
prime = min(A)
if prime > sqrt(limit):
break
P.append(prime)
i = 0
while i < len(A):
if A[i] % prime == 0:
A.pop(i)
continue
i += 1
for a in A:
P.append(a)
return P
# 同じものを含む順列
def permutation_with_duplicates(L):
if L == []:
return [[]]
else:
ret = []
# set(集合)型で重複を削除、ソート
S = sorted(set(L))
for i in S:
data = L[:]
data.remove(i)
for j in permutation_with_duplicates(data):
ret.append([i] + j)
return ret
def make_divisors(n):
lower_divisors, upper_divisors = [], []
i = 1
while i * i <= n:
if n % i == 0:
lower_divisors.append(i)
if i != n // i:
upper_divisors.append(n // i)
i += 1
return lower_divisors + upper_divisors[::-1]
# ここから書き始める
def is_ok(key, h, a, b, n):
total = 0
for i in range(n):
total += -(-(h[i] - b * key) // (-b + a))
if total <= key:
return True
return False
n, a, b = map(int, input().split())
h = [int(input()) for i in range(n)]
x = -(-max(h) // b)
ng = 0
ok = x + 1
while abs(ok - ng) > 1:
mid = (ok + ng) // 2
if is_ok(mid, h, a, b, n):
ok = mid
else:
ng = mid
print(ok)
| Statement
You are going out for a walk, when you suddenly encounter N monsters. Each
monster has a parameter called _health_ , and the health of the i-th monster
is h_i at the moment of encounter. A monster will vanish immediately when its
health drops to 0 or below.
Fortunately, you are a skilled magician, capable of causing explosions that
damage monsters. In one explosion, you can damage monsters as follows:
* Select an alive monster, and cause an explosion centered at that monster. The health of the monster at the center of the explosion will decrease by A, and the health of each of the other monsters will decrease by B. Here, A and B are predetermined parameters, and A > B holds.
At least how many explosions do you need to cause in order to vanish all the
monsters? | [{"input": "4 5 3\n 8\n 7\n 4\n 2", "output": "2\n \n\nYou can vanish all the monsters in two explosion, as follows:\n\n * First, cause an explosion centered at the monster with 8 health. The healths of the four monsters become 3, 4, 1 and -1, respectively, and the last monster vanishes.\n * Second, cause an explosion centered at the monster with 4 health remaining. The healths of the three remaining monsters become 0, -1 and -2, respectively, and all the monsters are now vanished.\n\n* * *"}, {"input": "2 10 4\n 20\n 20", "output": "4\n \n\nYou need to cause two explosions centered at each monster, for a total of\nfour.\n\n* * *"}, {"input": "5 2 1\n 900000000\n 900000000\n 1000000000\n 1000000000\n 1000000000", "output": "800000000"}] |
Print the minimum number of explosions that needs to be caused in order to
vanish all the monsters.
* * * | s601670755 | Runtime Error | p03700 | Input is given from Standard Input in the following format:
N A B
h_1
h_2
:
h_N | n, a, b = map(int, input().split())
nums = [0 for i in range(n)]
for i in range(n):
nums[i] = int(input())
nums = sorted(nums, reverse=True)
count = 0
while nums[0] > 0:
nums[0] = nums[0] - a
for i in range(1, n):
nums[i] = nums[i] - b
nums = sorted(num, reverse=True)
count += 1
print(str(count))
| Statement
You are going out for a walk, when you suddenly encounter N monsters. Each
monster has a parameter called _health_ , and the health of the i-th monster
is h_i at the moment of encounter. A monster will vanish immediately when its
health drops to 0 or below.
Fortunately, you are a skilled magician, capable of causing explosions that
damage monsters. In one explosion, you can damage monsters as follows:
* Select an alive monster, and cause an explosion centered at that monster. The health of the monster at the center of the explosion will decrease by A, and the health of each of the other monsters will decrease by B. Here, A and B are predetermined parameters, and A > B holds.
At least how many explosions do you need to cause in order to vanish all the
monsters? | [{"input": "4 5 3\n 8\n 7\n 4\n 2", "output": "2\n \n\nYou can vanish all the monsters in two explosion, as follows:\n\n * First, cause an explosion centered at the monster with 8 health. The healths of the four monsters become 3, 4, 1 and -1, respectively, and the last monster vanishes.\n * Second, cause an explosion centered at the monster with 4 health remaining. The healths of the three remaining monsters become 0, -1 and -2, respectively, and all the monsters are now vanished.\n\n* * *"}, {"input": "2 10 4\n 20\n 20", "output": "4\n \n\nYou need to cause two explosions centered at each monster, for a total of\nfour.\n\n* * *"}, {"input": "5 2 1\n 900000000\n 900000000\n 1000000000\n 1000000000\n 1000000000", "output": "800000000"}] |
Print the minimum number of explosions that needs to be caused in order to
vanish all the monsters.
* * * | s687081253 | Runtime Error | p03700 | Input is given from Standard Input in the following format:
N A B
h_1
h_2
:
h_N | # coding: utf-8
# Your code here!
n,a,b=map(int,input().split())
h=[]
for i in range(n):
x=int(input())
h.append(x)
def check(t):
c=0
for i in range(n):
c+=1+(max(0,h[i]-b*t)-1)//(a-b)
return t>=c
l=1
r=1+max(h)//b
while r-l>1:
mid=(r-l)//2+l
if check(mid):
r=mid
else:
l=mid
ans=l
if check(r):
#ans=r
print(ans)
| Statement
You are going out for a walk, when you suddenly encounter N monsters. Each
monster has a parameter called _health_ , and the health of the i-th monster
is h_i at the moment of encounter. A monster will vanish immediately when its
health drops to 0 or below.
Fortunately, you are a skilled magician, capable of causing explosions that
damage monsters. In one explosion, you can damage monsters as follows:
* Select an alive monster, and cause an explosion centered at that monster. The health of the monster at the center of the explosion will decrease by A, and the health of each of the other monsters will decrease by B. Here, A and B are predetermined parameters, and A > B holds.
At least how many explosions do you need to cause in order to vanish all the
monsters? | [{"input": "4 5 3\n 8\n 7\n 4\n 2", "output": "2\n \n\nYou can vanish all the monsters in two explosion, as follows:\n\n * First, cause an explosion centered at the monster with 8 health. The healths of the four monsters become 3, 4, 1 and -1, respectively, and the last monster vanishes.\n * Second, cause an explosion centered at the monster with 4 health remaining. The healths of the three remaining monsters become 0, -1 and -2, respectively, and all the monsters are now vanished.\n\n* * *"}, {"input": "2 10 4\n 20\n 20", "output": "4\n \n\nYou need to cause two explosions centered at each monster, for a total of\nfour.\n\n* * *"}, {"input": "5 2 1\n 900000000\n 900000000\n 1000000000\n 1000000000\n 1000000000", "output": "800000000"}] |
Print the minimum number of explosions that needs to be caused in order to
vanish all the monsters.
* * * | s421497594 | Wrong Answer | p03700 | Input is given from Standard Input in the following format:
N A B
h_1
h_2
:
h_N | n, a, b = map(int, input().split())
teki = []
ans = 0
for i in range(n):
teki.append(int(input()))
q = a - b
ss = max(teki)
m = 0
for i in range(n):
u = teki[i] // b + 1
if m <= u:
m = u
for i in range(n):
teki[i] = teki[i] - b * (m)
if teki[i] <= 0:
teki[i] == 0
ans += m
while 0 in teki:
teki.remove(0)
"""
while tekis != []:
for i in range(len(tekis)):
tekis[i] = tekis[i] - b
k = max(tekis)
tekis.remove(k)
tekis.append(k + a- b)
for i in range(len(tekis)):
if tekis[i] <= 0:
tekis[i] = 0
while 0 in tekis:
tekis.remove(0)
ans += 1
"""
print(ans - 1)
| Statement
You are going out for a walk, when you suddenly encounter N monsters. Each
monster has a parameter called _health_ , and the health of the i-th monster
is h_i at the moment of encounter. A monster will vanish immediately when its
health drops to 0 or below.
Fortunately, you are a skilled magician, capable of causing explosions that
damage monsters. In one explosion, you can damage monsters as follows:
* Select an alive monster, and cause an explosion centered at that monster. The health of the monster at the center of the explosion will decrease by A, and the health of each of the other monsters will decrease by B. Here, A and B are predetermined parameters, and A > B holds.
At least how many explosions do you need to cause in order to vanish all the
monsters? | [{"input": "4 5 3\n 8\n 7\n 4\n 2", "output": "2\n \n\nYou can vanish all the monsters in two explosion, as follows:\n\n * First, cause an explosion centered at the monster with 8 health. The healths of the four monsters become 3, 4, 1 and -1, respectively, and the last monster vanishes.\n * Second, cause an explosion centered at the monster with 4 health remaining. The healths of the three remaining monsters become 0, -1 and -2, respectively, and all the monsters are now vanished.\n\n* * *"}, {"input": "2 10 4\n 20\n 20", "output": "4\n \n\nYou need to cause two explosions centered at each monster, for a total of\nfour.\n\n* * *"}, {"input": "5 2 1\n 900000000\n 900000000\n 1000000000\n 1000000000\n 1000000000", "output": "800000000"}] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.