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 `Yes` if the string `CF` can be obtained from the string s by deleting
some characters. Otherwise print `No`.
* * * | s984369310 | Runtime Error | p03957 | The input is given from Standard Input in the following format:
s | k_t = input().split()
k = int(k_t[0])
t = int(k_t[1])
t_amount = input().split(" ")
while True:
if t == 1:
max = k
break
max = 0
for i in range(t - 1):
if t_amount[i + 1] >= t_amount[i]:
max = t_amount[i + 1]
elif max == 0:
max = t_amount[0]
t_amount.remove(max)
max2 = 0
for i in range(t - 2):
if t_amount[i + 1] >= t_amount[i]:
max2 = t_amount[i + 1]
elif max2 == 0:
max2 = t_amount[0]
t_amount.remove(max2)
if max2 == "0":
break
else:
max = int(max) - 1
max2 = int(max2) - 1
t_amount.append(str(max))
t_amount.append(str(max2))
if max == "0":
print(0)
else:
print(int(max) - 1)
| Statement
This contest is `CODEFESTIVAL`, which can be shortened to the string `CF` by
deleting some characters.
Mr. Takahashi, full of curiosity, wondered if he could obtain `CF` from other
strings in the same way.
You are given a string s consisting of uppercase English letters. Determine
whether the string `CF` can be obtained from the string s by deleting some
characters. | [{"input": "CODEFESTIVAL", "output": "Yes\n \n\n`CF` is obtained by deleting characters other than the first character `C` and\nthe fifth character `F`.\n\n* * *"}, {"input": "FESTIVALCODE", "output": "No\n \n\n`FC` can be obtained but `CF` cannot be obtained because you cannot change the\norder of the characters.\n\n* * *"}, {"input": "CF", "output": "Yes\n \n\nIt is also possible not to delete any characters.\n\n* * *"}, {"input": "FCF", "output": "Yes\n \n\n`CF` is obtained by deleting the first character."}] |
Print `Yes` if the string `CF` can be obtained from the string s by deleting
some characters. Otherwise print `No`.
* * * | s041434638 | Runtime Error | p03957 | The input is given from Standard Input in the following format:
s | #! /usr/bin/env python3
def main():
d = 10**9 + 7
ans = 1
N = int(input())
T = list(map(int, input().split()))
A = list(map(int, input().split()))
L = len(T)
ST = [T[0]] + [0] * (L - 2) + [T[-1] if T[-1] != T[-2] else 0]
SA = [A[0] if A[0] != A[1] else 0] + [0] * (L - 2) + [A[-1]]
for i in range(0, L - 1):
if T[i] == T[i - 1] and A[i] == A[i + 1]:
ans = (ans * min(T[i], A[i])) % d
else:
if T[i] != T[i - 1]:
ST[i] = T[i]
if A[i] != A[i + 1]:
SA[i] = A[i]
mt = ma = 0
for i in range(L):
ma = max(ma, SA[i])
mt = max(mt, ST[L - i - 1])
if ST[i] and SA[i] and ST[i] != SA[i]:
ans = 0
if (ST[i] and ST[i] < ma) or (SA[-i - 1] and SA[-i - 1] < mt):
ans = 0
print(ans)
if __name__ == "__main__":
main()
| Statement
This contest is `CODEFESTIVAL`, which can be shortened to the string `CF` by
deleting some characters.
Mr. Takahashi, full of curiosity, wondered if he could obtain `CF` from other
strings in the same way.
You are given a string s consisting of uppercase English letters. Determine
whether the string `CF` can be obtained from the string s by deleting some
characters. | [{"input": "CODEFESTIVAL", "output": "Yes\n \n\n`CF` is obtained by deleting characters other than the first character `C` and\nthe fifth character `F`.\n\n* * *"}, {"input": "FESTIVALCODE", "output": "No\n \n\n`FC` can be obtained but `CF` cannot be obtained because you cannot change the\norder of the characters.\n\n* * *"}, {"input": "CF", "output": "Yes\n \n\nIt is also possible not to delete any characters.\n\n* * *"}, {"input": "FCF", "output": "Yes\n \n\n`CF` is obtained by deleting the first character."}] |
Print `Yes` if the string `CF` can be obtained from the string s by deleting
some characters. Otherwise print `No`.
* * * | s372618448 | Runtime Error | p03957 | The input is given from Standard Input in the following format:
s | def read():
return [int(i) for i in input().split(" ")]
N = int(input())
T = read()
A = read()
L = [0] * N
unknowL = [0] * N
tempT, tempA = 0, 0
for i in range(N):
if T[i] > tempT:
tempT = L[i] = T[i]
else:
unknowL[i] = T[i]
for i in range(N - 1, -1, -1):
if A[i] > tempA:
if L[i] != 0 and L[i] != A[i]:
print(0)
exit()
tempA = L[i] = A[i]
unknowL[i] = 0
else:
unknowL[i] = min(unknowL[i], A[i])
P = 1
for i in unknowL:
if i != 0:
P *= i
print(P % (10**9 + 7))
| Statement
This contest is `CODEFESTIVAL`, which can be shortened to the string `CF` by
deleting some characters.
Mr. Takahashi, full of curiosity, wondered if he could obtain `CF` from other
strings in the same way.
You are given a string s consisting of uppercase English letters. Determine
whether the string `CF` can be obtained from the string s by deleting some
characters. | [{"input": "CODEFESTIVAL", "output": "Yes\n \n\n`CF` is obtained by deleting characters other than the first character `C` and\nthe fifth character `F`.\n\n* * *"}, {"input": "FESTIVALCODE", "output": "No\n \n\n`FC` can be obtained but `CF` cannot be obtained because you cannot change the\norder of the characters.\n\n* * *"}, {"input": "CF", "output": "Yes\n \n\nIt is also possible not to delete any characters.\n\n* * *"}, {"input": "FCF", "output": "Yes\n \n\n`CF` is obtained by deleting the first character."}] |
Print `Yes` if the string `CF` can be obtained from the string s by deleting
some characters. Otherwise print `No`.
* * * | s248055740 | Runtime Error | p03957 | The input is given from Standard Input in the following format:
s | a=input()
c=False
f=False
for i in range(len(a))
if c:
if a[i]=='F'
f=True
else:
if a[i]=='C'
c=True
if c and f:
print("Yes")
else:
print("No") | Statement
This contest is `CODEFESTIVAL`, which can be shortened to the string `CF` by
deleting some characters.
Mr. Takahashi, full of curiosity, wondered if he could obtain `CF` from other
strings in the same way.
You are given a string s consisting of uppercase English letters. Determine
whether the string `CF` can be obtained from the string s by deleting some
characters. | [{"input": "CODEFESTIVAL", "output": "Yes\n \n\n`CF` is obtained by deleting characters other than the first character `C` and\nthe fifth character `F`.\n\n* * *"}, {"input": "FESTIVALCODE", "output": "No\n \n\n`FC` can be obtained but `CF` cannot be obtained because you cannot change the\norder of the characters.\n\n* * *"}, {"input": "CF", "output": "Yes\n \n\nIt is also possible not to delete any characters.\n\n* * *"}, {"input": "FCF", "output": "Yes\n \n\n`CF` is obtained by deleting the first character."}] |
Print `Yes` if the string `CF` can be obtained from the string s by deleting
some characters. Otherwise print `No`.
* * * | s233280665 | Runtime Error | p03957 | The input is given from Standard Input in the following format:
s | s=input()
x=0;y=0
for i in range(len(s)):
if s[i]=='C':
x=i+1
break
for j in range(len(s)):
if s[j]=='F':
y=j+1
if x*y!=0 and x<y:print('Yes')
else:print('No') | Statement
This contest is `CODEFESTIVAL`, which can be shortened to the string `CF` by
deleting some characters.
Mr. Takahashi, full of curiosity, wondered if he could obtain `CF` from other
strings in the same way.
You are given a string s consisting of uppercase English letters. Determine
whether the string `CF` can be obtained from the string s by deleting some
characters. | [{"input": "CODEFESTIVAL", "output": "Yes\n \n\n`CF` is obtained by deleting characters other than the first character `C` and\nthe fifth character `F`.\n\n* * *"}, {"input": "FESTIVALCODE", "output": "No\n \n\n`FC` can be obtained but `CF` cannot be obtained because you cannot change the\norder of the characters.\n\n* * *"}, {"input": "CF", "output": "Yes\n \n\nIt is also possible not to delete any characters.\n\n* * *"}, {"input": "FCF", "output": "Yes\n \n\n`CF` is obtained by deleting the first character."}] |
Print `Yes` if the string `CF` can be obtained from the string s by deleting
some characters. Otherwise print `No`.
* * * | s252909181 | Runtime Error | p03957 | The input is given from Standard Input in the following format:
s | if 'CF' in input():
print('Yes')
else:
print('No) | Statement
This contest is `CODEFESTIVAL`, which can be shortened to the string `CF` by
deleting some characters.
Mr. Takahashi, full of curiosity, wondered if he could obtain `CF` from other
strings in the same way.
You are given a string s consisting of uppercase English letters. Determine
whether the string `CF` can be obtained from the string s by deleting some
characters. | [{"input": "CODEFESTIVAL", "output": "Yes\n \n\n`CF` is obtained by deleting characters other than the first character `C` and\nthe fifth character `F`.\n\n* * *"}, {"input": "FESTIVALCODE", "output": "No\n \n\n`FC` can be obtained but `CF` cannot be obtained because you cannot change the\norder of the characters.\n\n* * *"}, {"input": "CF", "output": "Yes\n \n\nIt is also possible not to delete any characters.\n\n* * *"}, {"input": "FCF", "output": "Yes\n \n\n`CF` is obtained by deleting the first character."}] |
Print `Yes` if the string `CF` can be obtained from the string s by deleting
some characters. Otherwise print `No`.
* * * | s798430737 | Runtime Error | p03957 | The input is given from Standard Input in the following format:
s | import re
print("YNEOS"[1-re.match('.*C.*F',input())::2]
| Statement
This contest is `CODEFESTIVAL`, which can be shortened to the string `CF` by
deleting some characters.
Mr. Takahashi, full of curiosity, wondered if he could obtain `CF` from other
strings in the same way.
You are given a string s consisting of uppercase English letters. Determine
whether the string `CF` can be obtained from the string s by deleting some
characters. | [{"input": "CODEFESTIVAL", "output": "Yes\n \n\n`CF` is obtained by deleting characters other than the first character `C` and\nthe fifth character `F`.\n\n* * *"}, {"input": "FESTIVALCODE", "output": "No\n \n\n`FC` can be obtained but `CF` cannot be obtained because you cannot change the\norder of the characters.\n\n* * *"}, {"input": "CF", "output": "Yes\n \n\nIt is also possible not to delete any characters.\n\n* * *"}, {"input": "FCF", "output": "Yes\n \n\n`CF` is obtained by deleting the first character."}] |
Print `Yes` if the string `CF` can be obtained from the string s by deleting
some characters. Otherwise print `No`.
* * * | s456120599 | Runtime Error | p03957 | The input is given from Standard Input in the following format:
s | S = input()
a,b= S.find('C'),S.find('F')
print('Yes') if a>0 and b>0 and> a<b else print('No') | Statement
This contest is `CODEFESTIVAL`, which can be shortened to the string `CF` by
deleting some characters.
Mr. Takahashi, full of curiosity, wondered if he could obtain `CF` from other
strings in the same way.
You are given a string s consisting of uppercase English letters. Determine
whether the string `CF` can be obtained from the string s by deleting some
characters. | [{"input": "CODEFESTIVAL", "output": "Yes\n \n\n`CF` is obtained by deleting characters other than the first character `C` and\nthe fifth character `F`.\n\n* * *"}, {"input": "FESTIVALCODE", "output": "No\n \n\n`FC` can be obtained but `CF` cannot be obtained because you cannot change the\norder of the characters.\n\n* * *"}, {"input": "CF", "output": "Yes\n \n\nIt is also possible not to delete any characters.\n\n* * *"}, {"input": "FCF", "output": "Yes\n \n\n`CF` is obtained by deleting the first character."}] |
Print `Yes` if the string `CF` can be obtained from the string s by deleting
some characters. Otherwise print `No`.
* * * | s646345183 | Wrong Answer | p03957 | The input is given from Standard Input in the following format:
s | print("Yes")
| Statement
This contest is `CODEFESTIVAL`, which can be shortened to the string `CF` by
deleting some characters.
Mr. Takahashi, full of curiosity, wondered if he could obtain `CF` from other
strings in the same way.
You are given a string s consisting of uppercase English letters. Determine
whether the string `CF` can be obtained from the string s by deleting some
characters. | [{"input": "CODEFESTIVAL", "output": "Yes\n \n\n`CF` is obtained by deleting characters other than the first character `C` and\nthe fifth character `F`.\n\n* * *"}, {"input": "FESTIVALCODE", "output": "No\n \n\n`FC` can be obtained but `CF` cannot be obtained because you cannot change the\norder of the characters.\n\n* * *"}, {"input": "CF", "output": "Yes\n \n\nIt is also possible not to delete any characters.\n\n* * *"}, {"input": "FCF", "output": "Yes\n \n\n`CF` is obtained by deleting the first character."}] |
Print `Yes` if the string `CF` can be obtained from the string s by deleting
some characters. Otherwise print `No`.
* * * | s733582205 | Runtime Error | p03957 | The input is given from Standard Input in the following format:
s | print<>=~/C.*F/?Yes:No,$/ | Statement
This contest is `CODEFESTIVAL`, which can be shortened to the string `CF` by
deleting some characters.
Mr. Takahashi, full of curiosity, wondered if he could obtain `CF` from other
strings in the same way.
You are given a string s consisting of uppercase English letters. Determine
whether the string `CF` can be obtained from the string s by deleting some
characters. | [{"input": "CODEFESTIVAL", "output": "Yes\n \n\n`CF` is obtained by deleting characters other than the first character `C` and\nthe fifth character `F`.\n\n* * *"}, {"input": "FESTIVALCODE", "output": "No\n \n\n`FC` can be obtained but `CF` cannot be obtained because you cannot change the\norder of the characters.\n\n* * *"}, {"input": "CF", "output": "Yes\n \n\nIt is also possible not to delete any characters.\n\n* * *"}, {"input": "FCF", "output": "Yes\n \n\n`CF` is obtained by deleting the first character."}] |
Print `Yes` if the string `CF` can be obtained from the string s by deleting
some characters. Otherwise print `No`.
* * * | s283567299 | Accepted | p03957 | The input is given from Standard Input in the following format:
s | s = list(input())
ans = ""
for i in s:
if i in "C":
ans += i
elif i in "F":
ans += i
print("Yes" if "CF" in ans else "No")
| Statement
This contest is `CODEFESTIVAL`, which can be shortened to the string `CF` by
deleting some characters.
Mr. Takahashi, full of curiosity, wondered if he could obtain `CF` from other
strings in the same way.
You are given a string s consisting of uppercase English letters. Determine
whether the string `CF` can be obtained from the string s by deleting some
characters. | [{"input": "CODEFESTIVAL", "output": "Yes\n \n\n`CF` is obtained by deleting characters other than the first character `C` and\nthe fifth character `F`.\n\n* * *"}, {"input": "FESTIVALCODE", "output": "No\n \n\n`FC` can be obtained but `CF` cannot be obtained because you cannot change the\norder of the characters.\n\n* * *"}, {"input": "CF", "output": "Yes\n \n\nIt is also possible not to delete any characters.\n\n* * *"}, {"input": "FCF", "output": "Yes\n \n\n`CF` is obtained by deleting the first character."}] |
Print `Yes` if the string `CF` can be obtained from the string s by deleting
some characters. Otherwise print `No`.
* * * | s048728074 | Runtime Error | p03957 | The input is given from Standard Input in the following format:
s | s = input()
ans = 'No'
c = s.find('C')
if c != -1:
f = s[c:].find('F')
if f != -1:
ans = 'Yes'
print(ans) | Statement
This contest is `CODEFESTIVAL`, which can be shortened to the string `CF` by
deleting some characters.
Mr. Takahashi, full of curiosity, wondered if he could obtain `CF` from other
strings in the same way.
You are given a string s consisting of uppercase English letters. Determine
whether the string `CF` can be obtained from the string s by deleting some
characters. | [{"input": "CODEFESTIVAL", "output": "Yes\n \n\n`CF` is obtained by deleting characters other than the first character `C` and\nthe fifth character `F`.\n\n* * *"}, {"input": "FESTIVALCODE", "output": "No\n \n\n`FC` can be obtained but `CF` cannot be obtained because you cannot change the\norder of the characters.\n\n* * *"}, {"input": "CF", "output": "Yes\n \n\nIt is also possible not to delete any characters.\n\n* * *"}, {"input": "FCF", "output": "Yes\n \n\n`CF` is obtained by deleting the first character."}] |
Print `Yes` if the string `CF` can be obtained from the string s by deleting
some characters. Otherwise print `No`.
* * * | s690990018 | Runtime Error | p03957 | The input is given from Standard Input in the following format:
s | s=input()
l=len(s)
x='No'
f=0
for i in range(l):
if s[i]=='C':
f=1
if s[i]=='F' and f=1:
x='Yes'
break
print(x) | Statement
This contest is `CODEFESTIVAL`, which can be shortened to the string `CF` by
deleting some characters.
Mr. Takahashi, full of curiosity, wondered if he could obtain `CF` from other
strings in the same way.
You are given a string s consisting of uppercase English letters. Determine
whether the string `CF` can be obtained from the string s by deleting some
characters. | [{"input": "CODEFESTIVAL", "output": "Yes\n \n\n`CF` is obtained by deleting characters other than the first character `C` and\nthe fifth character `F`.\n\n* * *"}, {"input": "FESTIVALCODE", "output": "No\n \n\n`FC` can be obtained but `CF` cannot be obtained because you cannot change the\norder of the characters.\n\n* * *"}, {"input": "CF", "output": "Yes\n \n\nIt is also possible not to delete any characters.\n\n* * *"}, {"input": "FCF", "output": "Yes\n \n\n`CF` is obtained by deleting the first character."}] |
Print `Yes` if the string `CF` can be obtained from the string s by deleting
some characters. Otherwise print `No`.
* * * | s432678400 | Runtime Error | p03957 | The input is given from Standard Input in the following format:
s | s = input()
a = s.find('C')
if a == -1:
print("No")
else:
if s[a:].find('F') == -1:
print("No")
else print("Yes") | Statement
This contest is `CODEFESTIVAL`, which can be shortened to the string `CF` by
deleting some characters.
Mr. Takahashi, full of curiosity, wondered if he could obtain `CF` from other
strings in the same way.
You are given a string s consisting of uppercase English letters. Determine
whether the string `CF` can be obtained from the string s by deleting some
characters. | [{"input": "CODEFESTIVAL", "output": "Yes\n \n\n`CF` is obtained by deleting characters other than the first character `C` and\nthe fifth character `F`.\n\n* * *"}, {"input": "FESTIVALCODE", "output": "No\n \n\n`FC` can be obtained but `CF` cannot be obtained because you cannot change the\norder of the characters.\n\n* * *"}, {"input": "CF", "output": "Yes\n \n\nIt is also possible not to delete any characters.\n\n* * *"}, {"input": "FCF", "output": "Yes\n \n\n`CF` is obtained by deleting the first character."}] |
Print `Yes` if the string `CF` can be obtained from the string s by deleting
some characters. Otherwise print `No`.
* * * | s674233788 | Runtime Error | p03957 | The input is given from Standard Input in the following format:
s | def main()
s = input()
f = False
if s.count('C') == 0 or s.count('F') == 0:
print('NO')
return
for i in range(len(s)):
if s[i] == 'C':
for j in range(i, len(s)):
if s[j] == 'F':
print('Yes')
f = True
break
if f == False:
print('No')
main() | Statement
This contest is `CODEFESTIVAL`, which can be shortened to the string `CF` by
deleting some characters.
Mr. Takahashi, full of curiosity, wondered if he could obtain `CF` from other
strings in the same way.
You are given a string s consisting of uppercase English letters. Determine
whether the string `CF` can be obtained from the string s by deleting some
characters. | [{"input": "CODEFESTIVAL", "output": "Yes\n \n\n`CF` is obtained by deleting characters other than the first character `C` and\nthe fifth character `F`.\n\n* * *"}, {"input": "FESTIVALCODE", "output": "No\n \n\n`FC` can be obtained but `CF` cannot be obtained because you cannot change the\norder of the characters.\n\n* * *"}, {"input": "CF", "output": "Yes\n \n\nIt is also possible not to delete any characters.\n\n* * *"}, {"input": "FCF", "output": "Yes\n \n\n`CF` is obtained by deleting the first character."}] |
Print `Yes` if the string `CF` can be obtained from the string s by deleting
some characters. Otherwise print `No`.
* * * | s594869766 | Runtime Error | p03957 | The input is given from Standard Input in the following format:
s | a=input()
c=False
f=False
for i in range(len(a)):
if c==True:
if a[i]=='F':
f=True
else:
if a[i]=='C':
c=True
if c==True and f==True:
print("Yes")
else:
print("No") | Statement
This contest is `CODEFESTIVAL`, which can be shortened to the string `CF` by
deleting some characters.
Mr. Takahashi, full of curiosity, wondered if he could obtain `CF` from other
strings in the same way.
You are given a string s consisting of uppercase English letters. Determine
whether the string `CF` can be obtained from the string s by deleting some
characters. | [{"input": "CODEFESTIVAL", "output": "Yes\n \n\n`CF` is obtained by deleting characters other than the first character `C` and\nthe fifth character `F`.\n\n* * *"}, {"input": "FESTIVALCODE", "output": "No\n \n\n`FC` can be obtained but `CF` cannot be obtained because you cannot change the\norder of the characters.\n\n* * *"}, {"input": "CF", "output": "Yes\n \n\nIt is also possible not to delete any characters.\n\n* * *"}, {"input": "FCF", "output": "Yes\n \n\n`CF` is obtained by deleting the first character."}] |
Print `Yes` if the string `CF` can be obtained from the string s by deleting
some characters. Otherwise print `No`.
* * * | s395128218 | Runtime Error | p03957 | The input is given from Standard Input in the following format:
s | import sys
def LI():
return list(map(int, sys.stdin.buffer.readline().split()))
def I():
return int(sys.stdin.buffer.readline())
def LS():
return sys.stdin.buffer.readline().rstrip().decode("utf-8").split()
def S():
return sys.stdin.buffer.readline().rstrip().decode("utf-8")
def IR(n):
return [I() for i in range(n)]
def LIR(n):
return [LI() for i in range(n)]
def SR(n):
return [S() for i in range(n)]
def LSR(n):
return [LS() for i in range(n)]
def SRL(n):
return [list(S()) for i in range(n)]
def MSRL(n):
return [[int(j) for j in list(S())] for i in range(n)]
s = S()
ans = ""
if "C" in s:
ans += "C"
if "F" in s[s.index("C") :]:
ans += "F"
if ans == "CF":
print("Yes")
else:
print("No")
| Statement
This contest is `CODEFESTIVAL`, which can be shortened to the string `CF` by
deleting some characters.
Mr. Takahashi, full of curiosity, wondered if he could obtain `CF` from other
strings in the same way.
You are given a string s consisting of uppercase English letters. Determine
whether the string `CF` can be obtained from the string s by deleting some
characters. | [{"input": "CODEFESTIVAL", "output": "Yes\n \n\n`CF` is obtained by deleting characters other than the first character `C` and\nthe fifth character `F`.\n\n* * *"}, {"input": "FESTIVALCODE", "output": "No\n \n\n`FC` can be obtained but `CF` cannot be obtained because you cannot change the\norder of the characters.\n\n* * *"}, {"input": "CF", "output": "Yes\n \n\nIt is also possible not to delete any characters.\n\n* * *"}, {"input": "FCF", "output": "Yes\n \n\n`CF` is obtained by deleting the first character."}] |
Print `Yes` if the string `CF` can be obtained from the string s by deleting
some characters. Otherwise print `No`.
* * * | s685229484 | Accepted | p03957 | The input is given from Standard Input in the following format:
s | a = input()
ans = int()
for i in range(len(a)):
if "C" in a[i]:
b = a[i + 1 :]
for j in range(len(b)):
if "F" in b[j]:
ans += 1
print("Yes" if ans > 0 else "No")
| Statement
This contest is `CODEFESTIVAL`, which can be shortened to the string `CF` by
deleting some characters.
Mr. Takahashi, full of curiosity, wondered if he could obtain `CF` from other
strings in the same way.
You are given a string s consisting of uppercase English letters. Determine
whether the string `CF` can be obtained from the string s by deleting some
characters. | [{"input": "CODEFESTIVAL", "output": "Yes\n \n\n`CF` is obtained by deleting characters other than the first character `C` and\nthe fifth character `F`.\n\n* * *"}, {"input": "FESTIVALCODE", "output": "No\n \n\n`FC` can be obtained but `CF` cannot be obtained because you cannot change the\norder of the characters.\n\n* * *"}, {"input": "CF", "output": "Yes\n \n\nIt is also possible not to delete any characters.\n\n* * *"}, {"input": "FCF", "output": "Yes\n \n\n`CF` is obtained by deleting the first character."}] |
Print your answer.
* * * | s198268966 | Accepted | p02645 | Input is given from Standard Input in the following format:
S | string = input()
print(string[:3])
| Statement
When you asked some guy in your class his name, he called himself S, where S
is a string of length between 3 and 20 (inclusive) consisting of lowercase
English letters. You have decided to choose some three consecutive characters
from S and make it his nickname. Print a string that is a valid nickname for
him. | [{"input": "takahashi", "output": "tak\n \n\n* * *"}, {"input": "naohiro", "output": "nao"}] |
Print your answer.
* * * | s748120015 | Accepted | p02645 | Input is given from Standard Input in the following format:
S | word = input()
print(word[:3])
| Statement
When you asked some guy in your class his name, he called himself S, where S
is a string of length between 3 and 20 (inclusive) consisting of lowercase
English letters. You have decided to choose some three consecutive characters
from S and make it his nickname. Print a string that is a valid nickname for
him. | [{"input": "takahashi", "output": "tak\n \n\n* * *"}, {"input": "naohiro", "output": "nao"}] |
Print your answer.
* * * | s271698587 | Wrong Answer | p02645 | Input is given from Standard Input in the following format:
S | print(input()[0:2])
| Statement
When you asked some guy in your class his name, he called himself S, where S
is a string of length between 3 and 20 (inclusive) consisting of lowercase
English letters. You have decided to choose some three consecutive characters
from S and make it his nickname. Print a string that is a valid nickname for
him. | [{"input": "takahashi", "output": "tak\n \n\n* * *"}, {"input": "naohiro", "output": "nao"}] |
Print your answer.
* * * | s616313829 | Accepted | p02645 | Input is given from Standard Input in the following format:
S | n = str(input())
m = n[0] + n[1] + n[2]
print(m)
| Statement
When you asked some guy in your class his name, he called himself S, where S
is a string of length between 3 and 20 (inclusive) consisting of lowercase
English letters. You have decided to choose some three consecutive characters
from S and make it his nickname. Print a string that is a valid nickname for
him. | [{"input": "takahashi", "output": "tak\n \n\n* * *"}, {"input": "naohiro", "output": "nao"}] |
Print your answer.
* * * | s793508378 | Accepted | p02645 | Input is given from Standard Input in the following format:
S | S = list(input())
l = list()
l.append(S[0])
l.append(S[1])
l.append(S[2])
print("".join(l))
| Statement
When you asked some guy in your class his name, he called himself S, where S
is a string of length between 3 and 20 (inclusive) consisting of lowercase
English letters. You have decided to choose some three consecutive characters
from S and make it his nickname. Print a string that is a valid nickname for
him. | [{"input": "takahashi", "output": "tak\n \n\n* * *"}, {"input": "naohiro", "output": "nao"}] |
Print your answer.
* * * | s276486594 | Accepted | p02645 | Input is given from Standard Input in the following format:
S | print((input())[:3])
| Statement
When you asked some guy in your class his name, he called himself S, where S
is a string of length between 3 and 20 (inclusive) consisting of lowercase
English letters. You have decided to choose some three consecutive characters
from S and make it his nickname. Print a string that is a valid nickname for
him. | [{"input": "takahashi", "output": "tak\n \n\n* * *"}, {"input": "naohiro", "output": "nao"}] |
Print your answer.
* * * | s660048896 | Runtime Error | p02645 | Input is given from Standard Input in the following format:
S | from sys import stdin
n, k = [int(x) for x in stdin.readline().rstrip().split()]
intense_counters = [0]
dd = [int(x) for x in stdin.readline().rstrip().split()]
intense_counters.extend(dd)
max_intense = False
additional = 0
if k >= n - 1:
print(" ".join(list(map(str, [n] * n))))
else:
for times in range(k):
counter = 0
new_intense_counters = [0] * (n + 1)
add_all = 0
for i, intense in enumerate(intense_counters):
if i == 0:
continue
intense += additional
if intense == n - 1:
counter += 1
add_all += 1
else:
min = i - intense
if min < 1:
min = 1
max = i + intense
if max > n:
max = n
if min == 1 and max == n:
add_all += 1
else:
for lighted_position in range(min, max + 1):
new_intense_counters[lighted_position] += 1
if counter == n:
max_intense = True
break
intense_counters = new_intense_counters
additional = add_all
if max_intense:
print(" ".join(list(map(str, [n] * n))))
else:
print(" ".join(list(map(str, intense_counters[1:]))))
| Statement
When you asked some guy in your class his name, he called himself S, where S
is a string of length between 3 and 20 (inclusive) consisting of lowercase
English letters. You have decided to choose some three consecutive characters
from S and make it his nickname. Print a string that is a valid nickname for
him. | [{"input": "takahashi", "output": "tak\n \n\n* * *"}, {"input": "naohiro", "output": "nao"}] |
Print your answer.
* * * | s409051667 | Runtime Error | p02645 | Input is given from Standard Input in the following format:
S | n, k = map(int, input().split())
a = list(map(int, input().split()))
b = [0] * (n + 2)
S = sum(a)
for i in range(k):
s = S
S = 0
for j in range(n):
if j < a[j]:
b[0] += 1
else:
b[j - a[j] + 1] += 1
if n - 1 - j < a[j]:
b[n + 1] -= 1
else:
b[j + a[j] + 2] -= 1
for j in range(n):
if j == 0:
a[j] = b[j] + b[j + 1]
else:
a[j] = a[j - 1] + b[j + 1]
b[j] = 0
S += a[j]
b[-2] = 0
b[-1] = 0
if S == s:
break
for i in a:
print(i, end=" ")
| Statement
When you asked some guy in your class his name, he called himself S, where S
is a string of length between 3 and 20 (inclusive) consisting of lowercase
English letters. You have decided to choose some three consecutive characters
from S and make it his nickname. Print a string that is a valid nickname for
him. | [{"input": "takahashi", "output": "tak\n \n\n* * *"}, {"input": "naohiro", "output": "nao"}] |
Print your answer.
* * * | s486474703 | Runtime Error | p02645 | Input is given from Standard Input in the following format:
S | import sys
readline = sys.stdin.readline
def mergeup(Av, Aw, vw):
v, w = vw
rv, rw = [], []
N = len(Av)
idx = 0
jdx = 0
for _ in range(2 * N):
if idx == N or Aw[idx] > Aw[jdx] + w:
if Aw[jdx] + w > limit:
break
rw.append(Aw[jdx] + w)
rv.append(Av[jdx] + v)
jdx += 1
else:
rw.append(Aw[idx])
rv.append(Av[idx])
idx += 1
return rv, rw
def mergedown(Av, Aw, vw):
v, w = vw
resv, resw = [], []
N = len(Av)
idx = 0
jdx = 0
for _ in range(2 * N):
if jdx == N:
resv.append(Av[idx])
resw.append(Aw[idx])
idx += 1
continue
if Aw[idx] <= Aw[jdx] - w:
resv.append(Av[idx])
resw.append(Aw[idx])
idx += 1
else:
if Aw[jdx] - w < 0:
jdx += 1
continue
resv.append(Av[jdx] + v)
resw.append(Aw[jdx] - w)
jdx += 1
return resv, resw
limit = 10**5
N = int(readline())
VW = [None] + [tuple(map(int, readline().split())) for _ in range(N)]
BS = min(N, 1 << 10)
Q = int(readline())
VL = [None] + [tuple(map(int, readline().split())) for _ in range(Q)]
Rv = [[0] for _ in range(BS + 1)]
Rw = [[0] for _ in range(BS + 1)]
for i in range(1, BS):
for vm, wm in zip(*mergeup(Rv[i // 2], Rw[i // 2], VW[i])):
if Rv[i][-1] < vm:
Rv[i].append(vm)
Rw[i].append(wm)
ans = [0] * (Q + 1)
for i in range(1, Q + 1):
v, l = VL[i]
Kv, Kw = [0], [l]
while v >= BS:
Kv, Kw = mergedown(Kv, Kw, VW[v])
v >>= 1
cnt = len(Rv[v]) - 1
ctr = 0
for j in range(len(Kv) - 1, -1, -1):
kv, kw = Kv[j], Kw[j]
while kw < Rw[v][cnt]:
cnt -= 1
ctr = max(ctr, kv + Rv[v][cnt])
ans[i] = ctr
print("\n".join(map(str, ans[1:])))
| Statement
When you asked some guy in your class his name, he called himself S, where S
is a string of length between 3 and 20 (inclusive) consisting of lowercase
English letters. You have decided to choose some three consecutive characters
from S and make it his nickname. Print a string that is a valid nickname for
him. | [{"input": "takahashi", "output": "tak\n \n\n* * *"}, {"input": "naohiro", "output": "nao"}] |
Print your answer.
* * * | s887945360 | Wrong Answer | p02645 | Input is given from Standard Input in the following format:
S | i = input()
print(i[0:2])
| Statement
When you asked some guy in your class his name, he called himself S, where S
is a string of length between 3 and 20 (inclusive) consisting of lowercase
English letters. You have decided to choose some three consecutive characters
from S and make it his nickname. Print a string that is a valid nickname for
him. | [{"input": "takahashi", "output": "tak\n \n\n* * *"}, {"input": "naohiro", "output": "nao"}] |
Print your answer.
* * * | s995864519 | Wrong Answer | p02645 | Input is given from Standard Input in the following format:
S | S = input("What's your name?")
Nickname = S[0:2]
print(Nickname)
| Statement
When you asked some guy in your class his name, he called himself S, where S
is a string of length between 3 and 20 (inclusive) consisting of lowercase
English letters. You have decided to choose some three consecutive characters
from S and make it his nickname. Print a string that is a valid nickname for
him. | [{"input": "takahashi", "output": "tak\n \n\n* * *"}, {"input": "naohiro", "output": "nao"}] |
Print your answer.
* * * | s002403601 | Accepted | p02645 | Input is given from Standard Input in the following format:
S | A = input()
print(A[:3])
| Statement
When you asked some guy in your class his name, he called himself S, where S
is a string of length between 3 and 20 (inclusive) consisting of lowercase
English letters. You have decided to choose some three consecutive characters
from S and make it his nickname. Print a string that is a valid nickname for
him. | [{"input": "takahashi", "output": "tak\n \n\n* * *"}, {"input": "naohiro", "output": "nao"}] |
Print your answer.
* * * | s478193470 | Runtime Error | p02645 | Input is given from Standard Input in the following format:
S | print(input[:3])
| Statement
When you asked some guy in your class his name, he called himself S, where S
is a string of length between 3 and 20 (inclusive) consisting of lowercase
English letters. You have decided to choose some three consecutive characters
from S and make it his nickname. Print a string that is a valid nickname for
him. | [{"input": "takahashi", "output": "tak\n \n\n* * *"}, {"input": "naohiro", "output": "nao"}] |
Print your answer.
* * * | s871455866 | Accepted | p02645 | Input is given from Standard Input in the following format:
S | T = str(input())
print(T[0:3])
| Statement
When you asked some guy in your class his name, he called himself S, where S
is a string of length between 3 and 20 (inclusive) consisting of lowercase
English letters. You have decided to choose some three consecutive characters
from S and make it his nickname. Print a string that is a valid nickname for
him. | [{"input": "takahashi", "output": "tak\n \n\n* * *"}, {"input": "naohiro", "output": "nao"}] |
Print your answer.
* * * | s264928586 | Runtime Error | p02645 | Input is given from Standard Input in the following format:
S | n = "NO"
y = "YES"
A, V = map(int, input().split()) # Aは初期座標 Vは1秒あたりの移動距離#
B, W = map(int, input().split()) # Aは初期座標 Wは1秒あたりの移動距離#
T = int(input()) # 移動許可秒数#
##################################################
# 答えはT秒後に鬼が逃げ役と同じ座標or追い越せばYES#
# 計算はTLE対策として掛け算を使用 #
# V,W * T でT秒間の移動距離を算出 #
# ANS = A,B + V,W * T #
##################################################
X = V * T
Y = W * T
A += X
B += Y
if B > A:
print(y)
else:
print(n)
| Statement
When you asked some guy in your class his name, he called himself S, where S
is a string of length between 3 and 20 (inclusive) consisting of lowercase
English letters. You have decided to choose some three consecutive characters
from S and make it his nickname. Print a string that is a valid nickname for
him. | [{"input": "takahashi", "output": "tak\n \n\n* * *"}, {"input": "naohiro", "output": "nao"}] |
Print your answer.
* * * | s556172742 | Wrong Answer | p02645 | Input is given from Standard Input in the following format:
S | name = input("What's your name?")
nickname = name[0:2]
| Statement
When you asked some guy in your class his name, he called himself S, where S
is a string of length between 3 and 20 (inclusive) consisting of lowercase
English letters. You have decided to choose some three consecutive characters
from S and make it his nickname. Print a string that is a valid nickname for
him. | [{"input": "takahashi", "output": "tak\n \n\n* * *"}, {"input": "naohiro", "output": "nao"}] |
Print your answer.
* * * | s767264848 | Accepted | p02645 | Input is given from Standard Input in the following format:
S | word = input()
nick = word[0] + word[1] + word[2]
print(nick)
| Statement
When you asked some guy in your class his name, he called himself S, where S
is a string of length between 3 and 20 (inclusive) consisting of lowercase
English letters. You have decided to choose some three consecutive characters
from S and make it his nickname. Print a string that is a valid nickname for
him. | [{"input": "takahashi", "output": "tak\n \n\n* * *"}, {"input": "naohiro", "output": "nao"}] |
Print your answer.
* * * | s961589589 | Accepted | p02645 | Input is given from Standard Input in the following format:
S | print(input()[:3:])
| Statement
When you asked some guy in your class his name, he called himself S, where S
is a string of length between 3 and 20 (inclusive) consisting of lowercase
English letters. You have decided to choose some three consecutive characters
from S and make it his nickname. Print a string that is a valid nickname for
him. | [{"input": "takahashi", "output": "tak\n \n\n* * *"}, {"input": "naohiro", "output": "nao"}] |
Print your answer.
* * * | s990068972 | Accepted | p02645 | Input is given from Standard Input in the following format:
S | s = list(str(input()))
ln = []
ln.append(s[0])
ln.append(s[1])
ln.append(s[2])
print("".join(ln))
| Statement
When you asked some guy in your class his name, he called himself S, where S
is a string of length between 3 and 20 (inclusive) consisting of lowercase
English letters. You have decided to choose some three consecutive characters
from S and make it his nickname. Print a string that is a valid nickname for
him. | [{"input": "takahashi", "output": "tak\n \n\n* * *"}, {"input": "naohiro", "output": "nao"}] |
Print your answer.
* * * | s484897053 | Accepted | p02645 | Input is given from Standard Input in the following format:
S | S = list(input())
name = []
name.append(S[0])
name.append(S[1])
name.append(S[2])
print("".join(name))
| Statement
When you asked some guy in your class his name, he called himself S, where S
is a string of length between 3 and 20 (inclusive) consisting of lowercase
English letters. You have decided to choose some three consecutive characters
from S and make it his nickname. Print a string that is a valid nickname for
him. | [{"input": "takahashi", "output": "tak\n \n\n* * *"}, {"input": "naohiro", "output": "nao"}] |
Print your answer.
* * * | s790766139 | Wrong Answer | p02645 | Input is given from Standard Input in the following format:
S | s = "This is a pen."
n = 1
m = 4
print(s[n - 1 : n - 1 + m]) # 'This'
print(s[0:4]) # 'This'
print(s[-4:-1]) # 'pen'
| Statement
When you asked some guy in your class his name, he called himself S, where S
is a string of length between 3 and 20 (inclusive) consisting of lowercase
English letters. You have decided to choose some three consecutive characters
from S and make it his nickname. Print a string that is a valid nickname for
him. | [{"input": "takahashi", "output": "tak\n \n\n* * *"}, {"input": "naohiro", "output": "nao"}] |
Print your answer.
* * * | s132490667 | Accepted | p02645 | Input is given from Standard Input in the following format:
S | nm = input()
print(nm[:3])
| Statement
When you asked some guy in your class his name, he called himself S, where S
is a string of length between 3 and 20 (inclusive) consisting of lowercase
English letters. You have decided to choose some three consecutive characters
from S and make it his nickname. Print a string that is a valid nickname for
him. | [{"input": "takahashi", "output": "tak\n \n\n* * *"}, {"input": "naohiro", "output": "nao"}] |
Output should be in the following format:
* In the first line, print integers h and w representing the size of the grid you constructed, with a space in between.
* Then, print h more lines. The i-th (1 \leq i \leq h) of these lines should contain a string s_i as follows:
* If the square at the i-th row and j-th column (1 \leq j \leq w) in the grid is painted white, the j-th character in s_i should be `.`.
* If the square at the i-th row and j-th column (1 \leq j \leq w) in the grid is painted black, the j-th character in s_i should be `#`.
* * * | s354535247 | Accepted | p03404 | Input is given from Standard Input in the following format:
A B | def examA():
C = [SI() for _ in range(3)]
ans = C[0][0] + C[1][1] + C[2][2]
print(ans)
return
def examB():
N, M = LI()
P = [0] * N
S = [LSI() for _ in range(M)]
pena = 0
ac = set()
for p, s in S:
p = int(p) - 1
if s == "WA":
P[p] += 1
else:
if p in ac:
continue
ac.add(p)
pena += P[p]
print(len(ac), pena)
return
def examC():
W, H, N = LI()
lx, rx, ly, ry = 0, W, 0, H
A = [LI() for _ in range(N)]
for x, y, a in A:
if a == 1:
lx = max(lx, x)
elif a == 2:
rx = min(rx, x)
elif a == 3:
ly = max(ly, y)
elif a == 4:
ry = min(ry, y)
ans = max(0, rx - lx) * max(0, ry - ly)
print(ans)
return
def examD():
N, H = LI()
B = [0] * N
maxa = 0
ans = 0
for i in range(N):
a, B[i] = LI()
if a > maxa:
maxa = a
B.sort(reverse=True)
for b in B:
if b < maxa:
break
H -= b
ans += 1
if H <= 0:
print(ans)
return
ans += -(-H // maxa)
print(ans)
return
def examE():
A, B = LI()
ans = [["#"] * 100 for _ in range(50)] + [["."] * 100 for _ in range(50)]
i = 0
j = 0
for _ in range(A - 1):
ans[i][j] = "."
j += 2
if j >= 100:
j = 0
i += 2
i = 0
j = 0
for _ in range(B - 1):
ans[99 - i][j] = "#"
j += 2
if j >= 100:
j = 0
i += 2
print(100, 100)
for v in ans:
print("".join(map(str, v)))
return
def examF():
ans = 0
print(ans)
return
import sys, bisect, itertools, heapq, math, random
from copy import deepcopy
from heapq import heappop, heappush, heapify
from collections import Counter, defaultdict, deque
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
def I():
return int(readline())
def LI():
return list(map(int, readline().split()))
def LSI():
return list(map(str, sys.stdin.readline().split()))
def LS():
return sys.stdin.readline().split()
def SI():
return sys.stdin.readline().strip()
global mod, mod2, inf, alphabet, _ep
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
_ep = 10 ** (-12)
alphabet = [chr(ord("a") + i) for i in range(26)]
sys.setrecursionlimit(10**7)
if __name__ == "__main__":
examE()
"""
142
12 9 1445 0 1
asd dfg hj o o
aidn
"""
| Statement
You are given two integers A and B.
Print a grid where each square is painted white or black that satisfies the
following conditions, in the format specified in Output section:
* Let the size of the grid be h \times w (h vertical, w horizontal). Both h and w are at most 100.
* The set of the squares painted white is divided into exactly A connected components.
* The set of the squares painted black is divided into exactly B connected components.
It can be proved that there always exist one or more solutions under the
conditions specified in Constraints section. If there are multiple solutions,
any of them may be printed. | [{"input": "2 3", "output": "3 3\n ##.\n ..#\n #.#\n \n\nThis output corresponds to the grid below:\n\n\n\n* * *"}, {"input": "7 8", "output": "3 5\n #.#.#\n .#.#.\n #.#.#\n \n\n* * *"}, {"input": "1 1", "output": "4 2\n ..\n #.\n ##\n ##\n \n\n* * *"}, {"input": "3 14", "output": "8 18\n ..................\n ..................\n ....##.......####.\n ....#.#.....#.....\n ...#...#....#.....\n ..#.###.#...#.....\n .#.......#..#.....\n #.........#..####."}] |
Output should be in the following format:
* In the first line, print integers h and w representing the size of the grid you constructed, with a space in between.
* Then, print h more lines. The i-th (1 \leq i \leq h) of these lines should contain a string s_i as follows:
* If the square at the i-th row and j-th column (1 \leq j \leq w) in the grid is painted white, the j-th character in s_i should be `.`.
* If the square at the i-th row and j-th column (1 \leq j \leq w) in the grid is painted black, the j-th character in s_i should be `#`.
* * * | s044113170 | Wrong Answer | p03404 | Input is given from Standard Input in the following format:
A B | import sys
import math
import copy
import random
from heapq import heappush, heappop, heapify
from functools import cmp_to_key
from bisect import bisect_left, bisect_right
from collections import defaultdict, deque, Counter
# sys.setrecursionlimit(1000000)
# input aliases
input = sys.stdin.readline
getS = lambda: input().strip()
getN = lambda: int(input())
getList = lambda: list(map(int, input().split()))
getZList = lambda: [int(x) - 1 for x in input().split()]
INF = float("inf")
MOD = 10**9 + 7
divide = lambda x: pow(x, MOD - 2, MOD)
def nck(n, k, kaijyo):
return (npk(n, k, kaijyo) * divide(kaijyo[k])) % MOD
def npk(n, k, kaijyo):
if k == 0 or k == n:
return n % MOD
return (kaijyo[n] * divide(kaijyo[n - k])) % MOD
def fact_and_inv(SIZE):
inv = [0] * SIZE # inv[j] = j^{-1} mod MOD
fac = [0] * SIZE # fac[j] = j! mod MOD
finv = [0] * SIZE # finv[j] = (j!)^{-1} mod MOD
inv[1] = 1
fac[0] = fac[1] = 1
finv[0] = finv[1] = 1
for i in range(2, SIZE):
inv[i] = MOD - (MOD // i) * inv[MOD % i] % MOD
fac[i] = fac[i - 1] * i % MOD
finv[i] = finv[i - 1] * inv[i] % MOD
return fac, finv
def renritsu(A, Y):
# example 2x + y = 3, x + 3y = 4
# A = [[2,1], [1,3]])
# Y = [[3],[4]] または [3,4]
A = np.matrix(A)
Y = np.matrix(Y)
Y = np.reshape(Y, (-1, 1))
X = np.linalg.solve(A, Y)
# [1.0, 1.0]
return X.flatten().tolist()[0]
class TwoDimGrid:
# 2次元座標 -> 1次元
def __init__(self, h, w, wall="#"):
self.h = h
self.w = w
self.size = (h + 2) * (w + 2)
self.wall = wall
self.get_grid()
# self.init_cost()
def get_grid(self):
grid = [self.wall * (self.w + 2)]
for i in range(self.h):
grid.append(self.wall + getS() + self.wall)
grid.append(self.wall * (self.w + 2))
self.grid = grid
def init_cost(self):
self.cost = [INF] * self.size
def pos(self, x, y):
# 壁も含めて0-indexed 元々の座標だけ考えると1-indexed
return y * (self.w + 2) + x
def getgrid(self, x, y):
return self.grid[y][x]
def get(self, x, y):
return self.cost[self.pos(x, y)]
def set(self, x, y, v):
self.cost[self.pos(x, y)] = v
return
def show(self):
for i in range(self.h + 2):
print(self.cost[(self.w + 2) * i : (self.w + 2) * (i + 1)])
def showsome(self, tgt):
for t in tgt:
print(t)
return
def showsomejoin(self, tgt):
for t in tgt:
print("".join(t))
return
def search(self):
grid = self.grid
move = [(0, 1), (0, -1), (1, 0), (-1, 0)]
move_eight = [
(0, 1),
(0, -1),
(1, 0),
(-1, 0),
(1, 1),
(1, -1),
(-1, 1),
(-1, -1),
]
# for i in range(1, self.h+1):
# for j in range(1, self.w+1):
# cx, cy = j, i
# for dx, dy in move_eight:
# nx, ny = dx + cx, dy + cy
def solve():
a, b = getList()
print(500, 500)
for i in range(500):
tmp = []
for j in range(500):
if i < 250:
if j % 2 == 1 or i % 2 == 1 or a <= 1:
tmp.append("#")
else:
tmp.append(".")
a -= 1
else:
if j % 2 == 1 or i % 2 == 0 or b <= 1:
tmp.append(".")
else:
tmp.append("#")
b -= 1
print("".join(tmp))
def main():
n = getN()
for _ in range(n):
s = "".join([random.choice(["F", "T"]) for i in range(20)])
print(s)
solve(s, 1, 0)
return
if __name__ == "__main__":
# main()
solve()
| Statement
You are given two integers A and B.
Print a grid where each square is painted white or black that satisfies the
following conditions, in the format specified in Output section:
* Let the size of the grid be h \times w (h vertical, w horizontal). Both h and w are at most 100.
* The set of the squares painted white is divided into exactly A connected components.
* The set of the squares painted black is divided into exactly B connected components.
It can be proved that there always exist one or more solutions under the
conditions specified in Constraints section. If there are multiple solutions,
any of them may be printed. | [{"input": "2 3", "output": "3 3\n ##.\n ..#\n #.#\n \n\nThis output corresponds to the grid below:\n\n\n\n* * *"}, {"input": "7 8", "output": "3 5\n #.#.#\n .#.#.\n #.#.#\n \n\n* * *"}, {"input": "1 1", "output": "4 2\n ..\n #.\n ##\n ##\n \n\n* * *"}, {"input": "3 14", "output": "8 18\n ..................\n ..................\n ....##.......####.\n ....#.#.....#.....\n ...#...#....#.....\n ..#.###.#...#.....\n .#.......#..#.....\n #.........#..####."}] |
Output should be in the following format:
* In the first line, print integers h and w representing the size of the grid you constructed, with a space in between.
* Then, print h more lines. The i-th (1 \leq i \leq h) of these lines should contain a string s_i as follows:
* If the square at the i-th row and j-th column (1 \leq j \leq w) in the grid is painted white, the j-th character in s_i should be `.`.
* If the square at the i-th row and j-th column (1 \leq j \leq w) in the grid is painted black, the j-th character in s_i should be `#`.
* * * | s658953519 | Wrong Answer | p03404 | Input is given from Standard Input in the following format:
A B | import string
import re
import datetime
import calendar
import collections
import heapq
import bisect
import array
import numpy as np
a, b = map(int, input().split())
ans = np.empty((100, 100), dtype=int)
x, y = ans.shape
for i in range(x):
for j in range(y):
if j == 0:
ans[i, j] = 1
elif j == y - 1:
ans[i, j] = 0
elif (i % 4) == 0 or (i % 4) == 1:
ans[i, j] = 1
else:
ans[i, j] = 0
def cut_b():
itr = 1
for i in range(2, x, 4):
for j in range(2, y // 2, 2):
yield itr
ans[i, j] = ans[i + 1, j] = 1
itr += 1
def cut_w():
itr = 1
for i in range(0, x, 4):
for j in range(-3, -y // 2, -2):
yield itr
ans[i, j] = ans[i + 1, j] = 0
itr += 1
for i in cut_b():
if i == a:
break
for i in cut_w():
if i == b:
break
for i in range(x):
for j in range(y):
if ans[i, j] == 0:
print(".", end="")
else:
print("#", end="")
print()
| Statement
You are given two integers A and B.
Print a grid where each square is painted white or black that satisfies the
following conditions, in the format specified in Output section:
* Let the size of the grid be h \times w (h vertical, w horizontal). Both h and w are at most 100.
* The set of the squares painted white is divided into exactly A connected components.
* The set of the squares painted black is divided into exactly B connected components.
It can be proved that there always exist one or more solutions under the
conditions specified in Constraints section. If there are multiple solutions,
any of them may be printed. | [{"input": "2 3", "output": "3 3\n ##.\n ..#\n #.#\n \n\nThis output corresponds to the grid below:\n\n\n\n* * *"}, {"input": "7 8", "output": "3 5\n #.#.#\n .#.#.\n #.#.#\n \n\n* * *"}, {"input": "1 1", "output": "4 2\n ..\n #.\n ##\n ##\n \n\n* * *"}, {"input": "3 14", "output": "8 18\n ..................\n ..................\n ....##.......####.\n ....#.#.....#.....\n ...#...#....#.....\n ..#.###.#...#.....\n .#.......#..#.....\n #.........#..####."}] |
Output should be in the following format:
* In the first line, print integers h and w representing the size of the grid you constructed, with a space in between.
* Then, print h more lines. The i-th (1 \leq i \leq h) of these lines should contain a string s_i as follows:
* If the square at the i-th row and j-th column (1 \leq j \leq w) in the grid is painted white, the j-th character in s_i should be `.`.
* If the square at the i-th row and j-th column (1 \leq j \leq w) in the grid is painted black, the j-th character in s_i should be `#`.
* * * | s816874773 | Wrong Answer | p03404 | Input is given from Standard Input in the following format:
A B | a, b = map(int, input().split())
white = "." * 100
black = "#" * 100
wb = ".#" * 50
ban = []
num_b = b - 1
num_a = a - 1
gyo_b = num_b // 50
ret_b = num_b % 50
gyo_a = num_a // 50
ret_a = num_a % 50
for i in range(gyo_a):
ban.append(wb)
ban.append(white)
ban.append((".#" * ret_a + (".." * (50 - ret_a))))
ban.append(white)
for i in range(50 - 2 * (gyo_a + 1)):
ban.append(white)
for i in range(50 - 2 * (gyo_b + 1)):
ban.append(black)
for i in range(gyo_b):
ban.append(wb)
ban.append(black)
ban.append(".#" * ret_b + "##" * (50 - ret_b))
ban.append(black)
for item in ban:
print("".join(item))
| Statement
You are given two integers A and B.
Print a grid where each square is painted white or black that satisfies the
following conditions, in the format specified in Output section:
* Let the size of the grid be h \times w (h vertical, w horizontal). Both h and w are at most 100.
* The set of the squares painted white is divided into exactly A connected components.
* The set of the squares painted black is divided into exactly B connected components.
It can be proved that there always exist one or more solutions under the
conditions specified in Constraints section. If there are multiple solutions,
any of them may be printed. | [{"input": "2 3", "output": "3 3\n ##.\n ..#\n #.#\n \n\nThis output corresponds to the grid below:\n\n\n\n* * *"}, {"input": "7 8", "output": "3 5\n #.#.#\n .#.#.\n #.#.#\n \n\n* * *"}, {"input": "1 1", "output": "4 2\n ..\n #.\n ##\n ##\n \n\n* * *"}, {"input": "3 14", "output": "8 18\n ..................\n ..................\n ....##.......####.\n ....#.#.....#.....\n ...#...#....#.....\n ..#.###.#...#.....\n .#.......#..#.....\n #.........#..####."}] |
Output should be in the following format:
* In the first line, print integers h and w representing the size of the grid you constructed, with a space in between.
* Then, print h more lines. The i-th (1 \leq i \leq h) of these lines should contain a string s_i as follows:
* If the square at the i-th row and j-th column (1 \leq j \leq w) in the grid is painted white, the j-th character in s_i should be `.`.
* If the square at the i-th row and j-th column (1 \leq j \leq w) in the grid is painted black, the j-th character in s_i should be `#`.
* * * | s622196612 | Accepted | p03404 | Input is given from Standard Input in the following format:
A B | import sys
# import math
# import bisect
# import numpy as np
# from decimal import Decimal
# from numba import njit, i8, u1, b1 #JIT compiler
# from itertools import combinations, product
# from collections import Counter, deque, defaultdict
# sys.setrecursionlimit(10 ** 6)
MOD = 10**9 + 7
INF = 10**9
PI = 3.14159265358979323846
def read_str():
return sys.stdin.readline().strip()
def read_int():
return int(sys.stdin.readline().strip())
def read_ints():
return map(int, sys.stdin.readline().strip().split())
def read_ints2(x):
return map(lambda num: int(num) - x, sys.stdin.readline().strip().split())
def read_str_list():
return list(sys.stdin.readline().strip().split())
def read_int_list():
return list(map(int, sys.stdin.readline().strip().split()))
def GCD(a: int, b: int) -> int:
return b if a % b == 0 else GCD(b, a % b)
def LCM(a: int, b: int) -> int:
return (a * b) // GCD(a, b)
def Main():
a, b = read_ints()
print(100, 100)
grid = [["#"] * 100 for _ in range(50)] + [["."] * 100 for _ in range(50)]
for i in range(~-a):
x, y = divmod(i, 49)
grid[x * 2 + 1][y * 2 + 1] = "."
for i in range(~-b):
x, y = divmod(i, 49)
grid[x * 2 + 51][y * 2 + 1] = "#"
print(*["".join(g) for g in grid], sep="\n")
if __name__ == "__main__":
Main()
| Statement
You are given two integers A and B.
Print a grid where each square is painted white or black that satisfies the
following conditions, in the format specified in Output section:
* Let the size of the grid be h \times w (h vertical, w horizontal). Both h and w are at most 100.
* The set of the squares painted white is divided into exactly A connected components.
* The set of the squares painted black is divided into exactly B connected components.
It can be proved that there always exist one or more solutions under the
conditions specified in Constraints section. If there are multiple solutions,
any of them may be printed. | [{"input": "2 3", "output": "3 3\n ##.\n ..#\n #.#\n \n\nThis output corresponds to the grid below:\n\n\n\n* * *"}, {"input": "7 8", "output": "3 5\n #.#.#\n .#.#.\n #.#.#\n \n\n* * *"}, {"input": "1 1", "output": "4 2\n ..\n #.\n ##\n ##\n \n\n* * *"}, {"input": "3 14", "output": "8 18\n ..................\n ..................\n ....##.......####.\n ....#.#.....#.....\n ...#...#....#.....\n ..#.###.#...#.....\n .#.......#..#.....\n #.........#..####."}] |
Output should be in the following format:
* In the first line, print integers h and w representing the size of the grid you constructed, with a space in between.
* Then, print h more lines. The i-th (1 \leq i \leq h) of these lines should contain a string s_i as follows:
* If the square at the i-th row and j-th column (1 \leq j \leq w) in the grid is painted white, the j-th character in s_i should be `.`.
* If the square at the i-th row and j-th column (1 \leq j \leq w) in the grid is painted black, the j-th character in s_i should be `#`.
* * * | s646951825 | Wrong Answer | p03404 | Input is given from Standard Input in the following format:
A B | def main():
a, b = map(int, input().split())
s, k = ".#"
ans = [[k] * 100 for _ in range(50)] + [[s] * 100 for _ in range(50)]
col = 0
row = 0
for _ in range(a - 1):
ans[row][col] = s
col += 2
if col == 100:
col = 0
row += 2
col = 0
row = 99
for _ in range(a - 1):
ans[row][col] = k
col += 2
if col == 100:
col = 0
row -= 2
print(100, 100)
for row in ans:
print("".join(row))
if __name__ == "__main__":
main()
| Statement
You are given two integers A and B.
Print a grid where each square is painted white or black that satisfies the
following conditions, in the format specified in Output section:
* Let the size of the grid be h \times w (h vertical, w horizontal). Both h and w are at most 100.
* The set of the squares painted white is divided into exactly A connected components.
* The set of the squares painted black is divided into exactly B connected components.
It can be proved that there always exist one or more solutions under the
conditions specified in Constraints section. If there are multiple solutions,
any of them may be printed. | [{"input": "2 3", "output": "3 3\n ##.\n ..#\n #.#\n \n\nThis output corresponds to the grid below:\n\n\n\n* * *"}, {"input": "7 8", "output": "3 5\n #.#.#\n .#.#.\n #.#.#\n \n\n* * *"}, {"input": "1 1", "output": "4 2\n ..\n #.\n ##\n ##\n \n\n* * *"}, {"input": "3 14", "output": "8 18\n ..................\n ..................\n ....##.......####.\n ....#.#.....#.....\n ...#...#....#.....\n ..#.###.#...#.....\n .#.......#..#.....\n #.........#..####."}] |
Output should be in the following format:
* In the first line, print integers h and w representing the size of the grid you constructed, with a space in between.
* Then, print h more lines. The i-th (1 \leq i \leq h) of these lines should contain a string s_i as follows:
* If the square at the i-th row and j-th column (1 \leq j \leq w) in the grid is painted white, the j-th character in s_i should be `.`.
* If the square at the i-th row and j-th column (1 \leq j \leq w) in the grid is painted black, the j-th character in s_i should be `#`.
* * * | s082877113 | Runtime Error | p03404 | Input is given from Standard Input in the following format:
A B | A,B = map(int,input().split())
n = 50
m = n*2
grid = []
for i in range(n):
grid.append([‘.’] * m)
for i in range(n):
grid.append([‘#’] * m)
x = 0
y = 0
for i in range(B-1):
grid[y][x] = ‘#’
x += 2
if x >= m:
x -= m
y += 2
x = 0
y = n+1
for i in range(A-1):
grid[y][x] = ‘.’
x += 2
if x >= m:
x -= m
y += 2
print(str(m) + ‘ ‘ + str(m))
for row in grid:
print(‘’.join(row)) | Statement
You are given two integers A and B.
Print a grid where each square is painted white or black that satisfies the
following conditions, in the format specified in Output section:
* Let the size of the grid be h \times w (h vertical, w horizontal). Both h and w are at most 100.
* The set of the squares painted white is divided into exactly A connected components.
* The set of the squares painted black is divided into exactly B connected components.
It can be proved that there always exist one or more solutions under the
conditions specified in Constraints section. If there are multiple solutions,
any of them may be printed. | [{"input": "2 3", "output": "3 3\n ##.\n ..#\n #.#\n \n\nThis output corresponds to the grid below:\n\n\n\n* * *"}, {"input": "7 8", "output": "3 5\n #.#.#\n .#.#.\n #.#.#\n \n\n* * *"}, {"input": "1 1", "output": "4 2\n ..\n #.\n ##\n ##\n \n\n* * *"}, {"input": "3 14", "output": "8 18\n ..................\n ..................\n ....##.......####.\n ....#.#.....#.....\n ...#...#....#.....\n ..#.###.#...#.....\n .#.......#..#.....\n #.........#..####."}] |
Output should be in the following format:
* In the first line, print integers h and w representing the size of the grid you constructed, with a space in between.
* Then, print h more lines. The i-th (1 \leq i \leq h) of these lines should contain a string s_i as follows:
* If the square at the i-th row and j-th column (1 \leq j \leq w) in the grid is painted white, the j-th character in s_i should be `.`.
* If the square at the i-th row and j-th column (1 \leq j \leq w) in the grid is painted black, the j-th character in s_i should be `#`.
* * * | s052027357 | Wrong Answer | p03404 | Input is given from Standard Input in the following format:
A B | tmp = list(map(int, input().split()))
a, b = tmp[0], tmp[1]
if a == b:
print(a * 2, 2)
for i in range(a):
print("###")
print("...")
else:
if a > b:
x = ".."
y = "##"
z = ".#"
elif a < b:
a, b = b, a
x = "##"
y = ".."
z = "#."
print(a * 2, 2)
for i in range(b):
print(x)
print(y)
for i in range(a - b):
print(y)
print(z)
| Statement
You are given two integers A and B.
Print a grid where each square is painted white or black that satisfies the
following conditions, in the format specified in Output section:
* Let the size of the grid be h \times w (h vertical, w horizontal). Both h and w are at most 100.
* The set of the squares painted white is divided into exactly A connected components.
* The set of the squares painted black is divided into exactly B connected components.
It can be proved that there always exist one or more solutions under the
conditions specified in Constraints section. If there are multiple solutions,
any of them may be printed. | [{"input": "2 3", "output": "3 3\n ##.\n ..#\n #.#\n \n\nThis output corresponds to the grid below:\n\n\n\n* * *"}, {"input": "7 8", "output": "3 5\n #.#.#\n .#.#.\n #.#.#\n \n\n* * *"}, {"input": "1 1", "output": "4 2\n ..\n #.\n ##\n ##\n \n\n* * *"}, {"input": "3 14", "output": "8 18\n ..................\n ..................\n ....##.......####.\n ....#.#.....#.....\n ...#...#....#.....\n ..#.###.#...#.....\n .#.......#..#.....\n #.........#..####."}] |
Output should be in the following format:
* In the first line, print integers h and w representing the size of the grid you constructed, with a space in between.
* Then, print h more lines. The i-th (1 \leq i \leq h) of these lines should contain a string s_i as follows:
* If the square at the i-th row and j-th column (1 \leq j \leq w) in the grid is painted white, the j-th character in s_i should be `.`.
* If the square at the i-th row and j-th column (1 \leq j \leq w) in the grid is painted black, the j-th character in s_i should be `#`.
* * * | s432281986 | Wrong Answer | p03404 | Input is given from Standard Input in the following format:
A B | a, b = map(int, input().split())
a_line = (a - 1) // 50 + 1
b_line = (b - 1) // 50 + 1
for i in range(a_line):
if i != a_line - 1:
print(".#" * 2 + ".")
else:
print(".#" * ((a - 1) % 50) + "##" * (50 - (a - 1) % 50))
print("#" * 100)
for i in range(b_line):
print("." * 100)
if i != b_line - 1:
print("#." * 2 + ".")
else:
print("#." * ((b - 1) % 50) + ".." * (50 - (b - 1) % 50))
| Statement
You are given two integers A and B.
Print a grid where each square is painted white or black that satisfies the
following conditions, in the format specified in Output section:
* Let the size of the grid be h \times w (h vertical, w horizontal). Both h and w are at most 100.
* The set of the squares painted white is divided into exactly A connected components.
* The set of the squares painted black is divided into exactly B connected components.
It can be proved that there always exist one or more solutions under the
conditions specified in Constraints section. If there are multiple solutions,
any of them may be printed. | [{"input": "2 3", "output": "3 3\n ##.\n ..#\n #.#\n \n\nThis output corresponds to the grid below:\n\n\n\n* * *"}, {"input": "7 8", "output": "3 5\n #.#.#\n .#.#.\n #.#.#\n \n\n* * *"}, {"input": "1 1", "output": "4 2\n ..\n #.\n ##\n ##\n \n\n* * *"}, {"input": "3 14", "output": "8 18\n ..................\n ..................\n ....##.......####.\n ....#.#.....#.....\n ...#...#....#.....\n ..#.###.#...#.....\n .#.......#..#.....\n #.........#..####."}] |
Output should be in the following format:
* In the first line, print integers h and w representing the size of the grid you constructed, with a space in between.
* Then, print h more lines. The i-th (1 \leq i \leq h) of these lines should contain a string s_i as follows:
* If the square at the i-th row and j-th column (1 \leq j \leq w) in the grid is painted white, the j-th character in s_i should be `.`.
* If the square at the i-th row and j-th column (1 \leq j \leq w) in the grid is painted black, the j-th character in s_i should be `#`.
* * * | s485602292 | Wrong Answer | p03404 | Input is given from Standard Input in the following format:
A B | import math
def make_divisors(n):
divisors = []
for i in range(1, int(n**0.5) + 1):
if n % i == 0:
divisors.append(i)
if i != n // i:
divisors.append(n // i)
divisors.sort()
return divisors
li = [".", "#"]
A, B = [int(x) for x in input().split()]
h = math.ceil((2 * max(A, B)) ** 0.5)
if (A - B) % 2 == 1:
h += 1 - h % 2
w = h
start = 0
if A > B:
start = 1
if max(A, B) == min(A, B) + 1:
start = 1
if A > B:
start = 0
d = make_divisors(A + B)
for i in d:
if i <= 100 and (A + B) // i <= 100:
h = i
w = (A + B) // i
print(h, w)
for i in range(h):
pr = ""
for j in range(w):
pr += li[start]
start = 1 - start
print(pr)
else:
n = math.ceil((max(A, B) - min(A, B)) / 2)
hw = (max(A, B) + n) * 2
d = make_divisors(hw)
for i in d:
if 2 < i <= 100 and 2 < hw // i <= 100:
h = i
w = (A + B) // i
print(h, w)
for i in range(h):
if w % 2 == 0:
start = 1 - start
pr = ""
for j in range(w):
if i % 2 == 1 and j % 2 == 1 and n > 0:
pr += pr[-1]
else:
pr += li[start]
start = 1 - start
print(pr)
| Statement
You are given two integers A and B.
Print a grid where each square is painted white or black that satisfies the
following conditions, in the format specified in Output section:
* Let the size of the grid be h \times w (h vertical, w horizontal). Both h and w are at most 100.
* The set of the squares painted white is divided into exactly A connected components.
* The set of the squares painted black is divided into exactly B connected components.
It can be proved that there always exist one or more solutions under the
conditions specified in Constraints section. If there are multiple solutions,
any of them may be printed. | [{"input": "2 3", "output": "3 3\n ##.\n ..#\n #.#\n \n\nThis output corresponds to the grid below:\n\n\n\n* * *"}, {"input": "7 8", "output": "3 5\n #.#.#\n .#.#.\n #.#.#\n \n\n* * *"}, {"input": "1 1", "output": "4 2\n ..\n #.\n ##\n ##\n \n\n* * *"}, {"input": "3 14", "output": "8 18\n ..................\n ..................\n ....##.......####.\n ....#.#.....#.....\n ...#...#....#.....\n ..#.###.#...#.....\n .#.......#..#.....\n #.........#..####."}] |
Output should be in the following format:
* In the first line, print integers h and w representing the size of the grid you constructed, with a space in between.
* Then, print h more lines. The i-th (1 \leq i \leq h) of these lines should contain a string s_i as follows:
* If the square at the i-th row and j-th column (1 \leq j \leq w) in the grid is painted white, the j-th character in s_i should be `.`.
* If the square at the i-th row and j-th column (1 \leq j \leq w) in the grid is painted black, the j-th character in s_i should be `#`.
* * * | s949055915 | Runtime Error | p03404 | Input is given from Standard Input in the following format:
A B | def main():
BK = "#"
WH = "."
A, B = map(int, input().split())
g = []
for _ in range(50):
g.append([BK] * 50)
for _ in range(50):
g.append([WH] * 50)
r, c = 1, 1
for w_cnt in range(A - 1):
g[r][c] = WH
c += 2
if c > 99:
c = 1
r += 2
r, c = 51, 1
for b_cnt in range(B - 1):
g[r][c] = BK
c += 2
if c > 99:
c = 1
r += 2
print(100, 100)
for row in g:
print(*row, sep="")
if __name__ == "__main__":
main()
| Statement
You are given two integers A and B.
Print a grid where each square is painted white or black that satisfies the
following conditions, in the format specified in Output section:
* Let the size of the grid be h \times w (h vertical, w horizontal). Both h and w are at most 100.
* The set of the squares painted white is divided into exactly A connected components.
* The set of the squares painted black is divided into exactly B connected components.
It can be proved that there always exist one or more solutions under the
conditions specified in Constraints section. If there are multiple solutions,
any of them may be printed. | [{"input": "2 3", "output": "3 3\n ##.\n ..#\n #.#\n \n\nThis output corresponds to the grid below:\n\n\n\n* * *"}, {"input": "7 8", "output": "3 5\n #.#.#\n .#.#.\n #.#.#\n \n\n* * *"}, {"input": "1 1", "output": "4 2\n ..\n #.\n ##\n ##\n \n\n* * *"}, {"input": "3 14", "output": "8 18\n ..................\n ..................\n ....##.......####.\n ....#.#.....#.....\n ...#...#....#.....\n ..#.###.#...#.....\n .#.......#..#.....\n #.........#..####."}] |
If the piece will remain on the grid at the end of the game, print `YES`;
otherwise, print `NO`.
* * * | s656483619 | Accepted | p03054 | Input is given from Standard Input in the following format:
H W N
s_r s_c
S
T | import sys
input = sys.stdin.buffer.readline
# sys.setrecursionlimit(10**9)
# from functools import lru_cache
def RD():
return input().rstrip().decode()
def II():
return int(input())
def FI():
return float(input())
def MI():
return map(int, input().split())
def MF():
return map(float, input().split())
def LI():
return list(map(int, input().split()))
def LF():
return list(map(float, input().split()))
def TI():
return tuple(map(int, input().split()))
# rstrip().decode()
def main():
h, w, n = MI()
sr, sc = MI()
S = RD()
T = RD()
ans = "YES"
# Rの検証
x = w - sc + 1
for i, j in zip(S, T):
if i == "R":
x -= 1
if x == 0:
ans = "NO"
if j == "L":
if x < w:
x += 1
# Lの検証
x = sc
for i, j in zip(S, T):
if i == "L":
x -= 1
if x == 0:
ans = "NO"
if j == "R":
if x < w:
x += 1
# Dの検証
x = h - sr + 1
for i, j in zip(S, T):
if i == "D":
x -= 1
if x == 0:
ans = "NO"
if j == "U":
if x < h:
x += 1
# Uの検証
x = sr
for i, j in zip(S, T):
if i == "U":
x -= 1
if x == 0:
ans = "NO"
if j == "D":
if x < h:
x += 1
print(ans)
if __name__ == "__main__":
main()
| Statement
We have a rectangular grid of squares with H horizontal rows and W vertical
columns. Let (i,j) denote the square at the i-th row from the top and the j-th
column from the left. On this grid, there is a piece, which is initially
placed at square (s_r,s_c).
Takahashi and Aoki will play a game, where each player has a string of length
N. Takahashi's string is S, and Aoki's string is T. S and T both consist of
four kinds of letters: `L`, `R`, `U` and `D`.
The game consists of N steps. The i-th step proceeds as follows:
* First, Takahashi performs a move. He either moves the piece in the direction of S_i, or does not move the piece.
* Second, Aoki performs a move. He either moves the piece in the direction of T_i, or does not move the piece.
Here, to move the piece in the direction of `L`, `R`, `U` and `D`, is to move
the piece from square (r,c) to square (r,c-1), (r,c+1), (r-1,c) and (r+1,c),
respectively. If the destination square does not exist, the piece is removed
from the grid, and the game ends, even if less than N steps are done.
Takahashi wants to remove the piece from the grid in one of the N steps. Aoki,
on the other hand, wants to finish the N steps with the piece remaining on the
grid. Determine if the piece will remain on the grid at the end of the game
when both players play optimally. | [{"input": "2 3 3\n 2 2\n RRL\n LUD", "output": "YES\n \n\nHere is one possible progress of the game:\n\n * Takahashi moves the piece right. The piece is now at (2,3).\n * Aoki moves the piece left. The piece is now at (2,2).\n * Takahashi does not move the piece. The piece remains at (2,2).\n * Aoki moves the piece up. The piece is now at (1,2).\n * Takahashi moves the piece left. The piece is now at (1,1).\n * Aoki does not move the piece. The piece remains at (1,1).\n\n* * *"}, {"input": "4 3 5\n 2 2\n UDRRR\n LLDUD", "output": "NO\n \n\n* * *"}, {"input": "5 6 11\n 2 1\n RLDRRUDDLRL\n URRDRLLDLRD", "output": "NO"}] |
If the piece will remain on the grid at the end of the game, print `YES`;
otherwise, print `NO`.
* * * | s719324998 | Wrong Answer | p03054 | Input is given from Standard Input in the following format:
H W N
s_r s_c
S
T | def solve():
H, W, N = map(int, input().split())
sr, sc = map(int, input().split())
S = list(input())
T = list(input())
# to left
vec = "L"
anv = "R"
border = 1
winner = "YES"
result = sc
addition = -1
out_mass_func = lambda x: x < border
for i in range(len(S)):
if S[i] == vec:
result += addition
if out_mass_func(result):
winner = "NO"
break
if T[i] == anv and result < border:
result -= addition
# print('left', result)
# to right
if winner == "YES":
vec = "R"
anv = "L"
border = W
winner = "YES"
result = sc
addition = 1
out_mass_func = lambda x: x > border
for i in range(len(S)):
if S[i] == vec:
result += addition
if out_mass_func(result):
winner = "NO"
break
if T[i] == anv and (1 < result):
result -= addition
# print('right', result)
# to top
if winner == "YES":
vec = "U"
anv = "D"
border = 1
winner = "YES"
result = sr
addition = -1
out_mass_func = lambda x: x < border
for i in range(len(S)):
if S[i] == vec:
result += addition
if out_mass_func(result):
winner = "NO"
break
if T[i] == anv and (result < border):
result -= addition
# print('top', result)
# to bottom
if winner == "YES":
vec = "D"
anv = "U"
border = H
winner = "YES"
result = sr
addition = 1
out_mass_func = lambda x: x > border
for i in range(len(S)):
if S[i] == vec:
result += addition
if out_mass_func(result):
winner = "NO"
break
if T[i] == anv and 1 < result:
result -= addition
# print('bottom', result)
print(winner)
if __name__ == "__main__":
solve()
| Statement
We have a rectangular grid of squares with H horizontal rows and W vertical
columns. Let (i,j) denote the square at the i-th row from the top and the j-th
column from the left. On this grid, there is a piece, which is initially
placed at square (s_r,s_c).
Takahashi and Aoki will play a game, where each player has a string of length
N. Takahashi's string is S, and Aoki's string is T. S and T both consist of
four kinds of letters: `L`, `R`, `U` and `D`.
The game consists of N steps. The i-th step proceeds as follows:
* First, Takahashi performs a move. He either moves the piece in the direction of S_i, or does not move the piece.
* Second, Aoki performs a move. He either moves the piece in the direction of T_i, or does not move the piece.
Here, to move the piece in the direction of `L`, `R`, `U` and `D`, is to move
the piece from square (r,c) to square (r,c-1), (r,c+1), (r-1,c) and (r+1,c),
respectively. If the destination square does not exist, the piece is removed
from the grid, and the game ends, even if less than N steps are done.
Takahashi wants to remove the piece from the grid in one of the N steps. Aoki,
on the other hand, wants to finish the N steps with the piece remaining on the
grid. Determine if the piece will remain on the grid at the end of the game
when both players play optimally. | [{"input": "2 3 3\n 2 2\n RRL\n LUD", "output": "YES\n \n\nHere is one possible progress of the game:\n\n * Takahashi moves the piece right. The piece is now at (2,3).\n * Aoki moves the piece left. The piece is now at (2,2).\n * Takahashi does not move the piece. The piece remains at (2,2).\n * Aoki moves the piece up. The piece is now at (1,2).\n * Takahashi moves the piece left. The piece is now at (1,1).\n * Aoki does not move the piece. The piece remains at (1,1).\n\n* * *"}, {"input": "4 3 5\n 2 2\n UDRRR\n LLDUD", "output": "NO\n \n\n* * *"}, {"input": "5 6 11\n 2 1\n RLDRRUDDLRL\n URRDRLLDLRD", "output": "NO"}] |
If the piece will remain on the grid at the end of the game, print `YES`;
otherwise, print `NO`.
* * * | s189602189 | Wrong Answer | p03054 | Input is given from Standard Input in the following format:
H W N
s_r s_c
S
T | from sys import exit
from collections import defaultdict
H, W, N = [int(n) for n in input().split()]
Sr, Sc = [int(n) for n in input().split()]
# 上に
Uout = H - Sr + 1
# 下に
Dout = Sr
# 右に落とすのに必要な歩数
Rout = W - Sc + 1
# 左に
Lout = Sc
S = str(input())
T = str(input())
ptrC = defaultdict(int)
ptrA = defaultdict(int)
for s, t in zip(S, T):
ptrC[s] += 1
ptrA[t] += 1
# print(ptrC,ptrA)
if (
ptrC["R"] - ptrA["L"] >= Rout
or ptrC["L"] - ptrA["R"] >= Lout
or ptrC["D"] - ptrA["U"] >= Dout
or ptrC["U"] - ptrA["D"] >= Uout
):
print("NO")
exit()
# def check(outcnt, C, A, lim, B):
# backed = 0
# for s,t in zip(S,T):
# if s == B and outcnt == lim -1 and backed > 0:
# outcnt -= 1
# backed -= 1
# if( s == C ):
# outcnt -= 1
# if( outcnt == 0 ):
# print("NO")
# exit()
# if( t == A and outcnt < lim ):
# outcnt += 1
# backed += 1
#
# check(Rout, "R", "L", W, "L")
# check(Lout, "L", "R", W, "R")
# check(Uout, "U", "D", H, "D")
# check(Dout, "D", "U", H, "U")
print("YES")
| Statement
We have a rectangular grid of squares with H horizontal rows and W vertical
columns. Let (i,j) denote the square at the i-th row from the top and the j-th
column from the left. On this grid, there is a piece, which is initially
placed at square (s_r,s_c).
Takahashi and Aoki will play a game, where each player has a string of length
N. Takahashi's string is S, and Aoki's string is T. S and T both consist of
four kinds of letters: `L`, `R`, `U` and `D`.
The game consists of N steps. The i-th step proceeds as follows:
* First, Takahashi performs a move. He either moves the piece in the direction of S_i, or does not move the piece.
* Second, Aoki performs a move. He either moves the piece in the direction of T_i, or does not move the piece.
Here, to move the piece in the direction of `L`, `R`, `U` and `D`, is to move
the piece from square (r,c) to square (r,c-1), (r,c+1), (r-1,c) and (r+1,c),
respectively. If the destination square does not exist, the piece is removed
from the grid, and the game ends, even if less than N steps are done.
Takahashi wants to remove the piece from the grid in one of the N steps. Aoki,
on the other hand, wants to finish the N steps with the piece remaining on the
grid. Determine if the piece will remain on the grid at the end of the game
when both players play optimally. | [{"input": "2 3 3\n 2 2\n RRL\n LUD", "output": "YES\n \n\nHere is one possible progress of the game:\n\n * Takahashi moves the piece right. The piece is now at (2,3).\n * Aoki moves the piece left. The piece is now at (2,2).\n * Takahashi does not move the piece. The piece remains at (2,2).\n * Aoki moves the piece up. The piece is now at (1,2).\n * Takahashi moves the piece left. The piece is now at (1,1).\n * Aoki does not move the piece. The piece remains at (1,1).\n\n* * *"}, {"input": "4 3 5\n 2 2\n UDRRR\n LLDUD", "output": "NO\n \n\n* * *"}, {"input": "5 6 11\n 2 1\n RLDRRUDDLRL\n URRDRLLDLRD", "output": "NO"}] |
If the piece will remain on the grid at the end of the game, print `YES`;
otherwise, print `NO`.
* * * | s460599937 | Runtime Error | p03054 | Input is given from Standard Input in the following format:
H W N
s_r s_c
S
T | import copy
import numpy as np
H, W = map(int, input().split())
A = np.array([[0 if a == "#" else 1 for a in input()] for _ in range(H)])
def change_color(A):
new_A = copy.deepcopy(A)
for i, ai in enumerate(A):
for j, aij in enumerate(ai):
if aij == 0:
if i == H - 1 and j == W - 1:
new_A[i - 1][j] = 0
new_A[i][j - 1] = 0
elif i == H - 1:
if j == 0:
new_A[i - 1][j] = 0
new_A[i][j + 1] = 0
else:
new_A[i - 1][j] = 0
new_A[i][j - 1] = 0
new_A[i][j + 1] = 0
elif j == W - 1:
if i == 0:
new_A[i + 1][j] = 0
new_A[i][j - 1] = 0
else:
new_A[i - 1][j] = 0
new_A[i + 1][j] = 0
new_A[i][j - 1] = 0
else:
if i == 0:
new_A[i + 1][j] = 0
new_A[i][j - 1] = 0
new_A[i][j + 1] = 0
elif j == 0:
new_A[i - 1][j] = 0
new_A[i + 1][j] = 0
new_A[i][j + 1] = 0
else:
new_A[i - 1][j] = 0
new_A[i + 1][j] = 0
new_A[i][j - 1] = 0
new_A[i][j + 1] = 0
return new_A
count = 0
while A.sum() != 0:
A = change_color(A)
count += 1
print(count)
| Statement
We have a rectangular grid of squares with H horizontal rows and W vertical
columns. Let (i,j) denote the square at the i-th row from the top and the j-th
column from the left. On this grid, there is a piece, which is initially
placed at square (s_r,s_c).
Takahashi and Aoki will play a game, where each player has a string of length
N. Takahashi's string is S, and Aoki's string is T. S and T both consist of
four kinds of letters: `L`, `R`, `U` and `D`.
The game consists of N steps. The i-th step proceeds as follows:
* First, Takahashi performs a move. He either moves the piece in the direction of S_i, or does not move the piece.
* Second, Aoki performs a move. He either moves the piece in the direction of T_i, or does not move the piece.
Here, to move the piece in the direction of `L`, `R`, `U` and `D`, is to move
the piece from square (r,c) to square (r,c-1), (r,c+1), (r-1,c) and (r+1,c),
respectively. If the destination square does not exist, the piece is removed
from the grid, and the game ends, even if less than N steps are done.
Takahashi wants to remove the piece from the grid in one of the N steps. Aoki,
on the other hand, wants to finish the N steps with the piece remaining on the
grid. Determine if the piece will remain on the grid at the end of the game
when both players play optimally. | [{"input": "2 3 3\n 2 2\n RRL\n LUD", "output": "YES\n \n\nHere is one possible progress of the game:\n\n * Takahashi moves the piece right. The piece is now at (2,3).\n * Aoki moves the piece left. The piece is now at (2,2).\n * Takahashi does not move the piece. The piece remains at (2,2).\n * Aoki moves the piece up. The piece is now at (1,2).\n * Takahashi moves the piece left. The piece is now at (1,1).\n * Aoki does not move the piece. The piece remains at (1,1).\n\n* * *"}, {"input": "4 3 5\n 2 2\n UDRRR\n LLDUD", "output": "NO\n \n\n* * *"}, {"input": "5 6 11\n 2 1\n RLDRRUDDLRL\n URRDRLLDLRD", "output": "NO"}] |
If the piece will remain on the grid at the end of the game, print `YES`;
otherwise, print `NO`.
* * * | s481929723 | Accepted | p03054 | Input is given from Standard Input in the following format:
H W N
s_r s_c
S
T | def solve(W, sc, chL, chR):
limLs, limRs = [0] * N, [0] * N
limL, limR = 0, W + 1
for i in reversed(range(N)):
if Ts[i] == chL:
limR += 1
if limR > W + 1:
limR = W + 1
elif Ts[i] == chR:
limL -= 1
if limL < 0:
limL = 0
if Ss[i] == chL:
limL += 1
if limL > W + 1:
limL = W + 1
elif Ss[i] == chR:
limR -= 1
if limR < 0:
limR = 0
limLs[i] = limL
limRs[i] = limR
posL, posR = sc, sc
for i in range(N):
if posR <= limLs[i] or limRs[i] <= posL:
return False
if Ss[i] == chL:
posR -= 1
if posR < 1:
posR = 1
elif Ss[i] == chR:
posL += 1
if posL > W:
posL = W
if Ts[i] == chL:
posL -= 1
if posL < 1:
posL = 1
elif Ts[i] == chR:
posR += 1
if posR > W:
posR = W
return True
H, W, N = map(int, input().split())
sr, sc = map(int, input().split())
Ss = input()
Ts = input()
ansLR = solve(W, sc, "L", "R")
ansUD = solve(H, sr, "U", "D")
print("YES" if ansLR and ansUD else "NO")
| Statement
We have a rectangular grid of squares with H horizontal rows and W vertical
columns. Let (i,j) denote the square at the i-th row from the top and the j-th
column from the left. On this grid, there is a piece, which is initially
placed at square (s_r,s_c).
Takahashi and Aoki will play a game, where each player has a string of length
N. Takahashi's string is S, and Aoki's string is T. S and T both consist of
four kinds of letters: `L`, `R`, `U` and `D`.
The game consists of N steps. The i-th step proceeds as follows:
* First, Takahashi performs a move. He either moves the piece in the direction of S_i, or does not move the piece.
* Second, Aoki performs a move. He either moves the piece in the direction of T_i, or does not move the piece.
Here, to move the piece in the direction of `L`, `R`, `U` and `D`, is to move
the piece from square (r,c) to square (r,c-1), (r,c+1), (r-1,c) and (r+1,c),
respectively. If the destination square does not exist, the piece is removed
from the grid, and the game ends, even if less than N steps are done.
Takahashi wants to remove the piece from the grid in one of the N steps. Aoki,
on the other hand, wants to finish the N steps with the piece remaining on the
grid. Determine if the piece will remain on the grid at the end of the game
when both players play optimally. | [{"input": "2 3 3\n 2 2\n RRL\n LUD", "output": "YES\n \n\nHere is one possible progress of the game:\n\n * Takahashi moves the piece right. The piece is now at (2,3).\n * Aoki moves the piece left. The piece is now at (2,2).\n * Takahashi does not move the piece. The piece remains at (2,2).\n * Aoki moves the piece up. The piece is now at (1,2).\n * Takahashi moves the piece left. The piece is now at (1,1).\n * Aoki does not move the piece. The piece remains at (1,1).\n\n* * *"}, {"input": "4 3 5\n 2 2\n UDRRR\n LLDUD", "output": "NO\n \n\n* * *"}, {"input": "5 6 11\n 2 1\n RLDRRUDDLRL\n URRDRLLDLRD", "output": "NO"}] |
If the piece will remain on the grid at the end of the game, print `YES`;
otherwise, print `NO`.
* * * | s724711539 | Runtime Error | p03054 | Input is given from Standard Input in the following format:
H W N
s_r s_c
S
T | H, W, N = tuple(map(int, input().split()))
r, c = tuple(map(int, input().split()))
Ta = input()
Ao = input()
def convert(ch):
if ch == "R":
return (0, 1)
elif ch == "L":
return (0, -1)
elif ch == "U":
return (1, 0)
else:
return (-1, 0)
# 青木くんのターンになったらやばいマップを逆方向に1動かして重ねた部分がやばくなる
import numpy as np
yabaiMap = np.zeros((H + 2, W + 2))
yabaiMap[1:-1, 1:-1] = np.ones((H, W))
for idx, (t, a) in enumerate(zip(reversed(Ta), reversed(Ao))):
if idx != 0:
dy, dx = convert(a)
# 動かした方向にやばくない場所があれば復帰する
# つまり フィルタをかけてしまえばいいので,元の場所が0かつ動かした先が1であればよい,その場所を1にする
yabaiMap[1:-1, 1:-1] += (1 - yabaiMap)[1:-1, 1:-1] * yabaiMap[
1 + dy : H + 1 + dy, 1 + dx : W + 1 + dx
]
# print("A",a,yabaiMap)
dy, dx = convert(t)
yabaiMap[1:-1, 1:-1] *= yabaiMap[1 + dy : H + 1 + dy, 1 + dx : W + 1 + dx]
if np.sum(yabaiMap) == 0:
print("NO")
quit()
print("YES" if yabaiMap[r, c] == 1 else "NO")
| Statement
We have a rectangular grid of squares with H horizontal rows and W vertical
columns. Let (i,j) denote the square at the i-th row from the top and the j-th
column from the left. On this grid, there is a piece, which is initially
placed at square (s_r,s_c).
Takahashi and Aoki will play a game, where each player has a string of length
N. Takahashi's string is S, and Aoki's string is T. S and T both consist of
four kinds of letters: `L`, `R`, `U` and `D`.
The game consists of N steps. The i-th step proceeds as follows:
* First, Takahashi performs a move. He either moves the piece in the direction of S_i, or does not move the piece.
* Second, Aoki performs a move. He either moves the piece in the direction of T_i, or does not move the piece.
Here, to move the piece in the direction of `L`, `R`, `U` and `D`, is to move
the piece from square (r,c) to square (r,c-1), (r,c+1), (r-1,c) and (r+1,c),
respectively. If the destination square does not exist, the piece is removed
from the grid, and the game ends, even if less than N steps are done.
Takahashi wants to remove the piece from the grid in one of the N steps. Aoki,
on the other hand, wants to finish the N steps with the piece remaining on the
grid. Determine if the piece will remain on the grid at the end of the game
when both players play optimally. | [{"input": "2 3 3\n 2 2\n RRL\n LUD", "output": "YES\n \n\nHere is one possible progress of the game:\n\n * Takahashi moves the piece right. The piece is now at (2,3).\n * Aoki moves the piece left. The piece is now at (2,2).\n * Takahashi does not move the piece. The piece remains at (2,2).\n * Aoki moves the piece up. The piece is now at (1,2).\n * Takahashi moves the piece left. The piece is now at (1,1).\n * Aoki does not move the piece. The piece remains at (1,1).\n\n* * *"}, {"input": "4 3 5\n 2 2\n UDRRR\n LLDUD", "output": "NO\n \n\n* * *"}, {"input": "5 6 11\n 2 1\n RLDRRUDDLRL\n URRDRLLDLRD", "output": "NO"}] |
If the piece will remain on the grid at the end of the game, print `YES`;
otherwise, print `NO`.
* * * | s017162262 | Wrong Answer | p03054 | Input is given from Standard Input in the following format:
H W N
s_r s_c
S
T | import sys
H, W, N = [int(x) for x in input().split(" ")]
x = tuple([int(x) for x in input().split(" ")])
# S = [x for x in input()]
# T = [x for x in input()]
S = input()
T = input()
class Takahashi:
def __init__(self, S, H, W):
self.s = S
self.up = S.count("R")
self.down = S.count("D")
self.right = S.count("R")
self.left = S.count("L")
self.H = H
self.W = W
def __call__(self, i, s, aoki):
if self.s[i] == "U":
self.up -= 1
if ((self.up - aoki.down - s[0]) - 1) > ((s[0] + self.down - aoki.up) - H):
return (s[0] - 1, s[1])
elif self.s[i] == "D":
self.down -= 1
if ((self.up - aoki.down - s[0]) - 1) < ((s[0] + self.down - aoki.up) - H):
return (s[0] - 1, s[1])
elif self.s[i] == "R":
self.right -= 1
if ((self.left - aoki.right - s[1]) - 1) < (
(s[1] + self.right - aoki.left) - W
):
return (s[0], s[1] + 1)
elif self.s[i] == "L":
self.left -= 1
if ((self.left - aoki.right - s[1]) - 1) > (
(s[1] + self.right - aoki.left) - W
):
return (s[0], s[1] - 1)
return s
class Aoki:
def __init__(self, T, H, W):
self.t = T
self.up = T.count("R")
self.down = T.count("D")
self.right = T.count("R")
self.left = T.count("L")
self.H = H
self.W = W
def __call__(self, i, s, takahashi):
if self.t[i] == "U":
self.up -= 1
if ((takahashi.up - self.down - s[0]) - 1) < (
(s[0] + takahashi.down - self.up) - H
):
return (s[0] - 1, s[1])
elif self.t[i] == "D":
self.down -= 1
if ((takahashi.up - self.down - s[0]) - 1) > (
(s[0] + takahashi.down - self.up) - H
):
return (s[0] - 1, s[1])
elif self.t[i] == "R":
self.right -= 1
if ((takahashi.left - self.right - s[1]) - 1) > (
(s[1] + takahashi.right - self.left) - W
):
return (s[0], s[1] + 1)
elif self.t[i] == "L":
self.left -= 1
if ((takahashi.left - self.right - s[1]) - 1) < (
(s[1] + takahashi.right - self.left) - W
):
return (s[0], s[1] - 1)
return s
takahashi = Takahashi(S, H, W)
aoki = Aoki(T, H, W)
for i in range(N):
x = takahashi(i, x, aoki)
if (x[0] < 1) or (x[0] > H) or (x[1] < 1) or (x[1] > W):
print("NO")
sys.exit()
x = aoki(i, x, takahashi)
print("YES")
| Statement
We have a rectangular grid of squares with H horizontal rows and W vertical
columns. Let (i,j) denote the square at the i-th row from the top and the j-th
column from the left. On this grid, there is a piece, which is initially
placed at square (s_r,s_c).
Takahashi and Aoki will play a game, where each player has a string of length
N. Takahashi's string is S, and Aoki's string is T. S and T both consist of
four kinds of letters: `L`, `R`, `U` and `D`.
The game consists of N steps. The i-th step proceeds as follows:
* First, Takahashi performs a move. He either moves the piece in the direction of S_i, or does not move the piece.
* Second, Aoki performs a move. He either moves the piece in the direction of T_i, or does not move the piece.
Here, to move the piece in the direction of `L`, `R`, `U` and `D`, is to move
the piece from square (r,c) to square (r,c-1), (r,c+1), (r-1,c) and (r+1,c),
respectively. If the destination square does not exist, the piece is removed
from the grid, and the game ends, even if less than N steps are done.
Takahashi wants to remove the piece from the grid in one of the N steps. Aoki,
on the other hand, wants to finish the N steps with the piece remaining on the
grid. Determine if the piece will remain on the grid at the end of the game
when both players play optimally. | [{"input": "2 3 3\n 2 2\n RRL\n LUD", "output": "YES\n \n\nHere is one possible progress of the game:\n\n * Takahashi moves the piece right. The piece is now at (2,3).\n * Aoki moves the piece left. The piece is now at (2,2).\n * Takahashi does not move the piece. The piece remains at (2,2).\n * Aoki moves the piece up. The piece is now at (1,2).\n * Takahashi moves the piece left. The piece is now at (1,1).\n * Aoki does not move the piece. The piece remains at (1,1).\n\n* * *"}, {"input": "4 3 5\n 2 2\n UDRRR\n LLDUD", "output": "NO\n \n\n* * *"}, {"input": "5 6 11\n 2 1\n RLDRRUDDLRL\n URRDRLLDLRD", "output": "NO"}] |
If the piece will remain on the grid at the end of the game, print `YES`;
otherwise, print `NO`.
* * * | s747469511 | Wrong Answer | p03054 | Input is given from Standard Input in the following format:
H W N
s_r s_c
S
T | h, w, n = (int(_) for _ in input().split())
r, c = (int(_) for _ in input().split())
remove = input()
keep = input()
rtoedge = w - c
ltoedge = w - 1
utoedge = h - 1
dtoedge = h - r
edge = {"R": w - c, "L": w - 1, "U": h - 1, "D": h - r}
found = True
if rtoedge > ltoedge:
minhor = "L"
opphor = "R"
hormoves = ltoedge
else:
minhor = "R"
opphor = "L"
hormoves = rtoedge
if utoedge > dtoedge:
minver = "D"
oppver = "U"
vermoves = dtoedge
else:
minver = "U"
oppver = "D"
vermoves = utoedge
removes = {"R": 0, "L": 0, "U": 0, "D": 0}
keepmoves = {"R": 0, "L": 0, "U": 0, "D": 0}
opp = [("R", "L"), ("U", "D")]
total = {"R": 0, "L": 0, "U": 0, "D": 0}
for move in remove:
removes[move] += 1
for move in keep:
keepmoves[move] += 1
if removes[minhor] > hormoves and removes[minhor] > keepmoves[opphor]:
print("YES")
elif removes[minver] > vermoves and removes[minver] > keepmoves[oppver]:
print("YES")
else:
for i in range(n):
rmove = remove[i]
kmove = keep[i]
total[rmove] += 1
for key in total:
if total[key] > edge[key]:
print("YES")
found = False
break
if rtoedge != 0 and kmove == "R":
total[kmove] -= 1
elif ltoedge != 0 and kmove == "L":
total[kmove] -= 1
elif utoedge != 0 and kmove == "U":
total[kmove] -= 1
elif dtoedge != 0 and kmove == "D":
total[kmove] -= 1
if not found:
print("NO")
| Statement
We have a rectangular grid of squares with H horizontal rows and W vertical
columns. Let (i,j) denote the square at the i-th row from the top and the j-th
column from the left. On this grid, there is a piece, which is initially
placed at square (s_r,s_c).
Takahashi and Aoki will play a game, where each player has a string of length
N. Takahashi's string is S, and Aoki's string is T. S and T both consist of
four kinds of letters: `L`, `R`, `U` and `D`.
The game consists of N steps. The i-th step proceeds as follows:
* First, Takahashi performs a move. He either moves the piece in the direction of S_i, or does not move the piece.
* Second, Aoki performs a move. He either moves the piece in the direction of T_i, or does not move the piece.
Here, to move the piece in the direction of `L`, `R`, `U` and `D`, is to move
the piece from square (r,c) to square (r,c-1), (r,c+1), (r-1,c) and (r+1,c),
respectively. If the destination square does not exist, the piece is removed
from the grid, and the game ends, even if less than N steps are done.
Takahashi wants to remove the piece from the grid in one of the N steps. Aoki,
on the other hand, wants to finish the N steps with the piece remaining on the
grid. Determine if the piece will remain on the grid at the end of the game
when both players play optimally. | [{"input": "2 3 3\n 2 2\n RRL\n LUD", "output": "YES\n \n\nHere is one possible progress of the game:\n\n * Takahashi moves the piece right. The piece is now at (2,3).\n * Aoki moves the piece left. The piece is now at (2,2).\n * Takahashi does not move the piece. The piece remains at (2,2).\n * Aoki moves the piece up. The piece is now at (1,2).\n * Takahashi moves the piece left. The piece is now at (1,1).\n * Aoki does not move the piece. The piece remains at (1,1).\n\n* * *"}, {"input": "4 3 5\n 2 2\n UDRRR\n LLDUD", "output": "NO\n \n\n* * *"}, {"input": "5 6 11\n 2 1\n RLDRRUDDLRL\n URRDRLLDLRD", "output": "NO"}] |
If the piece will remain on the grid at the end of the game, print `YES`;
otherwise, print `NO`.
* * * | s274911405 | Wrong Answer | p03054 | Input is given from Standard Input in the following format:
H W N
s_r s_c
S
T | from collections import defaultdict
s_dict = defaultdict(lambda: 0)
t_dict = defaultdict(lambda: 0)
h, w, n = map(int, input().split())
sr, sc = map(int, input().split())
s = list(str(input()))
t = list(str(input()))
for i in range(n):
s_dict[s[i]] += 1
t_dict[t[i]] += 1
# 落ちるパターン
# 駒が端にあり、高橋くんが場外に移動させることができる場合、落ちる
ans = "NO"
first = False
if (
sr == 1
and s_dict["L"] > 0
or sr == w
and s_dict["R"] > 0
or sc == 1
and s_dict["U"] > 0
or sc == h
and s_dict["D"] > 0
):
first = True
s_sum = defaultdict(lambda: 0)
t_sum = defaultdict(lambda: 0)
if not first:
# それぞれの累積和でmaxを考える
for i in range(n):
s_sum[s[i]] += 1
# 高橋くんは落とさないようにする制約がある
if t[i] == "L" and t_sum["L"] - s_sum["R"] >= sr - 1:
pass
elif t[i] == "R" and t_sum["R"] - s_sum["L"] >= w - sr:
pass
elif t[i] == "U" and t_sum["U"] - s_sum["D"] >= sc - 1:
pass
elif t[i] == "D" and t_sum["D"] - s_sum["U"] >= h - sc:
pass
else:
t_sum[t[i]] += 1
if sr <= s_sum["L"] - t_sum["R"]:
break
elif w - sr < s_sum["R"] - t_sum["L"]:
break
elif sc <= s_sum["U"] - t_sum["D"]:
break
elif h - sc < s_sum["D"] - t_sum["U"]:
break
if i == n - 1:
ans = "YES"
print(ans)
| Statement
We have a rectangular grid of squares with H horizontal rows and W vertical
columns. Let (i,j) denote the square at the i-th row from the top and the j-th
column from the left. On this grid, there is a piece, which is initially
placed at square (s_r,s_c).
Takahashi and Aoki will play a game, where each player has a string of length
N. Takahashi's string is S, and Aoki's string is T. S and T both consist of
four kinds of letters: `L`, `R`, `U` and `D`.
The game consists of N steps. The i-th step proceeds as follows:
* First, Takahashi performs a move. He either moves the piece in the direction of S_i, or does not move the piece.
* Second, Aoki performs a move. He either moves the piece in the direction of T_i, or does not move the piece.
Here, to move the piece in the direction of `L`, `R`, `U` and `D`, is to move
the piece from square (r,c) to square (r,c-1), (r,c+1), (r-1,c) and (r+1,c),
respectively. If the destination square does not exist, the piece is removed
from the grid, and the game ends, even if less than N steps are done.
Takahashi wants to remove the piece from the grid in one of the N steps. Aoki,
on the other hand, wants to finish the N steps with the piece remaining on the
grid. Determine if the piece will remain on the grid at the end of the game
when both players play optimally. | [{"input": "2 3 3\n 2 2\n RRL\n LUD", "output": "YES\n \n\nHere is one possible progress of the game:\n\n * Takahashi moves the piece right. The piece is now at (2,3).\n * Aoki moves the piece left. The piece is now at (2,2).\n * Takahashi does not move the piece. The piece remains at (2,2).\n * Aoki moves the piece up. The piece is now at (1,2).\n * Takahashi moves the piece left. The piece is now at (1,1).\n * Aoki does not move the piece. The piece remains at (1,1).\n\n* * *"}, {"input": "4 3 5\n 2 2\n UDRRR\n LLDUD", "output": "NO\n \n\n* * *"}, {"input": "5 6 11\n 2 1\n RLDRRUDDLRL\n URRDRLLDLRD", "output": "NO"}] |
For each dataset, output a single line containing _i_ where the first word of
the Short Phrase is _w i_. When multiple Short Phrases occur in the dataset,
you should output the first one. | s989231943 | Accepted | p01086 | The input consists of multiple datasets, each in the following format.
> _n_
> _w_ 1
> ...
> _w n_
>
Here, _n_ is the number of words, which is a positive integer not exceeding
40; _w i_ is the _i_ -th word, consisting solely of lowercase letters from 'a'
to 'z'. The length of each word is between 1 and 10, inclusive. You can assume
that every dataset includes a Short Phrase.
The end of the input is indicated by a line with a single zero. | def inp():
global n
n = int(input())
return n
def pos(p, l):
global w
if p < 0:
return -1
while l > 0 and p < n:
l -= w[p]
p += 1
if l == 0:
return p
return -1
while inp() > 0:
w = []
for i in range(n):
w.append(len(input()))
for i in range(n):
if pos(pos(pos(pos(pos(i, 5), 7), 5), 7), 7) >= 0:
print(i + 1)
break
| Short Phrase
A _Short Phrase_ (aka. Tanku) is a fixed verse, inspired by Japanese poetry
Tanka and Haiku. It is a sequence of words, each consisting of lowercase
letters 'a' to 'z', and must satisfy the following condition:
> (The Condition for a Short Phrase)
> The sequence of words can be divided into five sections such that the total
> number of the letters in the word(s) of the first section is five, that of
> the second is seven, and those of the rest are five, seven, and seven,
> respectively.
The following is an example of a Short Phrase.
>
> do the best
> and enjoy today
> at acm icpc
>
In this example, the sequence of the nine words can be divided into five
sections (1) "do" and "the", (2) "best" and "and", (3) "enjoy", (4) "today"
and "at", and (5) "acm" and "icpc" such that they have 5, 7, 5, 7, and 7
letters in this order, respectively. This surely satisfies the condition of a
Short Phrase.
Now, _Short Phrase Parnassus_ published by your company has received a lot of
contributions. By an unfortunate accident, however, some irrelevant texts seem
to be added at beginnings and ends of contributed Short Phrases. Your mission
is to write a program that finds the Short Phrase from a sequence of words
that may have an irrelevant prefix and/or a suffix. | [{"input": "do\n the\n best\n and\n enjoy\n today\n at\n acm\n icpc\n 14\n oh\n yes\n by\n far\n it\n is\n wow\n so\n bad\n to\n me\n you\n know\n hey\n 15\n abcde\n fghijkl\n mnopq\n rstuvwx\n yzz\n abcde\n fghijkl\n mnopq\n rstuvwx\n yz\n abcde\n fghijkl\n mnopq\n rstuvwx\n yz\n 0", "output": "2\n 6"}] |
For each dataset, output a single line containing _i_ where the first word of
the Short Phrase is _w i_. When multiple Short Phrases occur in the dataset,
you should output the first one. | s060207951 | Accepted | p01086 | The input consists of multiple datasets, each in the following format.
> _n_
> _w_ 1
> ...
> _w n_
>
Here, _n_ is the number of words, which is a positive integer not exceeding
40; _w i_ is the _i_ -th word, consisting solely of lowercase letters from 'a'
to 'z'. The length of each word is between 1 and 10, inclusive. You can assume
that every dataset includes a Short Phrase.
The end of the input is indicated by a line with a single zero. | while True:
n = int(input())
if n == 0:
break
w = []
go = 0
flag = True
x = 0
count = 0
for i in range(n):
w.append(input())
else:
while count < 5:
for i in range(x, n):
go += len(w[i])
if flag == True:
if go == 5:
flag = False
count += 1
go = 0
if go > 5:
x += 1
go = 0
count = 0
break
if flag == False:
if go == 7 and count == 3:
flag = False
count += 1
go = 0
if go == 7:
flag = True
count += 1
go = 0
if go > 7:
x += 1
go = 0
count = 0
flag = True
break
if count == 5:
break
print(x + 1)
| Short Phrase
A _Short Phrase_ (aka. Tanku) is a fixed verse, inspired by Japanese poetry
Tanka and Haiku. It is a sequence of words, each consisting of lowercase
letters 'a' to 'z', and must satisfy the following condition:
> (The Condition for a Short Phrase)
> The sequence of words can be divided into five sections such that the total
> number of the letters in the word(s) of the first section is five, that of
> the second is seven, and those of the rest are five, seven, and seven,
> respectively.
The following is an example of a Short Phrase.
>
> do the best
> and enjoy today
> at acm icpc
>
In this example, the sequence of the nine words can be divided into five
sections (1) "do" and "the", (2) "best" and "and", (3) "enjoy", (4) "today"
and "at", and (5) "acm" and "icpc" such that they have 5, 7, 5, 7, and 7
letters in this order, respectively. This surely satisfies the condition of a
Short Phrase.
Now, _Short Phrase Parnassus_ published by your company has received a lot of
contributions. By an unfortunate accident, however, some irrelevant texts seem
to be added at beginnings and ends of contributed Short Phrases. Your mission
is to write a program that finds the Short Phrase from a sequence of words
that may have an irrelevant prefix and/or a suffix. | [{"input": "do\n the\n best\n and\n enjoy\n today\n at\n acm\n icpc\n 14\n oh\n yes\n by\n far\n it\n is\n wow\n so\n bad\n to\n me\n you\n know\n hey\n 15\n abcde\n fghijkl\n mnopq\n rstuvwx\n yzz\n abcde\n fghijkl\n mnopq\n rstuvwx\n yz\n abcde\n fghijkl\n mnopq\n rstuvwx\n yz\n 0", "output": "2\n 6"}] |
For each dataset, output a single line containing _i_ where the first word of
the Short Phrase is _w i_. When multiple Short Phrases occur in the dataset,
you should output the first one. | s732966864 | Accepted | p01086 | The input consists of multiple datasets, each in the following format.
> _n_
> _w_ 1
> ...
> _w n_
>
Here, _n_ is the number of words, which is a positive integer not exceeding
40; _w i_ is the _i_ -th word, consisting solely of lowercase letters from 'a'
to 'z'. The length of each word is between 1 and 10, inclusive. You can assume
that every dataset includes a Short Phrase.
The end of the input is indicated by a line with a single zero. | while True:
n = int(input()) # 文字列の量
if n == 0:
break
w = list() # 文字用
for i in range(0, n): # 入力
w.append(input())
for j in range(1, n + 1): # 始めの文字の場所
ck = 0
co = 0
p = 0
t = ""
for k in range(j - 1, 50): # 57577チェック用
# print(k)
if co == 0 or co == 2: # 5の場所
if ck < 5: # 五以下
# print("<")
ck = ck + len(w[k + p]) # 文字増やす
elif ck == 5: # ピッタリになったら
# print("==")
co = co + 1 # 次に移る
ck = 0
p = p - 1
else: # オーバーしたら
# print(">")
break
else:
if ck < 7:
# print("<7")
ck = ck + len(w[k + p])
# print(" " ,ck)
elif ck == 7:
# print("==7")
co = co + 1
ck = 0
p = p - 1
if co == 5:
t = "fin"
break
else:
# print(">7")
break
if t == "fin":
print(j)
break
# print("over")
| Short Phrase
A _Short Phrase_ (aka. Tanku) is a fixed verse, inspired by Japanese poetry
Tanka and Haiku. It is a sequence of words, each consisting of lowercase
letters 'a' to 'z', and must satisfy the following condition:
> (The Condition for a Short Phrase)
> The sequence of words can be divided into five sections such that the total
> number of the letters in the word(s) of the first section is five, that of
> the second is seven, and those of the rest are five, seven, and seven,
> respectively.
The following is an example of a Short Phrase.
>
> do the best
> and enjoy today
> at acm icpc
>
In this example, the sequence of the nine words can be divided into five
sections (1) "do" and "the", (2) "best" and "and", (3) "enjoy", (4) "today"
and "at", and (5) "acm" and "icpc" such that they have 5, 7, 5, 7, and 7
letters in this order, respectively. This surely satisfies the condition of a
Short Phrase.
Now, _Short Phrase Parnassus_ published by your company has received a lot of
contributions. By an unfortunate accident, however, some irrelevant texts seem
to be added at beginnings and ends of contributed Short Phrases. Your mission
is to write a program that finds the Short Phrase from a sequence of words
that may have an irrelevant prefix and/or a suffix. | [{"input": "do\n the\n best\n and\n enjoy\n today\n at\n acm\n icpc\n 14\n oh\n yes\n by\n far\n it\n is\n wow\n so\n bad\n to\n me\n you\n know\n hey\n 15\n abcde\n fghijkl\n mnopq\n rstuvwx\n yzz\n abcde\n fghijkl\n mnopq\n rstuvwx\n yz\n abcde\n fghijkl\n mnopq\n rstuvwx\n yz\n 0", "output": "2\n 6"}] |
For each dataset, output a single line containing _i_ where the first word of
the Short Phrase is _w i_. When multiple Short Phrases occur in the dataset,
you should output the first one. | s187079727 | Accepted | p01086 | The input consists of multiple datasets, each in the following format.
> _n_
> _w_ 1
> ...
> _w n_
>
Here, _n_ is the number of words, which is a positive integer not exceeding
40; _w i_ is the _i_ -th word, consisting solely of lowercase letters from 'a'
to 'z'. The length of each word is between 1 and 10, inclusive. You can assume
that every dataset includes a Short Phrase.
The end of the input is indicated by a line with a single zero. | while True:
n = int(input())
if n == 0:
break
else:
words = []
for i in range(n):
w = input()
words.append(w)
check = [5, 7, 5, 7, 7]
flag = 0
count = 1
while True:
w_len = 0
for i in range(count - 1, n):
w_len += len(words[i])
if w_len == check[flag]:
flag += 1
w_len = 0
elif w_len > check[flag]:
flag = 0
break
if flag == 5:
print(count)
break
if flag == 5:
break
else:
count += 1
| Short Phrase
A _Short Phrase_ (aka. Tanku) is a fixed verse, inspired by Japanese poetry
Tanka and Haiku. It is a sequence of words, each consisting of lowercase
letters 'a' to 'z', and must satisfy the following condition:
> (The Condition for a Short Phrase)
> The sequence of words can be divided into five sections such that the total
> number of the letters in the word(s) of the first section is five, that of
> the second is seven, and those of the rest are five, seven, and seven,
> respectively.
The following is an example of a Short Phrase.
>
> do the best
> and enjoy today
> at acm icpc
>
In this example, the sequence of the nine words can be divided into five
sections (1) "do" and "the", (2) "best" and "and", (3) "enjoy", (4) "today"
and "at", and (5) "acm" and "icpc" such that they have 5, 7, 5, 7, and 7
letters in this order, respectively. This surely satisfies the condition of a
Short Phrase.
Now, _Short Phrase Parnassus_ published by your company has received a lot of
contributions. By an unfortunate accident, however, some irrelevant texts seem
to be added at beginnings and ends of contributed Short Phrases. Your mission
is to write a program that finds the Short Phrase from a sequence of words
that may have an irrelevant prefix and/or a suffix. | [{"input": "do\n the\n best\n and\n enjoy\n today\n at\n acm\n icpc\n 14\n oh\n yes\n by\n far\n it\n is\n wow\n so\n bad\n to\n me\n you\n know\n hey\n 15\n abcde\n fghijkl\n mnopq\n rstuvwx\n yzz\n abcde\n fghijkl\n mnopq\n rstuvwx\n yz\n abcde\n fghijkl\n mnopq\n rstuvwx\n yz\n 0", "output": "2\n 6"}] |
Print the minimum amount of MP needed to achieve the objective.
* * * | s911644574 | Accepted | p03111 | Input is given from Standard Input in the following format:
N A B C
l_1
l_2
:
l_N | n, a, b, c = map(int, input().split())
l = [int(input()) for i in range(n)]
ans = 0
from operator import mul
from functools import reduce
import itertools
def cmb(n, r):
if n < r:
return 0
r = min(n - r, r)
if r == 0:
return 1
over = reduce(mul, range(n, n - r, -1))
under = reduce(mul, range(1, r + 1))
return over // under
# 各竹への竹の割り振り方は10000通り弱。
# 各割り振りでの最小コストを求めればよい。(使わない竹がある場合も含め)
def mp(x, y, z): # 割り振りをx,y,zと決めた場合の最小MP…
ans = float("inf")
rng = list(range(n))
for ptn in itertools.combinations(rng, x):
cost = 0
cost += 10 * (x - 1) # まず接続コストを追加
wa = 0
copy = rng[:]
for i in ptn:
wa += l[i]
copy.remove(i)
# print(wa)
cost += abs(wa - a) # 出来た長さをaに調整する分の費用追加
for ptn2 in itertools.combinations(copy, y):
# print(ptn2)
cost1 = cost + 10 * (y - 1) # まず接続コストを追加
wa = 0
copy2 = copy[:]
for i in ptn2:
wa += l[i]
copy2.remove(i)
cost1 += abs(wa - b)
for ptn3 in itertools.combinations(copy2, z):
cost2 = cost1 + 10 * (z - 1)
wa = 0
for i in ptn3:
wa += l[i]
cost2 += abs(wa - c)
ans = min(ans, cost2)
return ans
final = float("inf")
for i in range(1, n - 1):
for j in range(1, n - i):
for k in range(1, n + 1 - i - j):
final = min(final, mp(i, j, k))
print(final)
| Statement
You have N bamboos. The lengths (in centimeters) of these are l_1, l_2, ...,
l_N, respectively.
Your objective is to use some of these bamboos (possibly all) to obtain three
bamboos of length A, B, C. For that, you can use the following three kinds of
magics any number:
* Extension Magic: Consumes 1 _MP_ (magic point). Choose one bamboo and increase its length by 1.
* Shortening Magic: Consumes 1 MP. Choose one bamboo of length at least 2 and decrease its length by 1.
* Composition Magic: Consumes 10 MP. Choose two bamboos and combine them into one bamboo. The length of this new bamboo is equal to the sum of the lengths of the two bamboos combined. (Afterwards, further magics can be used on this bamboo.)
At least how much MP is needed to achieve the objective? | [{"input": "5 100 90 80\n 98\n 40\n 30\n 21\n 80", "output": "23\n \n\nWe are obtaining three bamboos of lengths 100, 90, 80 from five bamboos 98,\n40, 30, 21, 80. We already have a bamboo of length 80, and we can obtain\nbamboos of lengths 100, 90 by using the magics as follows at the total cost of\n23 MP, which is optimal.\n\n 1. Use Extension Magic twice on the bamboo of length 98 to obtain a bamboo of length 100. (MP consumed: 2)\n 2. Use Composition Magic on the bamboos of lengths 40, 30 to obtain a bamboo of length 70. (MP consumed: 10)\n 3. Use Shortening Magic once on the bamboo of length 21 to obtain a bamboo of length 20. (MP consumed: 1)\n 4. Use Composition Magic on the bamboo of length 70 obtained in step 2 and the bamboo of length 20 obtained in step 3 to obtain a bamboo of length 90. (MP consumed: 10)\n\n* * *"}, {"input": "8 100 90 80\n 100\n 100\n 90\n 90\n 90\n 80\n 80\n 80", "output": "0\n \n\nIf we already have all bamboos of the desired lengths, the amount of MP needed\nis 0. As seen here, we do not necessarily need to use all the bamboos.\n\n* * *"}, {"input": "8 1000 800 100\n 300\n 333\n 400\n 444\n 500\n 555\n 600\n 666", "output": "243"}] |
Print the minimum amount of MP needed to achieve the objective.
* * * | s963033480 | Wrong Answer | p03111 | Input is given from Standard Input in the following format:
N A B C
l_1
l_2
:
l_N | import numpy as np
print(np.nan)
| Statement
You have N bamboos. The lengths (in centimeters) of these are l_1, l_2, ...,
l_N, respectively.
Your objective is to use some of these bamboos (possibly all) to obtain three
bamboos of length A, B, C. For that, you can use the following three kinds of
magics any number:
* Extension Magic: Consumes 1 _MP_ (magic point). Choose one bamboo and increase its length by 1.
* Shortening Magic: Consumes 1 MP. Choose one bamboo of length at least 2 and decrease its length by 1.
* Composition Magic: Consumes 10 MP. Choose two bamboos and combine them into one bamboo. The length of this new bamboo is equal to the sum of the lengths of the two bamboos combined. (Afterwards, further magics can be used on this bamboo.)
At least how much MP is needed to achieve the objective? | [{"input": "5 100 90 80\n 98\n 40\n 30\n 21\n 80", "output": "23\n \n\nWe are obtaining three bamboos of lengths 100, 90, 80 from five bamboos 98,\n40, 30, 21, 80. We already have a bamboo of length 80, and we can obtain\nbamboos of lengths 100, 90 by using the magics as follows at the total cost of\n23 MP, which is optimal.\n\n 1. Use Extension Magic twice on the bamboo of length 98 to obtain a bamboo of length 100. (MP consumed: 2)\n 2. Use Composition Magic on the bamboos of lengths 40, 30 to obtain a bamboo of length 70. (MP consumed: 10)\n 3. Use Shortening Magic once on the bamboo of length 21 to obtain a bamboo of length 20. (MP consumed: 1)\n 4. Use Composition Magic on the bamboo of length 70 obtained in step 2 and the bamboo of length 20 obtained in step 3 to obtain a bamboo of length 90. (MP consumed: 10)\n\n* * *"}, {"input": "8 100 90 80\n 100\n 100\n 90\n 90\n 90\n 80\n 80\n 80", "output": "0\n \n\nIf we already have all bamboos of the desired lengths, the amount of MP needed\nis 0. As seen here, we do not necessarily need to use all the bamboos.\n\n* * *"}, {"input": "8 1000 800 100\n 300\n 333\n 400\n 444\n 500\n 555\n 600\n 666", "output": "243"}] |
Print the minimum amount of MP needed to achieve the objective.
* * * | s973473014 | Accepted | p03111 | Input is given from Standard Input in the following format:
N A B C
l_1
l_2
:
l_N | N = 0
N, A, B, C = [int(s) for s in input().split()]
bamboos = [int(input()) for _ in range(N)]
# def divide(l):
# if len(l) == 0:
# return []
# if len(l) == 1:
# return [
# [[], [], []], # 使わない
# [[l[0]], [], []], # A で使う
# [[], [l[0]], []], # B で使う
# [[], [], [l[0]]], # C で使う
# ]
# res = []
# for a, b, c in divide(l[1:]):
# # 使わない
# res.append([a, b, c])
# # A で使う
# res.append([l[0:1] + a, b, c])
# # B で使う
# res.append([a, l[0:1] + b, c])
# # C で使う
# res.append([a, b, l[0:1] + c])
# return res
# min_mp = -1
# for a, b, c in divide(bamboos):
# al, ac = sum(a), len(a)
# bl, bc = sum(b), len(b)
# cl, cc = sum(c), len(c)
# if al == 0 or bl == 0 or cl == 0:
# continue
# # 合成に使った魔力
# composite = 10 * ((ac - 1) + (bc - 1) + (cc - 1))
# # 総合魔力
# mp = abs(al - A) + abs(bl - B) + abs(cl - C) + composite
# if mp < min_mp or min_mp == -1:
# min_mp = mp
# print(min_mp)
# ------------------------
# dfs を使うともっと短くかける
# ------------------------
def dfs(l, a, b, c):
global A, B, C
INF = 10**18
if len(l) == 0:
if min(a, b, c) > 0:
return abs(a - A) + abs(b - B) + abs(c - C) - 30
else:
return INF
ret0 = dfs(l[1:], a, b, c) # l[0] を使わない
retA = dfs(l[1:], a + l[0], b, c) + 10 # l[0] を A で使う
retB = dfs(l[1:], a, b + l[0], c) + 10 # l[0] を B で使う
retC = dfs(l[1:], a, b, c + l[0]) + 10 # l[0] を C で使う
return min(ret0, retA, retB, retC)
print(dfs(bamboos, 0, 0, 0))
| Statement
You have N bamboos. The lengths (in centimeters) of these are l_1, l_2, ...,
l_N, respectively.
Your objective is to use some of these bamboos (possibly all) to obtain three
bamboos of length A, B, C. For that, you can use the following three kinds of
magics any number:
* Extension Magic: Consumes 1 _MP_ (magic point). Choose one bamboo and increase its length by 1.
* Shortening Magic: Consumes 1 MP. Choose one bamboo of length at least 2 and decrease its length by 1.
* Composition Magic: Consumes 10 MP. Choose two bamboos and combine them into one bamboo. The length of this new bamboo is equal to the sum of the lengths of the two bamboos combined. (Afterwards, further magics can be used on this bamboo.)
At least how much MP is needed to achieve the objective? | [{"input": "5 100 90 80\n 98\n 40\n 30\n 21\n 80", "output": "23\n \n\nWe are obtaining three bamboos of lengths 100, 90, 80 from five bamboos 98,\n40, 30, 21, 80. We already have a bamboo of length 80, and we can obtain\nbamboos of lengths 100, 90 by using the magics as follows at the total cost of\n23 MP, which is optimal.\n\n 1. Use Extension Magic twice on the bamboo of length 98 to obtain a bamboo of length 100. (MP consumed: 2)\n 2. Use Composition Magic on the bamboos of lengths 40, 30 to obtain a bamboo of length 70. (MP consumed: 10)\n 3. Use Shortening Magic once on the bamboo of length 21 to obtain a bamboo of length 20. (MP consumed: 1)\n 4. Use Composition Magic on the bamboo of length 70 obtained in step 2 and the bamboo of length 20 obtained in step 3 to obtain a bamboo of length 90. (MP consumed: 10)\n\n* * *"}, {"input": "8 100 90 80\n 100\n 100\n 90\n 90\n 90\n 80\n 80\n 80", "output": "0\n \n\nIf we already have all bamboos of the desired lengths, the amount of MP needed\nis 0. As seen here, we do not necessarily need to use all the bamboos.\n\n* * *"}, {"input": "8 1000 800 100\n 300\n 333\n 400\n 444\n 500\n 555\n 600\n 666", "output": "243"}] |
Print the minimum amount of MP needed to achieve the objective.
* * * | s473277814 | Wrong Answer | p03111 | Input is given from Standard Input in the following format:
N A B C
l_1
l_2
:
l_N | # coding:utf-8
import sys
BAMB_NUM = 0
BAMB_A = 0
BAMB_B = 0
BAMB_C = 0
BAMB_LIST = []
def calcMP(idx, lenA, lenB, lenC):
"""
calculate MP.
"""
# when classified all bamboos
if idx == BAMB_NUM:
# exists a zero length bamboo
if lenA <= 0 or lenB <= 0 or lenC <= 0:
return sys.maxsize
else:
return abs(lenA - BAMB_A) + abs(lenB - BAMB_B) + abs(lenC - BAMB_C)
# don't use idx-th bamboo
mp = calcMP(idx + 1, lenA, lenB, lenC)
# use idx-th bamboo
mp = min(
mp,
calcMP(idx + 1, lenA + BAMB_LIST[idx], lenB, lenC) + (10 if BAMB_A > 0 else 0),
)
mp = min(
mp,
calcMP(idx + 1, lenA, lenB + BAMB_LIST[idx], lenC) + (10 if BAMB_B > 0 else 0),
)
mp = min(
mp,
calcMP(idx + 1, lenA, lenB, lenC + BAMB_LIST[idx]) + (10 if BAMB_C > 0 else 0),
)
return mp
if __name__ == "__main__":
"""
http://drken1215.hatenablog.com/entry/2019/02/24/224100
"""
# requested bamboo lengths
BAMB_NUM, BAMB_A, BAMB_B, BAMB_C = map(lambda x: int(x), input().split())
# available bamboo lengths
for bamb in range(BAMB_NUM):
BAMB_LIST.append(int(input()))
mp = calcMP(0, 0, 0, 0)
print(mp)
| Statement
You have N bamboos. The lengths (in centimeters) of these are l_1, l_2, ...,
l_N, respectively.
Your objective is to use some of these bamboos (possibly all) to obtain three
bamboos of length A, B, C. For that, you can use the following three kinds of
magics any number:
* Extension Magic: Consumes 1 _MP_ (magic point). Choose one bamboo and increase its length by 1.
* Shortening Magic: Consumes 1 MP. Choose one bamboo of length at least 2 and decrease its length by 1.
* Composition Magic: Consumes 10 MP. Choose two bamboos and combine them into one bamboo. The length of this new bamboo is equal to the sum of the lengths of the two bamboos combined. (Afterwards, further magics can be used on this bamboo.)
At least how much MP is needed to achieve the objective? | [{"input": "5 100 90 80\n 98\n 40\n 30\n 21\n 80", "output": "23\n \n\nWe are obtaining three bamboos of lengths 100, 90, 80 from five bamboos 98,\n40, 30, 21, 80. We already have a bamboo of length 80, and we can obtain\nbamboos of lengths 100, 90 by using the magics as follows at the total cost of\n23 MP, which is optimal.\n\n 1. Use Extension Magic twice on the bamboo of length 98 to obtain a bamboo of length 100. (MP consumed: 2)\n 2. Use Composition Magic on the bamboos of lengths 40, 30 to obtain a bamboo of length 70. (MP consumed: 10)\n 3. Use Shortening Magic once on the bamboo of length 21 to obtain a bamboo of length 20. (MP consumed: 1)\n 4. Use Composition Magic on the bamboo of length 70 obtained in step 2 and the bamboo of length 20 obtained in step 3 to obtain a bamboo of length 90. (MP consumed: 10)\n\n* * *"}, {"input": "8 100 90 80\n 100\n 100\n 90\n 90\n 90\n 80\n 80\n 80", "output": "0\n \n\nIf we already have all bamboos of the desired lengths, the amount of MP needed\nis 0. As seen here, we do not necessarily need to use all the bamboos.\n\n* * *"}, {"input": "8 1000 800 100\n 300\n 333\n 400\n 444\n 500\n 555\n 600\n 666", "output": "243"}] |
Print the minimum amount of MP needed to achieve the objective.
* * * | s728905701 | Wrong Answer | p03111 | Input is given from Standard Input in the following format:
N A B C
l_1
l_2
:
l_N | n, a, b, c = map(int, input().split())
l = [int(input()) for _ in range(n)]
cnt = 0
for k in [a, b, c]:
ans = 100000
for i in range(1, 2**n + 1):
s = 0
for j in range(n):
if i & 2**j:
if s > 0:
s += 10
s += l[j]
v = abs(k - s)
if v < ans:
ans = v
mast = i
cnt += ans
for j in range(n):
if mast & 2**j:
l[j] = 0
print(cnt)
| Statement
You have N bamboos. The lengths (in centimeters) of these are l_1, l_2, ...,
l_N, respectively.
Your objective is to use some of these bamboos (possibly all) to obtain three
bamboos of length A, B, C. For that, you can use the following three kinds of
magics any number:
* Extension Magic: Consumes 1 _MP_ (magic point). Choose one bamboo and increase its length by 1.
* Shortening Magic: Consumes 1 MP. Choose one bamboo of length at least 2 and decrease its length by 1.
* Composition Magic: Consumes 10 MP. Choose two bamboos and combine them into one bamboo. The length of this new bamboo is equal to the sum of the lengths of the two bamboos combined. (Afterwards, further magics can be used on this bamboo.)
At least how much MP is needed to achieve the objective? | [{"input": "5 100 90 80\n 98\n 40\n 30\n 21\n 80", "output": "23\n \n\nWe are obtaining three bamboos of lengths 100, 90, 80 from five bamboos 98,\n40, 30, 21, 80. We already have a bamboo of length 80, and we can obtain\nbamboos of lengths 100, 90 by using the magics as follows at the total cost of\n23 MP, which is optimal.\n\n 1. Use Extension Magic twice on the bamboo of length 98 to obtain a bamboo of length 100. (MP consumed: 2)\n 2. Use Composition Magic on the bamboos of lengths 40, 30 to obtain a bamboo of length 70. (MP consumed: 10)\n 3. Use Shortening Magic once on the bamboo of length 21 to obtain a bamboo of length 20. (MP consumed: 1)\n 4. Use Composition Magic on the bamboo of length 70 obtained in step 2 and the bamboo of length 20 obtained in step 3 to obtain a bamboo of length 90. (MP consumed: 10)\n\n* * *"}, {"input": "8 100 90 80\n 100\n 100\n 90\n 90\n 90\n 80\n 80\n 80", "output": "0\n \n\nIf we already have all bamboos of the desired lengths, the amount of MP needed\nis 0. As seen here, we do not necessarily need to use all the bamboos.\n\n* * *"}, {"input": "8 1000 800 100\n 300\n 333\n 400\n 444\n 500\n 555\n 600\n 666", "output": "243"}] |
Print the minimum amount of MP needed to achieve the objective.
* * * | s512540198 | Wrong Answer | p03111 | Input is given from Standard Input in the following format:
N A B C
l_1
l_2
:
l_N | n, A, B, C = map(int, input().split())
list = [A, B, C]
list_s = [A, B, C]
l = []
mp = 0
for i in range(n):
l.append(int(input()))
l.sort()
for i in list:
if l.count(i) > 0:
l.remove(i)
list_s.remove(i)
continue
elif l[0] > i:
mp = mp + (l[0] - i)
l.remove(l[0])
list_s.remove(i)
continue
for j in l:
if i - j <= 10:
mp = mp + (i - j)
l.remove(j)
list_s.remove(i)
break
for i in list_s:
if (
len(l) - len(list_s) >= 1
and l[0] + l[1] > i
and l[0] + l[1] - i <= i - l[0] + 10
):
mp = mp + (l[0] + l[1] - i) + 10
l_0, l_1 = l[0], l[1]
l.remove(l_0)
l.remove(l_1)
elif (
len(l) - len(list_s) >= 2
and l[0] + l[1] + l[2] > i
and l[0] + l[1] + l[2] - i < i - l[0] + 20
):
mp = mp + (l[0] + l[1] + l[2] - i) + 20
l_0, l_1, l_2 = l[0], l[1], l[2]
l.remove(l_0)
l.remove(l_1)
l.remove(l_2)
elif (
len(l) - len(list_s) >= 3
and l[0] + l[1] + l[2] + l[3] > i
and l[0] + l[1] + l[2] + l[3] - i < i - l[0] + 30
):
mp = mp + (l[0] + l[1] + l[2] + l[3] - i) + 30
l_0, l_1, l_2, l_3 = l[0], l[1], l[2], l[3]
l.remove(l_0)
l.remove(l_1)
l.remove(l_2)
l.remove(l_3)
elif (
len(l) - len(list_s) >= 4
and l[0] + l[1] + l[2] + l[3] + l[4] > i
and l[0] + l[1] + l[2] + l[3] + l[4] - i < i - l[0] + 40
):
mp = mp + (l[0] + l[1] + l[2] + l[3] + l[4] - i) + 40
l_0, l_1, l_2, l_3, l_4 = l[0], l[1], l[2], l[3], l[4]
l.remove(l_0)
l.remove(l_1)
l.remove(l_2)
l.remove(l_3)
l.remove(l_4)
elif (
len(l) - len(list_s) >= 5
and l[0] + l[1] + l[2] + l[3] + l[4] + l[5] > i
and l[0] + l[1] + l[2] + l[3] + l[4] + l[5] - i < i - l[0] + 50
):
mp = mp + (l[0] + l[1] + l[2] - l[3] + l[4] + l[5] - i) + 50
l_0, l_1, l_2, l_3, l_4, l_5 = l[0], l[1], l[2], l[3], l[4], l[5]
l.remove(l_0)
l.remove(l_1)
l.remove(l_2)
l.remove(l_3)
l.remove(l_4)
l.remove(l_5)
else:
mp = mp + (i - l[0])
l.remove(l[0])
print(mp)
| Statement
You have N bamboos. The lengths (in centimeters) of these are l_1, l_2, ...,
l_N, respectively.
Your objective is to use some of these bamboos (possibly all) to obtain three
bamboos of length A, B, C. For that, you can use the following three kinds of
magics any number:
* Extension Magic: Consumes 1 _MP_ (magic point). Choose one bamboo and increase its length by 1.
* Shortening Magic: Consumes 1 MP. Choose one bamboo of length at least 2 and decrease its length by 1.
* Composition Magic: Consumes 10 MP. Choose two bamboos and combine them into one bamboo. The length of this new bamboo is equal to the sum of the lengths of the two bamboos combined. (Afterwards, further magics can be used on this bamboo.)
At least how much MP is needed to achieve the objective? | [{"input": "5 100 90 80\n 98\n 40\n 30\n 21\n 80", "output": "23\n \n\nWe are obtaining three bamboos of lengths 100, 90, 80 from five bamboos 98,\n40, 30, 21, 80. We already have a bamboo of length 80, and we can obtain\nbamboos of lengths 100, 90 by using the magics as follows at the total cost of\n23 MP, which is optimal.\n\n 1. Use Extension Magic twice on the bamboo of length 98 to obtain a bamboo of length 100. (MP consumed: 2)\n 2. Use Composition Magic on the bamboos of lengths 40, 30 to obtain a bamboo of length 70. (MP consumed: 10)\n 3. Use Shortening Magic once on the bamboo of length 21 to obtain a bamboo of length 20. (MP consumed: 1)\n 4. Use Composition Magic on the bamboo of length 70 obtained in step 2 and the bamboo of length 20 obtained in step 3 to obtain a bamboo of length 90. (MP consumed: 10)\n\n* * *"}, {"input": "8 100 90 80\n 100\n 100\n 90\n 90\n 90\n 80\n 80\n 80", "output": "0\n \n\nIf we already have all bamboos of the desired lengths, the amount of MP needed\nis 0. As seen here, we do not necessarily need to use all the bamboos.\n\n* * *"}, {"input": "8 1000 800 100\n 300\n 333\n 400\n 444\n 500\n 555\n 600\n 666", "output": "243"}] |
Print the minimum amount of MP needed to achieve the objective.
* * * | s984776611 | Wrong Answer | p03111 | Input is given from Standard Input in the following format:
N A B C
l_1
l_2
:
l_N | now_ans = 100000
def kotae(A, a_tree, a_tree_sum):
ans = (a_tree - 1) * 10 + abs(a_tree_sum - A)
if a_tree == 0:
ans = 100000
return ans
def calc_final(A, B, C, a_tree, b_tree, c_tree, a_tree_sum, b_tree_sum, c_tree_sum):
global now_ans
ans = 0
ans += kotae(A, a_tree, a_tree_sum)
ans += kotae(B, b_tree, b_tree_sum)
ans += kotae(C, c_tree, c_tree_sum)
if ans < now_ans:
now_ans = ans
def calc_data(
tree_data,
A,
B,
C,
a_tree,
b_tree,
c_tree,
index,
a_tree_sum,
b_tree_sum,
c_tree_sum,
):
if a_tree_sum >= A and b_tree_sum >= B and c_tree_sum >= C:
calc_final(A, B, C, a_tree, b_tree, c_tree, a_tree_sum, b_tree_sum, c_tree_sum)
return
if index == len(tree_data) - 1 or tree_data[index + 1] <= 10:
calc_final(A, B, C, a_tree, b_tree, c_tree, a_tree_sum, b_tree_sum, c_tree_sum)
return
if a_tree_sum < A:
calc_data(
tree_data,
A,
B,
C,
a_tree + 1,
b_tree,
c_tree,
index + 1,
a_tree_sum + tree_data[index + 1],
b_tree_sum,
c_tree_sum,
)
if b_tree_sum < B:
calc_data(
tree_data,
A,
B,
C,
a_tree,
b_tree + 1,
c_tree,
index + 1,
a_tree_sum,
b_tree_sum + tree_data[index + 1],
c_tree_sum,
)
if c_tree_sum < C:
calc_data(
tree_data,
A,
B,
C,
a_tree,
b_tree,
c_tree + 1,
index + 1,
a_tree_sum,
b_tree_sum,
c_tree_sum + tree_data[index + 1],
)
calc_data(
tree_data,
A,
B,
C,
a_tree,
b_tree,
c_tree,
index + 1,
a_tree_sum,
b_tree_sum,
c_tree_sum,
)
def main():
global now_ans
num, A, B, C = list(map(int, input().split()))
tree_data = [int(input()) for i in range(num)]
tree_data.sort(reverse=True)
calc_data(tree_data, A, B, C, 1, 0, 0, 0, tree_data[0], 0, 0)
calc_data(tree_data, A, B, C, 0, 1, 0, 0, 0, tree_data[0], 0)
calc_data(tree_data, A, B, C, 0, 0, 1, 0, 0, 0, tree_data[0])
calc_data(tree_data, A, B, C, 0, 0, 0, 0, 0, 0, 0)
print(now_ans)
if __name__ == "__main__":
main()
| Statement
You have N bamboos. The lengths (in centimeters) of these are l_1, l_2, ...,
l_N, respectively.
Your objective is to use some of these bamboos (possibly all) to obtain three
bamboos of length A, B, C. For that, you can use the following three kinds of
magics any number:
* Extension Magic: Consumes 1 _MP_ (magic point). Choose one bamboo and increase its length by 1.
* Shortening Magic: Consumes 1 MP. Choose one bamboo of length at least 2 and decrease its length by 1.
* Composition Magic: Consumes 10 MP. Choose two bamboos and combine them into one bamboo. The length of this new bamboo is equal to the sum of the lengths of the two bamboos combined. (Afterwards, further magics can be used on this bamboo.)
At least how much MP is needed to achieve the objective? | [{"input": "5 100 90 80\n 98\n 40\n 30\n 21\n 80", "output": "23\n \n\nWe are obtaining three bamboos of lengths 100, 90, 80 from five bamboos 98,\n40, 30, 21, 80. We already have a bamboo of length 80, and we can obtain\nbamboos of lengths 100, 90 by using the magics as follows at the total cost of\n23 MP, which is optimal.\n\n 1. Use Extension Magic twice on the bamboo of length 98 to obtain a bamboo of length 100. (MP consumed: 2)\n 2. Use Composition Magic on the bamboos of lengths 40, 30 to obtain a bamboo of length 70. (MP consumed: 10)\n 3. Use Shortening Magic once on the bamboo of length 21 to obtain a bamboo of length 20. (MP consumed: 1)\n 4. Use Composition Magic on the bamboo of length 70 obtained in step 2 and the bamboo of length 20 obtained in step 3 to obtain a bamboo of length 90. (MP consumed: 10)\n\n* * *"}, {"input": "8 100 90 80\n 100\n 100\n 90\n 90\n 90\n 80\n 80\n 80", "output": "0\n \n\nIf we already have all bamboos of the desired lengths, the amount of MP needed\nis 0. As seen here, we do not necessarily need to use all the bamboos.\n\n* * *"}, {"input": "8 1000 800 100\n 300\n 333\n 400\n 444\n 500\n 555\n 600\n 666", "output": "243"}] |
Print the minimum amount of MP needed to achieve the objective.
* * * | s574568941 | Runtime Error | p03111 | Input is given from Standard Input in the following format:
N A B C
l_1
l_2
:
l_N | n, k = map(int, input().split())
x = list(map(int, input().split()))
mintime = 10**20
for i in range(n - k + 1):
left = x[i]
right = x[i + k - 1]
abss = (abs(left), abs(right))
if left * right >= 0:
mintime = min(mintime, max(abss))
else:
mintime = min(mintime, min(abss) * 2 + max(abss))
print(mintime)
| Statement
You have N bamboos. The lengths (in centimeters) of these are l_1, l_2, ...,
l_N, respectively.
Your objective is to use some of these bamboos (possibly all) to obtain three
bamboos of length A, B, C. For that, you can use the following three kinds of
magics any number:
* Extension Magic: Consumes 1 _MP_ (magic point). Choose one bamboo and increase its length by 1.
* Shortening Magic: Consumes 1 MP. Choose one bamboo of length at least 2 and decrease its length by 1.
* Composition Magic: Consumes 10 MP. Choose two bamboos and combine them into one bamboo. The length of this new bamboo is equal to the sum of the lengths of the two bamboos combined. (Afterwards, further magics can be used on this bamboo.)
At least how much MP is needed to achieve the objective? | [{"input": "5 100 90 80\n 98\n 40\n 30\n 21\n 80", "output": "23\n \n\nWe are obtaining three bamboos of lengths 100, 90, 80 from five bamboos 98,\n40, 30, 21, 80. We already have a bamboo of length 80, and we can obtain\nbamboos of lengths 100, 90 by using the magics as follows at the total cost of\n23 MP, which is optimal.\n\n 1. Use Extension Magic twice on the bamboo of length 98 to obtain a bamboo of length 100. (MP consumed: 2)\n 2. Use Composition Magic on the bamboos of lengths 40, 30 to obtain a bamboo of length 70. (MP consumed: 10)\n 3. Use Shortening Magic once on the bamboo of length 21 to obtain a bamboo of length 20. (MP consumed: 1)\n 4. Use Composition Magic on the bamboo of length 70 obtained in step 2 and the bamboo of length 20 obtained in step 3 to obtain a bamboo of length 90. (MP consumed: 10)\n\n* * *"}, {"input": "8 100 90 80\n 100\n 100\n 90\n 90\n 90\n 80\n 80\n 80", "output": "0\n \n\nIf we already have all bamboos of the desired lengths, the amount of MP needed\nis 0. As seen here, we do not necessarily need to use all the bamboos.\n\n* * *"}, {"input": "8 1000 800 100\n 300\n 333\n 400\n 444\n 500\n 555\n 600\n 666", "output": "243"}] |
Print the minimum amount of MP needed to achieve the objective.
* * * | s271334577 | Accepted | p03111 | Input is given from Standard Input in the following format:
N A B C
l_1
l_2
:
l_N | n, a, b, c = map(int, input().split())
l = sorted([int(input()) for i in range(n)])
ans = 10**10
for order in [[a, b, c], [b, c, a], [c, a, b], [a, c, b], [b, a, c], [c, b, a]]:
mp = 0
l_copy = l.copy()
for goal in order:
tem_mp = 10**10
used = []
for bit in range(1, 2 ** len(l_copy)):
length = 0
cost = 0
count = 0
tem_used = []
for j in range(len(l_copy)):
if (bit >> j) & 1:
length += l_copy[j]
count += 1
if count > 1:
cost += 10
tem_used.append(j)
if tem_mp > abs(goal - length) + cost:
used = tem_used
tem_mp = abs(goal - length) + cost
mp += tem_mp
for u in used[::-1]:
l_copy.pop(u)
ans = min(ans, mp)
print(ans)
| Statement
You have N bamboos. The lengths (in centimeters) of these are l_1, l_2, ...,
l_N, respectively.
Your objective is to use some of these bamboos (possibly all) to obtain three
bamboos of length A, B, C. For that, you can use the following three kinds of
magics any number:
* Extension Magic: Consumes 1 _MP_ (magic point). Choose one bamboo and increase its length by 1.
* Shortening Magic: Consumes 1 MP. Choose one bamboo of length at least 2 and decrease its length by 1.
* Composition Magic: Consumes 10 MP. Choose two bamboos and combine them into one bamboo. The length of this new bamboo is equal to the sum of the lengths of the two bamboos combined. (Afterwards, further magics can be used on this bamboo.)
At least how much MP is needed to achieve the objective? | [{"input": "5 100 90 80\n 98\n 40\n 30\n 21\n 80", "output": "23\n \n\nWe are obtaining three bamboos of lengths 100, 90, 80 from five bamboos 98,\n40, 30, 21, 80. We already have a bamboo of length 80, and we can obtain\nbamboos of lengths 100, 90 by using the magics as follows at the total cost of\n23 MP, which is optimal.\n\n 1. Use Extension Magic twice on the bamboo of length 98 to obtain a bamboo of length 100. (MP consumed: 2)\n 2. Use Composition Magic on the bamboos of lengths 40, 30 to obtain a bamboo of length 70. (MP consumed: 10)\n 3. Use Shortening Magic once on the bamboo of length 21 to obtain a bamboo of length 20. (MP consumed: 1)\n 4. Use Composition Magic on the bamboo of length 70 obtained in step 2 and the bamboo of length 20 obtained in step 3 to obtain a bamboo of length 90. (MP consumed: 10)\n\n* * *"}, {"input": "8 100 90 80\n 100\n 100\n 90\n 90\n 90\n 80\n 80\n 80", "output": "0\n \n\nIf we already have all bamboos of the desired lengths, the amount of MP needed\nis 0. As seen here, we do not necessarily need to use all the bamboos.\n\n* * *"}, {"input": "8 1000 800 100\n 300\n 333\n 400\n 444\n 500\n 555\n 600\n 666", "output": "243"}] |
Print the minimum amount of MP needed to achieve the objective.
* * * | s629352258 | Accepted | p03111 | Input is given from Standard Input in the following format:
N A B C
l_1
l_2
:
l_N | n, A, B, C = map(int, input().split())
l = []
for i in range(n):
a = int(input())
l += [a]
m = []
ans = 9999
for i in range(4**n):
a, b, c = 0, 0, 0
t = 0
if i % 4 == 1:
a += l[0]
elif i % 4 == 2:
b += l[0]
elif i % 4 == 3:
c += l[0]
if i // 4 != 0:
i = i // 4
if i % 4 == 1:
if a != 0:
t += 10
a += l[1]
elif i % 4 == 2:
if b != 0:
t += 10
b += l[1]
elif i % 4 == 3:
if c != 0:
t += 10
c += l[1]
if i // 4 != 0:
i = i // 4
if i % 4 == 1:
if a != 0:
t += 10
a += l[2]
elif i % 4 == 2:
if b != 0:
t += 10
b += l[2]
elif i % 4 == 3:
if c != 0:
t += 10
c += l[2]
if i // 4 != 0:
i = i // 4
if i % 4 == 1:
if a != 0:
t += 10
a += l[3]
elif i % 4 == 2:
if b != 0:
t += 10
b += l[3]
elif i % 4 == 3:
if c != 0:
t += 10
c += l[3]
if i // 4 != 0:
i = i // 4
if i % 4 == 1:
if a != 0:
t += 10
a += l[4]
elif i % 4 == 2:
if b != 0:
t += 10
b += l[4]
elif i % 4 == 3:
if c != 0:
t += 10
c += l[4]
if i // 4 != 0:
i = i // 4
if i % 4 == 1:
if a != 0:
t += 10
a += l[5]
elif i % 4 == 2:
if b != 0:
t += 10
b += l[5]
elif i % 4 == 3:
if c != 0:
t += 10
c += l[5]
if i // 4 != 0:
i = i // 4
if i % 4 == 1:
if a != 0:
t += 10
a += l[6]
elif i % 4 == 2:
if b != 0:
t += 10
b += l[6]
elif i % 4 == 3:
if c != 0:
t += 10
c += l[6]
if i // 4 != 0:
i = i // 4
if i % 4 == 1:
if a != 0:
t += 10
a += l[7]
elif i % 4 == 2:
if b != 0:
t += 10
b += l[7]
elif i % 4 == 3:
if c != 0:
t += 10
c += l[7]
if a == 0 or b == 0 or c == 0:
continue
t += abs(A - a) + abs(B - b) + abs(C - c)
if ans > t:
ans = t
print(ans)
| Statement
You have N bamboos. The lengths (in centimeters) of these are l_1, l_2, ...,
l_N, respectively.
Your objective is to use some of these bamboos (possibly all) to obtain three
bamboos of length A, B, C. For that, you can use the following three kinds of
magics any number:
* Extension Magic: Consumes 1 _MP_ (magic point). Choose one bamboo and increase its length by 1.
* Shortening Magic: Consumes 1 MP. Choose one bamboo of length at least 2 and decrease its length by 1.
* Composition Magic: Consumes 10 MP. Choose two bamboos and combine them into one bamboo. The length of this new bamboo is equal to the sum of the lengths of the two bamboos combined. (Afterwards, further magics can be used on this bamboo.)
At least how much MP is needed to achieve the objective? | [{"input": "5 100 90 80\n 98\n 40\n 30\n 21\n 80", "output": "23\n \n\nWe are obtaining three bamboos of lengths 100, 90, 80 from five bamboos 98,\n40, 30, 21, 80. We already have a bamboo of length 80, and we can obtain\nbamboos of lengths 100, 90 by using the magics as follows at the total cost of\n23 MP, which is optimal.\n\n 1. Use Extension Magic twice on the bamboo of length 98 to obtain a bamboo of length 100. (MP consumed: 2)\n 2. Use Composition Magic on the bamboos of lengths 40, 30 to obtain a bamboo of length 70. (MP consumed: 10)\n 3. Use Shortening Magic once on the bamboo of length 21 to obtain a bamboo of length 20. (MP consumed: 1)\n 4. Use Composition Magic on the bamboo of length 70 obtained in step 2 and the bamboo of length 20 obtained in step 3 to obtain a bamboo of length 90. (MP consumed: 10)\n\n* * *"}, {"input": "8 100 90 80\n 100\n 100\n 90\n 90\n 90\n 80\n 80\n 80", "output": "0\n \n\nIf we already have all bamboos of the desired lengths, the amount of MP needed\nis 0. As seen here, we do not necessarily need to use all the bamboos.\n\n* * *"}, {"input": "8 1000 800 100\n 300\n 333\n 400\n 444\n 500\n 555\n 600\n 666", "output": "243"}] |
Print the minimum amount of MP needed to achieve the objective.
* * * | s539455401 | Accepted | p03111 | Input is given from Standard Input in the following format:
N A B C
l_1
l_2
:
l_N | N, *A = map(int, input().split())
a = [[0] * 4]
r = [0, 1, 2]
for i in range(N):
l = int(input())
a = [
[p[j] + l * (i == j) for j in r] + [p[3] + (i < 3) * 10]
for i in r + [3]
for p in a
]
print(min(sum(abs(p[i] - A[i]) for i in r) - 30 + p[3] for p in a if min(p[:3]) > 0))
| Statement
You have N bamboos. The lengths (in centimeters) of these are l_1, l_2, ...,
l_N, respectively.
Your objective is to use some of these bamboos (possibly all) to obtain three
bamboos of length A, B, C. For that, you can use the following three kinds of
magics any number:
* Extension Magic: Consumes 1 _MP_ (magic point). Choose one bamboo and increase its length by 1.
* Shortening Magic: Consumes 1 MP. Choose one bamboo of length at least 2 and decrease its length by 1.
* Composition Magic: Consumes 10 MP. Choose two bamboos and combine them into one bamboo. The length of this new bamboo is equal to the sum of the lengths of the two bamboos combined. (Afterwards, further magics can be used on this bamboo.)
At least how much MP is needed to achieve the objective? | [{"input": "5 100 90 80\n 98\n 40\n 30\n 21\n 80", "output": "23\n \n\nWe are obtaining three bamboos of lengths 100, 90, 80 from five bamboos 98,\n40, 30, 21, 80. We already have a bamboo of length 80, and we can obtain\nbamboos of lengths 100, 90 by using the magics as follows at the total cost of\n23 MP, which is optimal.\n\n 1. Use Extension Magic twice on the bamboo of length 98 to obtain a bamboo of length 100. (MP consumed: 2)\n 2. Use Composition Magic on the bamboos of lengths 40, 30 to obtain a bamboo of length 70. (MP consumed: 10)\n 3. Use Shortening Magic once on the bamboo of length 21 to obtain a bamboo of length 20. (MP consumed: 1)\n 4. Use Composition Magic on the bamboo of length 70 obtained in step 2 and the bamboo of length 20 obtained in step 3 to obtain a bamboo of length 90. (MP consumed: 10)\n\n* * *"}, {"input": "8 100 90 80\n 100\n 100\n 90\n 90\n 90\n 80\n 80\n 80", "output": "0\n \n\nIf we already have all bamboos of the desired lengths, the amount of MP needed\nis 0. As seen here, we do not necessarily need to use all the bamboos.\n\n* * *"}, {"input": "8 1000 800 100\n 300\n 333\n 400\n 444\n 500\n 555\n 600\n 666", "output": "243"}] |
Print the minimum amount of MP needed to achieve the objective.
* * * | s273048912 | Accepted | p03111 | Input is given from Standard Input in the following format:
N A B C
l_1
l_2
:
l_N | from itertools import permutations, product
N, A, B, C = map(int, input().split())
L = [int(input()) for _ in range(N)]
G = {0: [], 1: [], 2: []}
cmin = 10**5
for x in permutations(range(N), 3):
for y in product(range(4), repeat=N - 3):
G[0] = [x[0]]
G[1] = [x[1]]
G[2] = [x[2]]
G[3] = []
Ind = list(range(N))
Ind.remove(x[0])
Ind.remove(x[1])
Ind.remove(x[2])
for i in range(N - 3):
G[y[i]].append(Ind[i])
cA = 0
nA = len(G[0])
cA = (nA - 1) * 10
xA = 0
for j in range(nA):
xA += L[G[0][j]]
cA += abs(A - xA)
cB = 0
nB = len(G[1])
cB = (nB - 1) * 10
xB = 0
for j in range(nB):
xB += L[G[1][j]]
cB += abs(B - xB)
cC = 0
nC = len(G[2])
cC = (nC - 1) * 10
xC = 0
for j in range(nC):
xC += L[G[2][j]]
cC += abs(C - xC)
cmin = min(cmin, cA + cB + cC)
print(cmin)
| Statement
You have N bamboos. The lengths (in centimeters) of these are l_1, l_2, ...,
l_N, respectively.
Your objective is to use some of these bamboos (possibly all) to obtain three
bamboos of length A, B, C. For that, you can use the following three kinds of
magics any number:
* Extension Magic: Consumes 1 _MP_ (magic point). Choose one bamboo and increase its length by 1.
* Shortening Magic: Consumes 1 MP. Choose one bamboo of length at least 2 and decrease its length by 1.
* Composition Magic: Consumes 10 MP. Choose two bamboos and combine them into one bamboo. The length of this new bamboo is equal to the sum of the lengths of the two bamboos combined. (Afterwards, further magics can be used on this bamboo.)
At least how much MP is needed to achieve the objective? | [{"input": "5 100 90 80\n 98\n 40\n 30\n 21\n 80", "output": "23\n \n\nWe are obtaining three bamboos of lengths 100, 90, 80 from five bamboos 98,\n40, 30, 21, 80. We already have a bamboo of length 80, and we can obtain\nbamboos of lengths 100, 90 by using the magics as follows at the total cost of\n23 MP, which is optimal.\n\n 1. Use Extension Magic twice on the bamboo of length 98 to obtain a bamboo of length 100. (MP consumed: 2)\n 2. Use Composition Magic on the bamboos of lengths 40, 30 to obtain a bamboo of length 70. (MP consumed: 10)\n 3. Use Shortening Magic once on the bamboo of length 21 to obtain a bamboo of length 20. (MP consumed: 1)\n 4. Use Composition Magic on the bamboo of length 70 obtained in step 2 and the bamboo of length 20 obtained in step 3 to obtain a bamboo of length 90. (MP consumed: 10)\n\n* * *"}, {"input": "8 100 90 80\n 100\n 100\n 90\n 90\n 90\n 80\n 80\n 80", "output": "0\n \n\nIf we already have all bamboos of the desired lengths, the amount of MP needed\nis 0. As seen here, we do not necessarily need to use all the bamboos.\n\n* * *"}, {"input": "8 1000 800 100\n 300\n 333\n 400\n 444\n 500\n 555\n 600\n 666", "output": "243"}] |
Print the minimum amount of MP needed to achieve the objective.
* * * | s689693198 | Runtime Error | p03111 | Input is given from Standard Input in the following format:
N A B C
l_1
l_2
:
l_N | a, b, q = input().split()
a, b, q = int(a), int(b), int(q)
s = [int(input()) for i in range(a)]
t = [int(input()) for i in range(b)]
x = [int(input()) for i in range(q)]
dist = ["" for i in range(8)]
dist1 = ["" for i in range(2)]
dist2 = ["" for i in range(4)]
sp1 = ["" for i in range(2)]
tp1 = ["" for i in range(4)]
import bisect
for k in range(q):
p1 = bisect.bisect_left(s, x[k])
if 0 < p1 < a:
dist1[0] = x[k] - s[p1 - 1]
dist1[1] = s[p1] - x[k]
sp1[0] = s[p1 - 1]
sp1[1] = s[p1]
elif p1 == 0:
dist1[0] = s[0] - x[k]
dist1[1] = s[0] - x[k]
sp1[0] = s[0]
sp1[1] = s[0]
elif p1 == a:
dist1[0] = x[k] - s[a - 1]
dist1[1] = x[k] - s[a - 1]
sp1[0] = s[a - 1]
sp1[1] = s[a - 1]
for i in range(2):
p11 = bisect.bisect_left(t, sp1[i])
if 0 < p11 < b:
dist2[0 + 2 * i] = sp1[i] - t[p11 - 1]
dist2[1 + 2 * i] = t[p11] - sp1[i]
if p11 == 0:
dist2[0 + 2 * i] = t[0] - sp1[i]
dist2[1 + 2 * i] = t[0] - sp1[i]
elif p11 == b:
dist2[0 + 2 * i] = sp1[i] - t[b - 1]
dist2[1 + 2 * i] = sp1[i] - t[b - 1]
dist[0] = dist1[0] + dist2[0]
dist[1] = dist1[0] + dist2[1]
dist[2] = dist1[1] + dist2[2]
dist[3] = dist1[1] + dist2[3]
p1 = bisect.bisect_left(t, x[k])
if 0 < p1 < b:
sp1[0] = t[p1 - 1]
sp1[1] = t[p1]
dist1[0] = x[k] - t[p1 - 1]
dist1[1] = t[p1] - x[k]
elif p1 == 0:
sp1[0] = t[0]
sp1[1] = t[0]
dist1[0] = t[0] - x[k]
dist1[1] = t[0] - x[k]
elif p1 == b:
sp1[0] = t[b - 1]
sp1[1] = t[b - 1]
dist1[0] = x[k] - t[b - 1]
dist1[1] = x[k] - t[b - 1]
for i in range(2):
p11 = bisect.bisect_left(s, sp1[i])
if 0 < p11 < a:
dist2[0 + 2 * i] = sp1[i] - s[p11 - 1]
dist2[1 + 2 * i] = s[p11] - sp1[i]
elif p11 == 0:
dist2[0 + 2 * i] = s[0] - sp1[i]
dist2[1 + 2 * i] = s[0] - sp1[i]
elif p11 == a:
dist2[0 + 2 * i] = sp1[i] - s[a - 1]
dist2[1 + 2 * i] = sp1[i] - s[a - 1]
dist[4] = dist1[0] + dist2[0]
dist[5] = dist1[0] + dist2[1]
dist[6] = dist1[1] + dist2[2]
dist[7] = dist1[1] + dist2[3]
ans = min(dist[0], dist[1], dist[2], dist[3], dist[4], dist[5], dist[6], dist[7])
print(ans)
| Statement
You have N bamboos. The lengths (in centimeters) of these are l_1, l_2, ...,
l_N, respectively.
Your objective is to use some of these bamboos (possibly all) to obtain three
bamboos of length A, B, C. For that, you can use the following three kinds of
magics any number:
* Extension Magic: Consumes 1 _MP_ (magic point). Choose one bamboo and increase its length by 1.
* Shortening Magic: Consumes 1 MP. Choose one bamboo of length at least 2 and decrease its length by 1.
* Composition Magic: Consumes 10 MP. Choose two bamboos and combine them into one bamboo. The length of this new bamboo is equal to the sum of the lengths of the two bamboos combined. (Afterwards, further magics can be used on this bamboo.)
At least how much MP is needed to achieve the objective? | [{"input": "5 100 90 80\n 98\n 40\n 30\n 21\n 80", "output": "23\n \n\nWe are obtaining three bamboos of lengths 100, 90, 80 from five bamboos 98,\n40, 30, 21, 80. We already have a bamboo of length 80, and we can obtain\nbamboos of lengths 100, 90 by using the magics as follows at the total cost of\n23 MP, which is optimal.\n\n 1. Use Extension Magic twice on the bamboo of length 98 to obtain a bamboo of length 100. (MP consumed: 2)\n 2. Use Composition Magic on the bamboos of lengths 40, 30 to obtain a bamboo of length 70. (MP consumed: 10)\n 3. Use Shortening Magic once on the bamboo of length 21 to obtain a bamboo of length 20. (MP consumed: 1)\n 4. Use Composition Magic on the bamboo of length 70 obtained in step 2 and the bamboo of length 20 obtained in step 3 to obtain a bamboo of length 90. (MP consumed: 10)\n\n* * *"}, {"input": "8 100 90 80\n 100\n 100\n 90\n 90\n 90\n 80\n 80\n 80", "output": "0\n \n\nIf we already have all bamboos of the desired lengths, the amount of MP needed\nis 0. As seen here, we do not necessarily need to use all the bamboos.\n\n* * *"}, {"input": "8 1000 800 100\n 300\n 333\n 400\n 444\n 500\n 555\n 600\n 666", "output": "243"}] |
Print the minimum amount of MP needed to achieve the objective.
* * * | s638594209 | Wrong Answer | p03111 | Input is given from Standard Input in the following format:
N A B C
l_1
l_2
:
l_N | n, a, b, c = list(map(int, input().split()))
ll = tuple([int(input()) for _ in range(n)])
def nearest(key, lst):
ans = float("inf")
d = float("inf")
for el in lst:
if abs(el - key) < d:
ans = el
d = abs(el - key)
return ans, d
def tend(lln):
llm = list(lln)
al, ad = nearest(a, llm)
llm.remove(al)
bl, bd = nearest(b, llm)
llm.remove(bl)
cl, cd = nearest(c, llm)
return ad + bd + cd
def synth(lln):
lol = []
for i in range(len(lln) - 1):
for j in range(i + 1, len(lln)):
llm = list(lln)
lj = llm.pop(j)
li = llm.pop(i)
llm.append(li + lj)
lol.append(tuple(llm))
return lol
def synth2(lolln):
lol = []
for lln in lolln:
lol.extend(synth(lln))
return tuple(lol)
ans = tend(ll)
lolln = set((ll,))
for i in range(5):
if n >= i + 4:
lolln = set(synth2(lolln))
for lln in lolln:
ans = min(ans, 10 * (i + 1) + tend(lln))
print(ans)
| Statement
You have N bamboos. The lengths (in centimeters) of these are l_1, l_2, ...,
l_N, respectively.
Your objective is to use some of these bamboos (possibly all) to obtain three
bamboos of length A, B, C. For that, you can use the following three kinds of
magics any number:
* Extension Magic: Consumes 1 _MP_ (magic point). Choose one bamboo and increase its length by 1.
* Shortening Magic: Consumes 1 MP. Choose one bamboo of length at least 2 and decrease its length by 1.
* Composition Magic: Consumes 10 MP. Choose two bamboos and combine them into one bamboo. The length of this new bamboo is equal to the sum of the lengths of the two bamboos combined. (Afterwards, further magics can be used on this bamboo.)
At least how much MP is needed to achieve the objective? | [{"input": "5 100 90 80\n 98\n 40\n 30\n 21\n 80", "output": "23\n \n\nWe are obtaining three bamboos of lengths 100, 90, 80 from five bamboos 98,\n40, 30, 21, 80. We already have a bamboo of length 80, and we can obtain\nbamboos of lengths 100, 90 by using the magics as follows at the total cost of\n23 MP, which is optimal.\n\n 1. Use Extension Magic twice on the bamboo of length 98 to obtain a bamboo of length 100. (MP consumed: 2)\n 2. Use Composition Magic on the bamboos of lengths 40, 30 to obtain a bamboo of length 70. (MP consumed: 10)\n 3. Use Shortening Magic once on the bamboo of length 21 to obtain a bamboo of length 20. (MP consumed: 1)\n 4. Use Composition Magic on the bamboo of length 70 obtained in step 2 and the bamboo of length 20 obtained in step 3 to obtain a bamboo of length 90. (MP consumed: 10)\n\n* * *"}, {"input": "8 100 90 80\n 100\n 100\n 90\n 90\n 90\n 80\n 80\n 80", "output": "0\n \n\nIf we already have all bamboos of the desired lengths, the amount of MP needed\nis 0. As seen here, we do not necessarily need to use all the bamboos.\n\n* * *"}, {"input": "8 1000 800 100\n 300\n 333\n 400\n 444\n 500\n 555\n 600\n 666", "output": "243"}] |
Print the minimum amount of MP needed to achieve the objective.
* * * | s028797030 | Accepted | p03111 | Input is given from Standard Input in the following format:
N A B C
l_1
l_2
:
l_N | import itertools
n, a, b, c = map(int, input().split())
l = [int(input()) for i in range(n)]
zairyo = ("A", "B", "C", "N")
zairyo_list = [0] * (4**n)
j = 0
for i in itertools.product(zairyo, repeat=len(l)):
zairyo_list[j] = i
j += 1
mplist = []
for zl in zairyo_list:
if "A" in zl and "B" in zl and "C" in zl:
mp = 0
alist = [l[i] for i, e in enumerate(zl) if e == "A"]
blist = [l[i] for i, e in enumerate(zl) if e == "B"]
clist = [l[i] for i, e in enumerate(zl) if e == "C"]
mp += (len(alist) + len(blist) + len(clist) - 3) * 10
akoho = sum(alist)
bkoho = sum(blist)
ckoho = sum(clist)
mp += abs(akoho - a) + abs(bkoho - b) + abs(ckoho - c)
mplist.append(mp)
print(min(mplist))
| Statement
You have N bamboos. The lengths (in centimeters) of these are l_1, l_2, ...,
l_N, respectively.
Your objective is to use some of these bamboos (possibly all) to obtain three
bamboos of length A, B, C. For that, you can use the following three kinds of
magics any number:
* Extension Magic: Consumes 1 _MP_ (magic point). Choose one bamboo and increase its length by 1.
* Shortening Magic: Consumes 1 MP. Choose one bamboo of length at least 2 and decrease its length by 1.
* Composition Magic: Consumes 10 MP. Choose two bamboos and combine them into one bamboo. The length of this new bamboo is equal to the sum of the lengths of the two bamboos combined. (Afterwards, further magics can be used on this bamboo.)
At least how much MP is needed to achieve the objective? | [{"input": "5 100 90 80\n 98\n 40\n 30\n 21\n 80", "output": "23\n \n\nWe are obtaining three bamboos of lengths 100, 90, 80 from five bamboos 98,\n40, 30, 21, 80. We already have a bamboo of length 80, and we can obtain\nbamboos of lengths 100, 90 by using the magics as follows at the total cost of\n23 MP, which is optimal.\n\n 1. Use Extension Magic twice on the bamboo of length 98 to obtain a bamboo of length 100. (MP consumed: 2)\n 2. Use Composition Magic on the bamboos of lengths 40, 30 to obtain a bamboo of length 70. (MP consumed: 10)\n 3. Use Shortening Magic once on the bamboo of length 21 to obtain a bamboo of length 20. (MP consumed: 1)\n 4. Use Composition Magic on the bamboo of length 70 obtained in step 2 and the bamboo of length 20 obtained in step 3 to obtain a bamboo of length 90. (MP consumed: 10)\n\n* * *"}, {"input": "8 100 90 80\n 100\n 100\n 90\n 90\n 90\n 80\n 80\n 80", "output": "0\n \n\nIf we already have all bamboos of the desired lengths, the amount of MP needed\nis 0. As seen here, we do not necessarily need to use all the bamboos.\n\n* * *"}, {"input": "8 1000 800 100\n 300\n 333\n 400\n 444\n 500\n 555\n 600\n 666", "output": "243"}] |
Print the minimum amount of MP needed to achieve the objective.
* * * | s790252083 | Accepted | p03111 | Input is given from Standard Input in the following format:
N A B C
l_1
l_2
:
l_N | minMP = 100000
def make_patterns(nowstr, count0, count1, count2, count3, rest):
if count0 > N - 2:
return
if count1 > N - 2:
return
if count2 > N - 2:
return
if count3 > N - 3:
return
if rest == 0:
if 0 == count0:
return
if 0 == count1:
return
if 0 == count2:
return
do_calc(list(nowstr), count0, count1, count2)
return
make_patterns(nowstr + "0", count0 + 1, count1, count2, count3, rest - 1)
make_patterns(nowstr + "1", count0, count1 + 1, count2, count3, rest - 1)
make_patterns(nowstr + "2", count0, count1, count2 + 1, count3, rest - 1)
make_patterns(nowstr + "3", count0, count1, count2, count3 + 1, rest - 1)
return
def do_calc(pattern_list, c0, c1, c2):
global minMP
# print(pattern_list)
tempA = 0
tempB = 0
tempC = 0
tempcost = (c0 + c1 + c2 - 3) * 10
for i in range(N):
num = int(pattern_list[i])
if num == 0:
tempA += L_list[i]
if num == 1:
tempB += L_list[i]
if num == 2:
tempC += L_list[i]
tempcost += abs(A - tempA) + abs(B - tempB) + abs(C - tempC)
if tempcost < minMP:
minMP = tempcost
N, A, B, C = map(int, input().split())
L_list = [int(input()) for i in range(N)]
# print(L_list)
make_patterns("", 0, 0, 0, 0, N)
print(minMP)
| Statement
You have N bamboos. The lengths (in centimeters) of these are l_1, l_2, ...,
l_N, respectively.
Your objective is to use some of these bamboos (possibly all) to obtain three
bamboos of length A, B, C. For that, you can use the following three kinds of
magics any number:
* Extension Magic: Consumes 1 _MP_ (magic point). Choose one bamboo and increase its length by 1.
* Shortening Magic: Consumes 1 MP. Choose one bamboo of length at least 2 and decrease its length by 1.
* Composition Magic: Consumes 10 MP. Choose two bamboos and combine them into one bamboo. The length of this new bamboo is equal to the sum of the lengths of the two bamboos combined. (Afterwards, further magics can be used on this bamboo.)
At least how much MP is needed to achieve the objective? | [{"input": "5 100 90 80\n 98\n 40\n 30\n 21\n 80", "output": "23\n \n\nWe are obtaining three bamboos of lengths 100, 90, 80 from five bamboos 98,\n40, 30, 21, 80. We already have a bamboo of length 80, and we can obtain\nbamboos of lengths 100, 90 by using the magics as follows at the total cost of\n23 MP, which is optimal.\n\n 1. Use Extension Magic twice on the bamboo of length 98 to obtain a bamboo of length 100. (MP consumed: 2)\n 2. Use Composition Magic on the bamboos of lengths 40, 30 to obtain a bamboo of length 70. (MP consumed: 10)\n 3. Use Shortening Magic once on the bamboo of length 21 to obtain a bamboo of length 20. (MP consumed: 1)\n 4. Use Composition Magic on the bamboo of length 70 obtained in step 2 and the bamboo of length 20 obtained in step 3 to obtain a bamboo of length 90. (MP consumed: 10)\n\n* * *"}, {"input": "8 100 90 80\n 100\n 100\n 90\n 90\n 90\n 80\n 80\n 80", "output": "0\n \n\nIf we already have all bamboos of the desired lengths, the amount of MP needed\nis 0. As seen here, we do not necessarily need to use all the bamboos.\n\n* * *"}, {"input": "8 1000 800 100\n 300\n 333\n 400\n 444\n 500\n 555\n 600\n 666", "output": "243"}] |
Print the minimum amount of MP needed to achieve the objective.
* * * | s106404321 | Accepted | p03111 | Input is given from Standard Input in the following format:
N A B C
l_1
l_2
:
l_N | N, A, B, C = map(int, input().split(" "))
l = [int(input()) for x in range(N)]
b = []
for x in range(4**N):
o = []
s = -30
for y in range(N):
o.append((x // (4**y)) % 4)
if (0 in o) and (1 in o) and (2 in o):
a = [A, B, C]
for y in range(N):
if o[y] != 3:
a[o[y]] -= l[y]
s += 10
b.append(sum(map(lambda x: x if x > 0 else -x, a)) + s)
print(min(b))
| Statement
You have N bamboos. The lengths (in centimeters) of these are l_1, l_2, ...,
l_N, respectively.
Your objective is to use some of these bamboos (possibly all) to obtain three
bamboos of length A, B, C. For that, you can use the following three kinds of
magics any number:
* Extension Magic: Consumes 1 _MP_ (magic point). Choose one bamboo and increase its length by 1.
* Shortening Magic: Consumes 1 MP. Choose one bamboo of length at least 2 and decrease its length by 1.
* Composition Magic: Consumes 10 MP. Choose two bamboos and combine them into one bamboo. The length of this new bamboo is equal to the sum of the lengths of the two bamboos combined. (Afterwards, further magics can be used on this bamboo.)
At least how much MP is needed to achieve the objective? | [{"input": "5 100 90 80\n 98\n 40\n 30\n 21\n 80", "output": "23\n \n\nWe are obtaining three bamboos of lengths 100, 90, 80 from five bamboos 98,\n40, 30, 21, 80. We already have a bamboo of length 80, and we can obtain\nbamboos of lengths 100, 90 by using the magics as follows at the total cost of\n23 MP, which is optimal.\n\n 1. Use Extension Magic twice on the bamboo of length 98 to obtain a bamboo of length 100. (MP consumed: 2)\n 2. Use Composition Magic on the bamboos of lengths 40, 30 to obtain a bamboo of length 70. (MP consumed: 10)\n 3. Use Shortening Magic once on the bamboo of length 21 to obtain a bamboo of length 20. (MP consumed: 1)\n 4. Use Composition Magic on the bamboo of length 70 obtained in step 2 and the bamboo of length 20 obtained in step 3 to obtain a bamboo of length 90. (MP consumed: 10)\n\n* * *"}, {"input": "8 100 90 80\n 100\n 100\n 90\n 90\n 90\n 80\n 80\n 80", "output": "0\n \n\nIf we already have all bamboos of the desired lengths, the amount of MP needed\nis 0. As seen here, we do not necessarily need to use all the bamboos.\n\n* * *"}, {"input": "8 1000 800 100\n 300\n 333\n 400\n 444\n 500\n 555\n 600\n 666", "output": "243"}] |
Print the minimum amount of MP needed to achieve the objective.
* * * | s895336269 | Wrong Answer | p03111 | Input is given from Standard Input in the following format:
N A B C
l_1
l_2
:
l_N | (
n,
a,
b,
c,
) = map(int, input().split())
bb = [int(input()) for i in range(n)]
res = []
for j in range(4**n - 1):
t = str(bin(j))
tt = t[2:]
ttt = "0" * (2 * n - len(tt)) + tt
tttt = tuple(ttt)
ttttt = tuple(map(int, tttt))
mp = 0
ans = 10000000
lg = [0, 0, 0, 0]
for take in range(n):
use = ttttt[take * 2] * 2 + ttttt[take * 2 + 1]
mp += 10
if lg[use] == 0:
mp -= 10
lg[use] += bb[take]
lg[3] = 0
mp += abs(a - lg[0])
mp += abs(b - lg[1])
mp += abs(c - lg[2])
if ans > mp:
ans = mp
res.append(ans)
print(min(res))
| Statement
You have N bamboos. The lengths (in centimeters) of these are l_1, l_2, ...,
l_N, respectively.
Your objective is to use some of these bamboos (possibly all) to obtain three
bamboos of length A, B, C. For that, you can use the following three kinds of
magics any number:
* Extension Magic: Consumes 1 _MP_ (magic point). Choose one bamboo and increase its length by 1.
* Shortening Magic: Consumes 1 MP. Choose one bamboo of length at least 2 and decrease its length by 1.
* Composition Magic: Consumes 10 MP. Choose two bamboos and combine them into one bamboo. The length of this new bamboo is equal to the sum of the lengths of the two bamboos combined. (Afterwards, further magics can be used on this bamboo.)
At least how much MP is needed to achieve the objective? | [{"input": "5 100 90 80\n 98\n 40\n 30\n 21\n 80", "output": "23\n \n\nWe are obtaining three bamboos of lengths 100, 90, 80 from five bamboos 98,\n40, 30, 21, 80. We already have a bamboo of length 80, and we can obtain\nbamboos of lengths 100, 90 by using the magics as follows at the total cost of\n23 MP, which is optimal.\n\n 1. Use Extension Magic twice on the bamboo of length 98 to obtain a bamboo of length 100. (MP consumed: 2)\n 2. Use Composition Magic on the bamboos of lengths 40, 30 to obtain a bamboo of length 70. (MP consumed: 10)\n 3. Use Shortening Magic once on the bamboo of length 21 to obtain a bamboo of length 20. (MP consumed: 1)\n 4. Use Composition Magic on the bamboo of length 70 obtained in step 2 and the bamboo of length 20 obtained in step 3 to obtain a bamboo of length 90. (MP consumed: 10)\n\n* * *"}, {"input": "8 100 90 80\n 100\n 100\n 90\n 90\n 90\n 80\n 80\n 80", "output": "0\n \n\nIf we already have all bamboos of the desired lengths, the amount of MP needed\nis 0. As seen here, we do not necessarily need to use all the bamboos.\n\n* * *"}, {"input": "8 1000 800 100\n 300\n 333\n 400\n 444\n 500\n 555\n 600\n 666", "output": "243"}] |
Print the minimum amount of MP needed to achieve the objective.
* * * | s988717405 | Accepted | p03111 | Input is given from Standard Input in the following format:
N A B C
l_1
l_2
:
l_N | l = []
n, a, b, c = map(int, input().split())
for i in range(n):
li = int(input())
l.append(li)
d = [a, b, c]
d.sort()
mpmin = sum(l) * 4 + len(l) * 10 + sum(d)
for i in range(4**n):
k = []
kj = i % 4
k.append(kj)
b = int((i - kj) / 4)
l0 = []
l1 = []
l2 = []
l3 = []
if kj == 0:
l0.append(l[0])
elif kj == 1:
l1.append(l[0])
elif kj == 2:
l2.append(l[0])
elif kj == 3:
l3.append(l[0])
for j in range(n - 1):
kj = b % 4
k.append(kj)
b = int((b - kj) / 4)
if kj == 0:
l0.append(l[j + 1])
elif kj == 1:
l1.append(l[j + 1])
elif kj == 2:
l2.append(l[j + 1])
elif kj == 3:
l3.append(l[j + 1])
mp = 0
if len(l0) >= 1:
mp = mp + (len(l0) - 1) * 10
if len(l1) >= 1:
mp = mp + (len(l1) - 1) * 10
if len(l2) >= 1:
mp = mp + (len(l2) - 1) * 10
ls = []
ls = [sum(l0), sum(l1), sum(l2)]
ls.sort()
mp = mp + abs(d[0] - ls[0]) + abs(d[1] - ls[1]) + abs(d[2] - ls[2])
if mpmin > mp and len(l0) >= 1 and len(l1) >= 1 and len(l2) >= 1:
mpmin = mp
print(mpmin)
| Statement
You have N bamboos. The lengths (in centimeters) of these are l_1, l_2, ...,
l_N, respectively.
Your objective is to use some of these bamboos (possibly all) to obtain three
bamboos of length A, B, C. For that, you can use the following three kinds of
magics any number:
* Extension Magic: Consumes 1 _MP_ (magic point). Choose one bamboo and increase its length by 1.
* Shortening Magic: Consumes 1 MP. Choose one bamboo of length at least 2 and decrease its length by 1.
* Composition Magic: Consumes 10 MP. Choose two bamboos and combine them into one bamboo. The length of this new bamboo is equal to the sum of the lengths of the two bamboos combined. (Afterwards, further magics can be used on this bamboo.)
At least how much MP is needed to achieve the objective? | [{"input": "5 100 90 80\n 98\n 40\n 30\n 21\n 80", "output": "23\n \n\nWe are obtaining three bamboos of lengths 100, 90, 80 from five bamboos 98,\n40, 30, 21, 80. We already have a bamboo of length 80, and we can obtain\nbamboos of lengths 100, 90 by using the magics as follows at the total cost of\n23 MP, which is optimal.\n\n 1. Use Extension Magic twice on the bamboo of length 98 to obtain a bamboo of length 100. (MP consumed: 2)\n 2. Use Composition Magic on the bamboos of lengths 40, 30 to obtain a bamboo of length 70. (MP consumed: 10)\n 3. Use Shortening Magic once on the bamboo of length 21 to obtain a bamboo of length 20. (MP consumed: 1)\n 4. Use Composition Magic on the bamboo of length 70 obtained in step 2 and the bamboo of length 20 obtained in step 3 to obtain a bamboo of length 90. (MP consumed: 10)\n\n* * *"}, {"input": "8 100 90 80\n 100\n 100\n 90\n 90\n 90\n 80\n 80\n 80", "output": "0\n \n\nIf we already have all bamboos of the desired lengths, the amount of MP needed\nis 0. As seen here, we do not necessarily need to use all the bamboos.\n\n* * *"}, {"input": "8 1000 800 100\n 300\n 333\n 400\n 444\n 500\n 555\n 600\n 666", "output": "243"}] |
Print the minimum amount of MP needed to achieve the objective.
* * * | s193408769 | Accepted | p03111 | Input is given from Standard Input in the following format:
N A B C
l_1
l_2
:
l_N | n, x, y, z = map(int, input().split())
l = []
cmin = 1000000000
for i in range(n):
l.append(int(input()))
for i in range(4**n):
l1 = []
for j in range(n):
if i >= 4:
l1.append(i % 4)
i = i // 4
elif i != 0:
l1.append(i)
i = 0
else:
l1.append(i)
c1 = 0
c2 = 0
c3 = 0
d1 = 0
d2 = 0
d3 = 0
l1 = l1[::-1]
for j in range(n):
if l1[j] == 0:
pass
elif l1[j] == 1:
c1 += l[j]
d1 += 1
elif l1[j] == 2:
c2 += l[j]
d2 += 1
else:
c3 += l[j]
d3 += 1
if c1 * c2 * c3 != 0:
c = abs(c1 - x) + abs(c2 - y) + abs(c3 - z) + (d1 + d2 + d3 - 3) * 10
if c <= cmin:
cmin = c
print(cmin)
| Statement
You have N bamboos. The lengths (in centimeters) of these are l_1, l_2, ...,
l_N, respectively.
Your objective is to use some of these bamboos (possibly all) to obtain three
bamboos of length A, B, C. For that, you can use the following three kinds of
magics any number:
* Extension Magic: Consumes 1 _MP_ (magic point). Choose one bamboo and increase its length by 1.
* Shortening Magic: Consumes 1 MP. Choose one bamboo of length at least 2 and decrease its length by 1.
* Composition Magic: Consumes 10 MP. Choose two bamboos and combine them into one bamboo. The length of this new bamboo is equal to the sum of the lengths of the two bamboos combined. (Afterwards, further magics can be used on this bamboo.)
At least how much MP is needed to achieve the objective? | [{"input": "5 100 90 80\n 98\n 40\n 30\n 21\n 80", "output": "23\n \n\nWe are obtaining three bamboos of lengths 100, 90, 80 from five bamboos 98,\n40, 30, 21, 80. We already have a bamboo of length 80, and we can obtain\nbamboos of lengths 100, 90 by using the magics as follows at the total cost of\n23 MP, which is optimal.\n\n 1. Use Extension Magic twice on the bamboo of length 98 to obtain a bamboo of length 100. (MP consumed: 2)\n 2. Use Composition Magic on the bamboos of lengths 40, 30 to obtain a bamboo of length 70. (MP consumed: 10)\n 3. Use Shortening Magic once on the bamboo of length 21 to obtain a bamboo of length 20. (MP consumed: 1)\n 4. Use Composition Magic on the bamboo of length 70 obtained in step 2 and the bamboo of length 20 obtained in step 3 to obtain a bamboo of length 90. (MP consumed: 10)\n\n* * *"}, {"input": "8 100 90 80\n 100\n 100\n 90\n 90\n 90\n 80\n 80\n 80", "output": "0\n \n\nIf we already have all bamboos of the desired lengths, the amount of MP needed\nis 0. As seen here, we do not necessarily need to use all the bamboos.\n\n* * *"}, {"input": "8 1000 800 100\n 300\n 333\n 400\n 444\n 500\n 555\n 600\n 666", "output": "243"}] |
Print the minimum amount of MP needed to achieve the objective.
* * * | s799935187 | Accepted | p03111 | Input is given from Standard Input in the following format:
N A B C
l_1
l_2
:
l_N | want = [0, 0, 0]
ans = []
N, want[0], want[1], want[2] = map(int, input().split())
L = []
for _ in range(N):
L.append(int(input()))
table = [0, 1, 2, -1]
import itertools as it
c = list(it.product(table, repeat=N))
for x in c:
ABC = [0, 0, 0, 0]
cnt = -3
for i in range(len(x)):
ABC[x[i]] += L[i]
if x[i] != -1:
cnt += 1
t = ABC.pop(-1)
if 0 in ABC:
continue
val = sum(map(lambda x: abs(x[0] - x[1]), list(zip(ABC, want))))
val += 10 * cnt
ans.append(val)
print(min(ans))
| Statement
You have N bamboos. The lengths (in centimeters) of these are l_1, l_2, ...,
l_N, respectively.
Your objective is to use some of these bamboos (possibly all) to obtain three
bamboos of length A, B, C. For that, you can use the following three kinds of
magics any number:
* Extension Magic: Consumes 1 _MP_ (magic point). Choose one bamboo and increase its length by 1.
* Shortening Magic: Consumes 1 MP. Choose one bamboo of length at least 2 and decrease its length by 1.
* Composition Magic: Consumes 10 MP. Choose two bamboos and combine them into one bamboo. The length of this new bamboo is equal to the sum of the lengths of the two bamboos combined. (Afterwards, further magics can be used on this bamboo.)
At least how much MP is needed to achieve the objective? | [{"input": "5 100 90 80\n 98\n 40\n 30\n 21\n 80", "output": "23\n \n\nWe are obtaining three bamboos of lengths 100, 90, 80 from five bamboos 98,\n40, 30, 21, 80. We already have a bamboo of length 80, and we can obtain\nbamboos of lengths 100, 90 by using the magics as follows at the total cost of\n23 MP, which is optimal.\n\n 1. Use Extension Magic twice on the bamboo of length 98 to obtain a bamboo of length 100. (MP consumed: 2)\n 2. Use Composition Magic on the bamboos of lengths 40, 30 to obtain a bamboo of length 70. (MP consumed: 10)\n 3. Use Shortening Magic once on the bamboo of length 21 to obtain a bamboo of length 20. (MP consumed: 1)\n 4. Use Composition Magic on the bamboo of length 70 obtained in step 2 and the bamboo of length 20 obtained in step 3 to obtain a bamboo of length 90. (MP consumed: 10)\n\n* * *"}, {"input": "8 100 90 80\n 100\n 100\n 90\n 90\n 90\n 80\n 80\n 80", "output": "0\n \n\nIf we already have all bamboos of the desired lengths, the amount of MP needed\nis 0. As seen here, we do not necessarily need to use all the bamboos.\n\n* * *"}, {"input": "8 1000 800 100\n 300\n 333\n 400\n 444\n 500\n 555\n 600\n 666", "output": "243"}] |
Print the minimum amount of MP needed to achieve the objective.
* * * | s605154614 | Accepted | p03111 | Input is given from Standard Input in the following format:
N A B C
l_1
l_2
:
l_N | def c_synthetic_kadomatsu(N, A, B, C, L):
from itertools import permutations
# for j in range(1, N):
# for k in range(1, N - j):
# for l in range(1, N - j - k + 1):
# print(j, k, l, L[:j], L[j:j + k], L[j + k:j + k + l])
ans = float("inf")
for perm in permutations(range(N)):
for j in range(1, N):
for k in range(1, N - j):
for l in range(1, N - j - k + 1):
cost = 0
s, t, u = perm[:j], perm[j : j + k], perm[j + k : j + k + l]
a, b, c = [], [], []
for _s in s:
a.append(L[_s])
for _t in t:
b.append(L[_t])
for _u in u:
c.append(L[_u])
cost += (len(a) + len(b) + len(c) - 3) * 10
cost += abs(sum(a) - A) + abs(sum(b) - B) + abs(sum(c) - C)
ans = min(ans, cost)
return ans
N, A, B, C = [int(i) for i in input().split()]
L = [int(input()) for _ in range(N)]
print(c_synthetic_kadomatsu(N, A, B, C, L))
| Statement
You have N bamboos. The lengths (in centimeters) of these are l_1, l_2, ...,
l_N, respectively.
Your objective is to use some of these bamboos (possibly all) to obtain three
bamboos of length A, B, C. For that, you can use the following three kinds of
magics any number:
* Extension Magic: Consumes 1 _MP_ (magic point). Choose one bamboo and increase its length by 1.
* Shortening Magic: Consumes 1 MP. Choose one bamboo of length at least 2 and decrease its length by 1.
* Composition Magic: Consumes 10 MP. Choose two bamboos and combine them into one bamboo. The length of this new bamboo is equal to the sum of the lengths of the two bamboos combined. (Afterwards, further magics can be used on this bamboo.)
At least how much MP is needed to achieve the objective? | [{"input": "5 100 90 80\n 98\n 40\n 30\n 21\n 80", "output": "23\n \n\nWe are obtaining three bamboos of lengths 100, 90, 80 from five bamboos 98,\n40, 30, 21, 80. We already have a bamboo of length 80, and we can obtain\nbamboos of lengths 100, 90 by using the magics as follows at the total cost of\n23 MP, which is optimal.\n\n 1. Use Extension Magic twice on the bamboo of length 98 to obtain a bamboo of length 100. (MP consumed: 2)\n 2. Use Composition Magic on the bamboos of lengths 40, 30 to obtain a bamboo of length 70. (MP consumed: 10)\n 3. Use Shortening Magic once on the bamboo of length 21 to obtain a bamboo of length 20. (MP consumed: 1)\n 4. Use Composition Magic on the bamboo of length 70 obtained in step 2 and the bamboo of length 20 obtained in step 3 to obtain a bamboo of length 90. (MP consumed: 10)\n\n* * *"}, {"input": "8 100 90 80\n 100\n 100\n 90\n 90\n 90\n 80\n 80\n 80", "output": "0\n \n\nIf we already have all bamboos of the desired lengths, the amount of MP needed\nis 0. As seen here, we do not necessarily need to use all the bamboos.\n\n* * *"}, {"input": "8 1000 800 100\n 300\n 333\n 400\n 444\n 500\n 555\n 600\n 666", "output": "243"}] |
Print the minimum amount of MP needed to achieve the objective.
* * * | s100579348 | Accepted | p03111 | Input is given from Standard Input in the following format:
N A B C
l_1
l_2
:
l_N | def compute():
from sys import stdin
N, A, B, C = list(map(int, stdin.readline().split()))
l = list(int(stdin.readline().split()[0]) for _ in range(N))
dp = {}
abclist = [A, B, C]
def f(bamboo, remain, abc):
if remain == 0:
if abc >= 2:
return 0
# print(bin(bamboo), remain, abc)
return f(bamboo, abclist[abc + 1], abc + 1)
args = (bamboo, remain, abc)
if args in dp:
return dp[args]
dp[args] = 10000
for x in range(N):
if (bamboo & (1 << x)) == 0:
nexbam = bamboo | (1 << x)
mp = abs(remain - l[x])
dp[args] = min(dp[args], mp + f(nexbam, 0, abc))
dp[args] = min(dp[args], 10 + f(nexbam, remain - l[x], abc))
return dp[args]
print(f(0, abclist[0], 0))
if __name__ == "__main__":
compute()
| Statement
You have N bamboos. The lengths (in centimeters) of these are l_1, l_2, ...,
l_N, respectively.
Your objective is to use some of these bamboos (possibly all) to obtain three
bamboos of length A, B, C. For that, you can use the following three kinds of
magics any number:
* Extension Magic: Consumes 1 _MP_ (magic point). Choose one bamboo and increase its length by 1.
* Shortening Magic: Consumes 1 MP. Choose one bamboo of length at least 2 and decrease its length by 1.
* Composition Magic: Consumes 10 MP. Choose two bamboos and combine them into one bamboo. The length of this new bamboo is equal to the sum of the lengths of the two bamboos combined. (Afterwards, further magics can be used on this bamboo.)
At least how much MP is needed to achieve the objective? | [{"input": "5 100 90 80\n 98\n 40\n 30\n 21\n 80", "output": "23\n \n\nWe are obtaining three bamboos of lengths 100, 90, 80 from five bamboos 98,\n40, 30, 21, 80. We already have a bamboo of length 80, and we can obtain\nbamboos of lengths 100, 90 by using the magics as follows at the total cost of\n23 MP, which is optimal.\n\n 1. Use Extension Magic twice on the bamboo of length 98 to obtain a bamboo of length 100. (MP consumed: 2)\n 2. Use Composition Magic on the bamboos of lengths 40, 30 to obtain a bamboo of length 70. (MP consumed: 10)\n 3. Use Shortening Magic once on the bamboo of length 21 to obtain a bamboo of length 20. (MP consumed: 1)\n 4. Use Composition Magic on the bamboo of length 70 obtained in step 2 and the bamboo of length 20 obtained in step 3 to obtain a bamboo of length 90. (MP consumed: 10)\n\n* * *"}, {"input": "8 100 90 80\n 100\n 100\n 90\n 90\n 90\n 80\n 80\n 80", "output": "0\n \n\nIf we already have all bamboos of the desired lengths, the amount of MP needed\nis 0. As seen here, we do not necessarily need to use all the bamboos.\n\n* * *"}, {"input": "8 1000 800 100\n 300\n 333\n 400\n 444\n 500\n 555\n 600\n 666", "output": "243"}] |
Print the minimum amount of MP needed to achieve the objective.
* * * | s963024037 | Runtime Error | p03111 | Input is given from Standard Input in the following format:
N A B C
l_1
l_2
:
l_N | import sys
import numpy as np
def update(df, ol, t):
ol = ol[ol != 10000].reshape(-1, 3)
df = df[df != 10000].reshape(-1, 3)
for idx in range(len(df)):
min_a = np.argmin(ol[:, idx])
max_a = np.argmax(ol[:, idx])
ol[max_a] = ol[min_a] + ol[max_a]
ol[min_a] = 0
ol = ol[ol != 0].reshape(-1, 3)
df = t - ol
return df, ol
v = []
for line in sys.stdin:
v.append([int(i) for i in line.split()])
a, b, c = v[0][1:]
t = [a, b, c]
l = np.squeeze(np.array(v[1:]))
ol = np.zeros((3, len(l)))
ol[0] = l
ol[1] = l
ol[2] = l
ol = ol.transpose()
df = np.zeros((3, len(l)))
df[0] = np.array([a] * len(l)) - l
df[1] = np.array([b] * len(l)) - l
df[2] = np.array([c] * len(l)) - l
df = df.transpose()
count = 0
mp = 0
while count != 3:
for idx, df_v in enumerate(df):
min_v = np.min(np.abs(df_v))
min_v_arg = np.argmin(np.abs(df_v))
if min_v <= 10:
ol[idx, :] = 10000
df[idx, :] = 10000
t[min_v_arg] = -1
count += 1
mp += min_v
if count == 3:
break
if count == 3:
break
df, ol = update(df, ol, t)
mp += 10
print(np.int(mp))
| Statement
You have N bamboos. The lengths (in centimeters) of these are l_1, l_2, ...,
l_N, respectively.
Your objective is to use some of these bamboos (possibly all) to obtain three
bamboos of length A, B, C. For that, you can use the following three kinds of
magics any number:
* Extension Magic: Consumes 1 _MP_ (magic point). Choose one bamboo and increase its length by 1.
* Shortening Magic: Consumes 1 MP. Choose one bamboo of length at least 2 and decrease its length by 1.
* Composition Magic: Consumes 10 MP. Choose two bamboos and combine them into one bamboo. The length of this new bamboo is equal to the sum of the lengths of the two bamboos combined. (Afterwards, further magics can be used on this bamboo.)
At least how much MP is needed to achieve the objective? | [{"input": "5 100 90 80\n 98\n 40\n 30\n 21\n 80", "output": "23\n \n\nWe are obtaining three bamboos of lengths 100, 90, 80 from five bamboos 98,\n40, 30, 21, 80. We already have a bamboo of length 80, and we can obtain\nbamboos of lengths 100, 90 by using the magics as follows at the total cost of\n23 MP, which is optimal.\n\n 1. Use Extension Magic twice on the bamboo of length 98 to obtain a bamboo of length 100. (MP consumed: 2)\n 2. Use Composition Magic on the bamboos of lengths 40, 30 to obtain a bamboo of length 70. (MP consumed: 10)\n 3. Use Shortening Magic once on the bamboo of length 21 to obtain a bamboo of length 20. (MP consumed: 1)\n 4. Use Composition Magic on the bamboo of length 70 obtained in step 2 and the bamboo of length 20 obtained in step 3 to obtain a bamboo of length 90. (MP consumed: 10)\n\n* * *"}, {"input": "8 100 90 80\n 100\n 100\n 90\n 90\n 90\n 80\n 80\n 80", "output": "0\n \n\nIf we already have all bamboos of the desired lengths, the amount of MP needed\nis 0. As seen here, we do not necessarily need to use all the bamboos.\n\n* * *"}, {"input": "8 1000 800 100\n 300\n 333\n 400\n 444\n 500\n 555\n 600\n 666", "output": "243"}] |
Print the minimum amount of MP needed to achieve the objective.
* * * | s893308944 | Wrong Answer | p03111 | Input is given from Standard Input in the following format:
N A B C
l_1
l_2
:
l_N | # coding: utf-8
N, A, B, C = map(int, input().split())
L = []
INF = 10**6
ans = INF
def base10to(n, b):
if int(n / b):
return base10to(int(n / b), b) + str(n % b)
return str(n % b)
for i in range(N):
L.append(int(input()))
for i in range(3**N):
S = base10to(i, 3).zfill(N)
LA = []
LB = []
LC = []
for j in range(N):
if S[j] == "0":
LA.append(L[j])
elif S[j] == "1":
LB.append(L[j])
elif S[j] == "2":
LC.append(L[j])
if not (LA) or not (LB) or not (LC):
continue
dpA = [[INF for b in range(1500)] for a in range(len(LA))]
dpB = [[INF for b in range(1500)] for a in range(len(LB))]
dpC = [[INF for b in range(1500)] for a in range(len(LC))]
for a in range(len(LA)):
l = LA[a]
dpA[a][l] = 0
dpA[a][0] = 0
for b in range(1500):
if a > 0 and b - l >= 0:
dpA[a][b] = min(dpA[a][b], dpA[a][b - 1] + 1, dpA[a - 1][b - l] + 10)
for b in range(1500):
if b > 0:
dpA[a][-(b + 1)] = min(dpA[a][b], dpA[a][-b] + 1)
for a in range(len(LB)):
l = LB[a]
dpB[a][l] = 0
dpB[a][0] = 0
for b in range(1500):
if a > 0 and b - l >= 0:
dpB[a][b] = min(dpB[a][b], dpB[a][b - 1] + 1, dpB[a - 1][b - l] + 10)
for b in range(1500):
if b > 0:
dpB[a][-(b + 1)] = min(dpB[a][b], dpB[a][-b] + 1)
for a in range(len(LC)):
l = LC[a]
dpC[a][l] = 0
dpC[a][0] = 0
for b in range(1500):
if a > 0 and b - l >= 0:
dpC[a][b] = min(dpC[a][b], dpC[a][b - 1] + 1, dpC[a - 1][b - l] + 10)
for b in range(1500):
if b > 0:
dpC[a][-(b + 1)] = min(dpC[a][b], dpC[a][-b] + 1)
ans = min(ans, dpA[len(LA) - 1][A] + dpB[len(LB) - 1][B] + dpC[len(LC) - 1][C])
print(ans)
| Statement
You have N bamboos. The lengths (in centimeters) of these are l_1, l_2, ...,
l_N, respectively.
Your objective is to use some of these bamboos (possibly all) to obtain three
bamboos of length A, B, C. For that, you can use the following three kinds of
magics any number:
* Extension Magic: Consumes 1 _MP_ (magic point). Choose one bamboo and increase its length by 1.
* Shortening Magic: Consumes 1 MP. Choose one bamboo of length at least 2 and decrease its length by 1.
* Composition Magic: Consumes 10 MP. Choose two bamboos and combine them into one bamboo. The length of this new bamboo is equal to the sum of the lengths of the two bamboos combined. (Afterwards, further magics can be used on this bamboo.)
At least how much MP is needed to achieve the objective? | [{"input": "5 100 90 80\n 98\n 40\n 30\n 21\n 80", "output": "23\n \n\nWe are obtaining three bamboos of lengths 100, 90, 80 from five bamboos 98,\n40, 30, 21, 80. We already have a bamboo of length 80, and we can obtain\nbamboos of lengths 100, 90 by using the magics as follows at the total cost of\n23 MP, which is optimal.\n\n 1. Use Extension Magic twice on the bamboo of length 98 to obtain a bamboo of length 100. (MP consumed: 2)\n 2. Use Composition Magic on the bamboos of lengths 40, 30 to obtain a bamboo of length 70. (MP consumed: 10)\n 3. Use Shortening Magic once on the bamboo of length 21 to obtain a bamboo of length 20. (MP consumed: 1)\n 4. Use Composition Magic on the bamboo of length 70 obtained in step 2 and the bamboo of length 20 obtained in step 3 to obtain a bamboo of length 90. (MP consumed: 10)\n\n* * *"}, {"input": "8 100 90 80\n 100\n 100\n 90\n 90\n 90\n 80\n 80\n 80", "output": "0\n \n\nIf we already have all bamboos of the desired lengths, the amount of MP needed\nis 0. As seen here, we do not necessarily need to use all the bamboos.\n\n* * *"}, {"input": "8 1000 800 100\n 300\n 333\n 400\n 444\n 500\n 555\n 600\n 666", "output": "243"}] |
Print the minimum amount of MP needed to achieve the objective.
* * * | s985077991 | Wrong Answer | p03111 | Input is given from Standard Input in the following format:
N A B C
l_1
l_2
:
l_N | N, A, B, C = map(int, input().split())
l = [int(input()) for i in range(N)]
def convert(n):
list_q = []
while True:
a = n % 4
n //= 4
list_q.insert(0, a)
if n == 0:
break
return list_q
MP = -1
for i in range(21, 4**N):
mp_a = 0
mp_b = 0
mp_c = 0
use = convert(i)
a_n = use.count(1)
b_n = use.count(2)
c_n = use.count(3)
if a_n == 0 or b_n == 0 or c_n == 0:
pass
else:
mp_a += 10 * (a_n - 1)
mp_b += 10 * (b_n - 1)
mp_c += 10 * (c_n - 1)
b_a = 0
b_b = 0
b_c = 0
idx = 0
for i in use:
if i == 1:
b_a += l[idx]
elif i == 2:
b_b += l[idx]
elif i == 3:
b_c += l[idx]
idx += 1
mp_a += abs(A - b_a)
mp_b += abs(B - b_b)
mp_c += abs(C - b_c)
mp = mp_a + mp_b + mp_c
if MP == -1 or mp < MP:
MP = mp
print(MP)
| Statement
You have N bamboos. The lengths (in centimeters) of these are l_1, l_2, ...,
l_N, respectively.
Your objective is to use some of these bamboos (possibly all) to obtain three
bamboos of length A, B, C. For that, you can use the following three kinds of
magics any number:
* Extension Magic: Consumes 1 _MP_ (magic point). Choose one bamboo and increase its length by 1.
* Shortening Magic: Consumes 1 MP. Choose one bamboo of length at least 2 and decrease its length by 1.
* Composition Magic: Consumes 10 MP. Choose two bamboos and combine them into one bamboo. The length of this new bamboo is equal to the sum of the lengths of the two bamboos combined. (Afterwards, further magics can be used on this bamboo.)
At least how much MP is needed to achieve the objective? | [{"input": "5 100 90 80\n 98\n 40\n 30\n 21\n 80", "output": "23\n \n\nWe are obtaining three bamboos of lengths 100, 90, 80 from five bamboos 98,\n40, 30, 21, 80. We already have a bamboo of length 80, and we can obtain\nbamboos of lengths 100, 90 by using the magics as follows at the total cost of\n23 MP, which is optimal.\n\n 1. Use Extension Magic twice on the bamboo of length 98 to obtain a bamboo of length 100. (MP consumed: 2)\n 2. Use Composition Magic on the bamboos of lengths 40, 30 to obtain a bamboo of length 70. (MP consumed: 10)\n 3. Use Shortening Magic once on the bamboo of length 21 to obtain a bamboo of length 20. (MP consumed: 1)\n 4. Use Composition Magic on the bamboo of length 70 obtained in step 2 and the bamboo of length 20 obtained in step 3 to obtain a bamboo of length 90. (MP consumed: 10)\n\n* * *"}, {"input": "8 100 90 80\n 100\n 100\n 90\n 90\n 90\n 80\n 80\n 80", "output": "0\n \n\nIf we already have all bamboos of the desired lengths, the amount of MP needed\nis 0. As seen here, we do not necessarily need to use all the bamboos.\n\n* * *"}, {"input": "8 1000 800 100\n 300\n 333\n 400\n 444\n 500\n 555\n 600\n 666", "output": "243"}] |
Print the minimum amount of MP needed to achieve the objective.
* * * | s746605755 | Accepted | p03111 | Input is given from Standard Input in the following format:
N A B C
l_1
l_2
:
l_N | import itertools
N, A, B, C = map(int, input().split())
L = [int(input()) for n in range(N)]
P = []
for n in range(1, N + 1):
P.extend(itertools.combinations([n for n in range(N)], n))
add_len = {s: sum(L[i] for i in s) for s in P}
def cost(v, s):
return 10 * (len(s) - 1) + abs(v - add_len[s])
res = 2 << 30
for a in P:
cost_a = cost(A, a)
if res < cost_a:
continue
for b in P:
cost_b = cost(B, b)
if res < cost_b:
continue
set_a = set(a)
set_b = set(b)
if len(set_a & set_b):
continue
for c in P:
cost_c = cost(C, c)
if res < cost_c:
continue
set_c = set(c)
if len(set_a & set_c) or len(set_b & set_c):
continue
res = min(res, cost_a + cost_b + cost_c)
print(res)
| Statement
You have N bamboos. The lengths (in centimeters) of these are l_1, l_2, ...,
l_N, respectively.
Your objective is to use some of these bamboos (possibly all) to obtain three
bamboos of length A, B, C. For that, you can use the following three kinds of
magics any number:
* Extension Magic: Consumes 1 _MP_ (magic point). Choose one bamboo and increase its length by 1.
* Shortening Magic: Consumes 1 MP. Choose one bamboo of length at least 2 and decrease its length by 1.
* Composition Magic: Consumes 10 MP. Choose two bamboos and combine them into one bamboo. The length of this new bamboo is equal to the sum of the lengths of the two bamboos combined. (Afterwards, further magics can be used on this bamboo.)
At least how much MP is needed to achieve the objective? | [{"input": "5 100 90 80\n 98\n 40\n 30\n 21\n 80", "output": "23\n \n\nWe are obtaining three bamboos of lengths 100, 90, 80 from five bamboos 98,\n40, 30, 21, 80. We already have a bamboo of length 80, and we can obtain\nbamboos of lengths 100, 90 by using the magics as follows at the total cost of\n23 MP, which is optimal.\n\n 1. Use Extension Magic twice on the bamboo of length 98 to obtain a bamboo of length 100. (MP consumed: 2)\n 2. Use Composition Magic on the bamboos of lengths 40, 30 to obtain a bamboo of length 70. (MP consumed: 10)\n 3. Use Shortening Magic once on the bamboo of length 21 to obtain a bamboo of length 20. (MP consumed: 1)\n 4. Use Composition Magic on the bamboo of length 70 obtained in step 2 and the bamboo of length 20 obtained in step 3 to obtain a bamboo of length 90. (MP consumed: 10)\n\n* * *"}, {"input": "8 100 90 80\n 100\n 100\n 90\n 90\n 90\n 80\n 80\n 80", "output": "0\n \n\nIf we already have all bamboos of the desired lengths, the amount of MP needed\nis 0. As seen here, we do not necessarily need to use all the bamboos.\n\n* * *"}, {"input": "8 1000 800 100\n 300\n 333\n 400\n 444\n 500\n 555\n 600\n 666", "output": "243"}] |
For each find operation, print the minimum value. | s211662210 | Accepted | p02350 | n q
query1
query2
:
queryq
In the first line, n (the number of elements in A) and q (the number of
queries) are given. Then, _i_ th query queryi is given in the following
format:
0 s t x
or
1 s t
The first digit represents the type of the query. '0' denotes update(s, t, x)
and '1' denotes find(s, t). | import sys
readline = sys.stdin.readline
write = sys.stdout.write
N, Q = map(int, input().split())
INF = 2**31 - 1
LV = (N - 1).bit_length()
N0 = 2**LV
data = [INF] * (2 * N0)
lazy = [None] * (2 * N0)
def gindex(l, r):
L = (l + N0) >> 1
R = (r + N0) >> 1
lc = 0 if l & 1 else (L & -L).bit_length()
rc = 0 if r & 1 else (R & -R).bit_length()
for i in range(LV):
if rc <= i:
yield R
if L < R and lc <= i:
yield L
L >>= 1
R >>= 1
def propagates(*ids):
for i in reversed(ids):
v = lazy[i - 1]
if v is None:
continue
lazy[2 * i - 1] = data[2 * i - 1] = lazy[2 * i] = data[2 * i] = v
lazy[i - 1] = None
def update(l, r, x):
(*ids,) = gindex(l, r)
propagates(*ids)
L = N0 + l
R = N0 + r
while L < R:
if R & 1:
R -= 1
lazy[R - 1] = data[R - 1] = x
if L & 1:
lazy[L - 1] = data[L - 1] = x
L += 1
L >>= 1
R >>= 1
for i in ids:
data[i - 1] = min(data[2 * i - 1], data[2 * i])
def query(l, r):
propagates(*gindex(l, r))
L = N0 + l
R = N0 + r
s = INF
while L < R:
if R & 1:
R -= 1
s = min(s, data[R - 1])
if L & 1:
s = min(s, data[L - 1])
L += 1
L >>= 1
R >>= 1
return s
ans = []
for q in range(Q):
t, *cmd = map(int, readline().split())
if t:
s, t = cmd
ans.append(str(query(s, t + 1)))
else:
s, t, x = cmd
update(s, t + 1, x)
write("\n".join(ans))
write("\n")
| RMQ and RUQ
Write a program which manipulates a sequence A = {a0, a1, . . . , an−1} with
the following operations:
* update(s, t, x): change as, as+1, ..., at to x.
* find(s, t): report the minimum element in as, as+1, ..., at.
Note that the initial values of ai (i = 0, 1, . . . , n−1) are 231-1. | [{"input": "3 5\n 0 0 1 1\n 0 1 2 3\n 0 2 2 2\n 1 0 2\n 1 1 2", "output": "1\n 2"}, {"input": "1 3\n 1 0 0\n 0 0 0 5\n 1 0 0", "output": "2147483647\n 5"}] |
For each find operation, print the minimum value. | s989359821 | Wrong Answer | p02350 | n q
query1
query2
:
queryq
In the first line, n (the number of elements in A) and q (the number of
queries) are given. Then, _i_ th query queryi is given in the following
format:
0 s t x
or
1 s t
The first digit represents the type of the query. '0' denotes update(s, t, x)
and '1' denotes find(s, t). | INT_MAX = 1 << 31 - 1
_N, query_num = map(int, input().split())
queries = [list(map(int, input().split())) for i in range(query_num)]
N = 1 << 17
arr_size = 2 * N - 1
A = [INT_MAX] * (arr_size)
lazy_A = [None] * (arr_size)
def tree_propagate(k):
if lazy_A[k] is None:
return
if k < N // 2:
A[k * 2 + 1] = A[k * 2 + 2] = lazy_A[k * 2 + 1] = lazy_A[k * 2 + 2] = lazy_A[k]
lazy_A[k] = None
return
if k < N - 1:
A[k * 2 + 1] = A[k * 2 + 2] = lazy_A[k]
lazy_A[k] = None
def update(s, t, x, k, l, r):
if r <= s or t <= l:
return
if s <= l and r <= t:
A[k] = x
if k < N - 1:
lazy_A[k] = x
return
tree_propagate(k)
center = (l + r) // 2
update(s, t, x, k * 2 + 1, l, center)
update(s, t, x, k * 2 + 2, center, r)
A[k] = min(A[k * 2 + 1], A[k * 2 + 2])
def find(s, t, k, l, r):
if r <= s or t <= l:
return INT_MAX
if s <= l and r <= t:
return A[k]
tree_propagate(k)
center = (l + r) // 2
v_left = find(s, t, k * 2 + 1, l, center)
v_right = find(s, t, k * 2 + 2, center, r)
return min(v_left, v_right)
answers = []
for query in queries:
# update
if query[0] == 0:
update(query[1], query[2] + 1, query[3], 0, 0, N)
# find
else:
answers.append(find(query[1], query[2] + 1, 0, 0, N))
print("\n".join([str(ans) for ans in answers]))
| RMQ and RUQ
Write a program which manipulates a sequence A = {a0, a1, . . . , an−1} with
the following operations:
* update(s, t, x): change as, as+1, ..., at to x.
* find(s, t): report the minimum element in as, as+1, ..., at.
Note that the initial values of ai (i = 0, 1, . . . , n−1) are 231-1. | [{"input": "3 5\n 0 0 1 1\n 0 1 2 3\n 0 2 2 2\n 1 0 2\n 1 1 2", "output": "1\n 2"}, {"input": "1 3\n 1 0 0\n 0 0 0 5\n 1 0 0", "output": "2147483647\n 5"}] |
Print the indices of the vertices v such that Takahashi can place the piece on
v at the beginning and win the game, in a line, in ascending order.
* * * | s097084348 | Runtime Error | p03812 | The input is given from Standard Input in the following format:
N
A_1 A_2 … A_N
a_1 b_1
:
a_{N-1} b_{N-1} | #!/usr/bin/env python3
# -*- coding: utf-8 -*-
from fractions import gcd
def readln():
_res = list(map(int, str(input()).split(" ")))
return _res
def calc(x, line):
if line == 0:
for l in v[x]:
if e[l][0] == x:
son = e[l][1]
else:
son = e[l][0]
if a[son - 1] < a[x - 1] and calc(son, l) == -1:
return 1
return -1
else:
if e[line][0] == x:
y = 0
else:
y = 1
if f[x][y] != 0:
return f[x][y]
if len(v[x]) == 1:
f[x][y] = -1
return -1
for l in v[x]:
if l != line:
if e[l][0] == x:
son = e[l][1]
else:
son = e[l][0]
if a[son - 1] < a[x - 1] and calc(son, l) == -1:
f[x][y] = 1
return 1
f[x][y] = -1
return -1
n = int(input())
v = [set([]) for i in range(0, n + 1)]
e = [0 for i in range(0, n)]
a = readln()
for i in range(1, n):
s = readln()
v[s[0]].add(i)
v[s[1]].add(i)
e[i] = s
f = [[0, 0] for i in range(0, n)]
ans = []
for i in range(1, n + 1):
if calc(i, 0) == 1:
ans.append(i)
ans = list(map(str, ans))
print(" ".join(ans))
| Statement
There is a tree with N vertices, numbered 1 through N. The i-th of the N-1
edges connects vertices a_i and b_i.
Currently, there are A_i stones placed on vertex i. Takahashi and Aoki will
play a game using this tree.
First, Takahashi will select a vertex and place a piece on it. Then, starting
from Takahashi, they will alternately perform the following operation:
* Remove one stone from the vertex currently occupied by the piece.
* Then, move the piece to a vertex that is adjacent to the currently occupied vertex.
The player who is left with no stone on the vertex occupied by the piece and
thus cannot perform the operation, loses the game. Find all the vertices v
such that Takahashi can place the piece on v at the beginning and win the
game. | [{"input": "3\n 1 2 3\n 1 2\n 2 3", "output": "2\n \n\nThe following is one possible progress of the game when Takahashi places the\npiece on vertex 2:\n\n * Takahashi moves the piece to vertex 1. The number of the stones on each vertex is now: (1,1,3).\n * Aoki moves the piece to vertex 2. The number of the stones on each vertex is now: (0,1,3).\n * Takahashi moves the piece to vertex 1. The number of the stones on each vertex is now: (0,0,3).\n * Aoki cannot take a stone from the vertex, and thus Takahashi wins.\n\n* * *"}, {"input": "5\n 5 4 1 2 3\n 1 2\n 1 3\n 2 4\n 2 5", "output": "1 2\n \n\n* * *"}, {"input": "3\n 1 1 1\n 1 2\n 2 3", "output": "Note that the correct output may be an empty line."}] |
Print the indices of the vertices v such that Takahashi can place the piece on
v at the beginning and win the game, in a line, in ascending order.
* * * | s094281848 | Runtime Error | p03812 | The input is given from Standard Input in the following format:
N
A_1 A_2 … A_N
a_1 b_1
:
a_{N-1} b_{N-1} | #include <bits/stdc++.h>
//#include <math.h>
using namespace std;
#define INF 1.1e9
#define LINF 1.1e18
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define BIT(x,n) bitset<n>(x)
#define PI 3.14159265358979323846
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,P> PP;
//-----------------------------------------------------------------------------
int n;
vector<int> g[3000];
ll a[3000];
int dp[3000];
int dfs(int v,int prv) {
if(dp[v]!=0) return dp[v];
for(auto u:g[v]) {
if(u!=prv&&a[u]<a[v]&&dfs(u,v)==-1) return dp[v]=1;
}
return dp[v]=-1;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
cin>>n;
REP(i,n) cin>>a[i];
REP(i,n-1) {
int u,v;cin>>u>>v;;u--,v--;
g[u].pb(v),g[v].pb(u);
}
REP(i,n) {
dfs(i,-1);
}
bool fst=true;
REP(i,n) {
if(!fst) cout<<' ';
if(dp[i]==1) {
cout<<i+1;
fst=false;
}
}
cout<<endl;
return 0;
}
| Statement
There is a tree with N vertices, numbered 1 through N. The i-th of the N-1
edges connects vertices a_i and b_i.
Currently, there are A_i stones placed on vertex i. Takahashi and Aoki will
play a game using this tree.
First, Takahashi will select a vertex and place a piece on it. Then, starting
from Takahashi, they will alternately perform the following operation:
* Remove one stone from the vertex currently occupied by the piece.
* Then, move the piece to a vertex that is adjacent to the currently occupied vertex.
The player who is left with no stone on the vertex occupied by the piece and
thus cannot perform the operation, loses the game. Find all the vertices v
such that Takahashi can place the piece on v at the beginning and win the
game. | [{"input": "3\n 1 2 3\n 1 2\n 2 3", "output": "2\n \n\nThe following is one possible progress of the game when Takahashi places the\npiece on vertex 2:\n\n * Takahashi moves the piece to vertex 1. The number of the stones on each vertex is now: (1,1,3).\n * Aoki moves the piece to vertex 2. The number of the stones on each vertex is now: (0,1,3).\n * Takahashi moves the piece to vertex 1. The number of the stones on each vertex is now: (0,0,3).\n * Aoki cannot take a stone from the vertex, and thus Takahashi wins.\n\n* * *"}, {"input": "5\n 5 4 1 2 3\n 1 2\n 1 3\n 2 4\n 2 5", "output": "1 2\n \n\n* * *"}, {"input": "3\n 1 1 1\n 1 2\n 2 3", "output": "Note that the correct output may be an empty line."}] |
If Takahashi will win, print `Yes`; if he will lose, print `No`.
* * * | s207626407 | Accepted | p02700 | Input is given from Standard Input in the following format:
A B C D | h1, a1, h2, a2 = map(int, input().split())
cnt1 = h2 // a1 if h2 % a1 == 0 else h2 // a1 + 1
cnt2 = h1 // a2 if h1 % a2 == 0 else h1 // a2 + 1
print("Yes" if cnt1 <= cnt2 else "No")
| Statement
Takahashi and Aoki will have a battle using their monsters.
The health and strength of Takahashi's monster are A and B, respectively, and
those of Aoki's monster are C and D, respectively.
The two monsters will take turns attacking, in the order Takahashi's, Aoki's,
Takahashi's, Aoki's, ... Here, an attack decreases the opponent's health by
the value equal to the attacker's strength. The monsters keep attacking until
the health of one monster becomes 0 or below. The person with the monster
whose health becomes 0 or below loses, and the other person wins.
If Takahashi will win, print `Yes`; if he will lose, print `No`. | [{"input": "10 9 10 10", "output": "No\n \n\nFirst, Takahashi's monster attacks Aoki's monster, whose health is now 10-9=1.\n\nNext, Aoki's monster attacks Takahashi's monster, whose health is now 10-10=0.\n\nTakahashi's monster is the first to have 0 or less health, so Takahashi loses.\n\n* * *"}, {"input": "46 4 40 5", "output": "Yes"}] |
If Takahashi will win, print `Yes`; if he will lose, print `No`.
* * * | s780925443 | Wrong Answer | p02700 | Input is given from Standard Input in the following format:
A B C D | A, B, C, D = list(map(lambda x: int(x), input().split(" ")))
print("Yes") if int(A / D) > int(C / B) else print("No")
| Statement
Takahashi and Aoki will have a battle using their monsters.
The health and strength of Takahashi's monster are A and B, respectively, and
those of Aoki's monster are C and D, respectively.
The two monsters will take turns attacking, in the order Takahashi's, Aoki's,
Takahashi's, Aoki's, ... Here, an attack decreases the opponent's health by
the value equal to the attacker's strength. The monsters keep attacking until
the health of one monster becomes 0 or below. The person with the monster
whose health becomes 0 or below loses, and the other person wins.
If Takahashi will win, print `Yes`; if he will lose, print `No`. | [{"input": "10 9 10 10", "output": "No\n \n\nFirst, Takahashi's monster attacks Aoki's monster, whose health is now 10-9=1.\n\nNext, Aoki's monster attacks Takahashi's monster, whose health is now 10-10=0.\n\nTakahashi's monster is the first to have 0 or less health, so Takahashi loses.\n\n* * *"}, {"input": "46 4 40 5", "output": "Yes"}] |
If Takahashi will win, print `Yes`; if he will lose, print `No`.
* * * | s022567592 | Wrong Answer | p02700 | Input is given from Standard Input in the following format:
A B C D | A, B, C, D = map(float, input().split())
x = A / D
y = C / B
print("Yes" if x <= y else "No")
| Statement
Takahashi and Aoki will have a battle using their monsters.
The health and strength of Takahashi's monster are A and B, respectively, and
those of Aoki's monster are C and D, respectively.
The two monsters will take turns attacking, in the order Takahashi's, Aoki's,
Takahashi's, Aoki's, ... Here, an attack decreases the opponent's health by
the value equal to the attacker's strength. The monsters keep attacking until
the health of one monster becomes 0 or below. The person with the monster
whose health becomes 0 or below loses, and the other person wins.
If Takahashi will win, print `Yes`; if he will lose, print `No`. | [{"input": "10 9 10 10", "output": "No\n \n\nFirst, Takahashi's monster attacks Aoki's monster, whose health is now 10-9=1.\n\nNext, Aoki's monster attacks Takahashi's monster, whose health is now 10-10=0.\n\nTakahashi's monster is the first to have 0 or less health, so Takahashi loses.\n\n* * *"}, {"input": "46 4 40 5", "output": "Yes"}] |
If Takahashi will win, print `Yes`; if he will lose, print `No`.
* * * | s451032052 | Accepted | p02700 | Input is given from Standard Input in the following format:
A B C D | thp, ta, ahp, aa = map(int, input().split())
ans = []
while thp >= 0 or ahp >= 0:
ahp -= ta
thp -= aa
if ahp <= 0:
ans.append("Yes")
elif thp <= 0:
ans.append("No")
print(ans[0])
| Statement
Takahashi and Aoki will have a battle using their monsters.
The health and strength of Takahashi's monster are A and B, respectively, and
those of Aoki's monster are C and D, respectively.
The two monsters will take turns attacking, in the order Takahashi's, Aoki's,
Takahashi's, Aoki's, ... Here, an attack decreases the opponent's health by
the value equal to the attacker's strength. The monsters keep attacking until
the health of one monster becomes 0 or below. The person with the monster
whose health becomes 0 or below loses, and the other person wins.
If Takahashi will win, print `Yes`; if he will lose, print `No`. | [{"input": "10 9 10 10", "output": "No\n \n\nFirst, Takahashi's monster attacks Aoki's monster, whose health is now 10-9=1.\n\nNext, Aoki's monster attacks Takahashi's monster, whose health is now 10-10=0.\n\nTakahashi's monster is the first to have 0 or less health, so Takahashi loses.\n\n* * *"}, {"input": "46 4 40 5", "output": "Yes"}] |
If Takahashi will win, print `Yes`; if he will lose, print `No`.
* * * | s727628884 | Accepted | p02700 | Input is given from Standard Input in the following format:
A B C D | A, B, C, D = map(int, input().split())
An = A
Cn = C
Ai = 0
Ci = 0
while An > 0:
An = An - D
Ai += 1
while Cn > 0:
Cn = Cn - B
Ci += 1
print("Yes" if Ai >= Ci else "No")
| Statement
Takahashi and Aoki will have a battle using their monsters.
The health and strength of Takahashi's monster are A and B, respectively, and
those of Aoki's monster are C and D, respectively.
The two monsters will take turns attacking, in the order Takahashi's, Aoki's,
Takahashi's, Aoki's, ... Here, an attack decreases the opponent's health by
the value equal to the attacker's strength. The monsters keep attacking until
the health of one monster becomes 0 or below. The person with the monster
whose health becomes 0 or below loses, and the other person wins.
If Takahashi will win, print `Yes`; if he will lose, print `No`. | [{"input": "10 9 10 10", "output": "No\n \n\nFirst, Takahashi's monster attacks Aoki's monster, whose health is now 10-9=1.\n\nNext, Aoki's monster attacks Takahashi's monster, whose health is now 10-10=0.\n\nTakahashi's monster is the first to have 0 or less health, so Takahashi loses.\n\n* * *"}, {"input": "46 4 40 5", "output": "Yes"}] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.