output_description stringlengths 15 956 | submission_id stringlengths 10 10 | status stringclasses 3 values | problem_id stringlengths 6 6 | input_description stringlengths 9 2.55k | attempt stringlengths 1 13.7k | problem_description stringlengths 7 5.24k | samples stringlengths 2 2.72k |
|---|---|---|---|---|---|---|---|
Print the answer.
* * * | s040837315 | Runtime Error | p03548 | Input is given from Standard Input in the following format:
X Y Z | # -*- coding: utf-8 -*-
A, B = input().split()
if int(A, 16) = int(B, 16):
print('=')
elif int(A, 16) > int(B, 16):
print('>')
elif int(A, 16) < int(B, 16):
print('<')
| Statement
We have a long seat of width X centimeters. There are many people who wants to
sit here. A person sitting on the seat will always occupy an interval of
length Y centimeters.
We would like to seat as many people as possible, but they are all very shy,
and there must be a gap of length at least Z centimeters between two people,
and between the end of the seat and a person.
At most how many people can sit on the seat? | [{"input": "13 3 1", "output": "3\n \n\nThere is just enough room for three, as shown below:\n\n\n\nFigure\n\n* * *"}, {"input": "12 3 1", "output": "2\n \n\n* * *"}, {"input": "100000 1 1", "output": "49999\n \n\n* * *"}, {"input": "64146 123 456", "output": "110\n \n\n* * *"}, {"input": "64145 123 456", "output": "109"}] |
Print the answer.
* * * | s405483225 | Accepted | p03548 | Input is given from Standard Input in the following format:
X Y Z | chair, width, isolate = map(int, input().split())
print((chair - isolate) // (width + isolate))
| Statement
We have a long seat of width X centimeters. There are many people who wants to
sit here. A person sitting on the seat will always occupy an interval of
length Y centimeters.
We would like to seat as many people as possible, but they are all very shy,
and there must be a gap of length at least Z centimeters between two people,
and between the end of the seat and a person.
At most how many people can sit on the seat? | [{"input": "13 3 1", "output": "3\n \n\nThere is just enough room for three, as shown below:\n\n\n\nFigure\n\n* * *"}, {"input": "12 3 1", "output": "2\n \n\n* * *"}, {"input": "100000 1 1", "output": "49999\n \n\n* * *"}, {"input": "64146 123 456", "output": "110\n \n\n* * *"}, {"input": "64145 123 456", "output": "109"}] |
Print the answer.
* * * | s613720068 | Wrong Answer | p03548 | Input is given from Standard Input in the following format:
X Y Z | s = input()
x, y, z = [int(i) for i in s.split()]
print(int((x - y) / (y + z)) + 1)
| Statement
We have a long seat of width X centimeters. There are many people who wants to
sit here. A person sitting on the seat will always occupy an interval of
length Y centimeters.
We would like to seat as many people as possible, but they are all very shy,
and there must be a gap of length at least Z centimeters between two people,
and between the end of the seat and a person.
At most how many people can sit on the seat? | [{"input": "13 3 1", "output": "3\n \n\nThere is just enough room for three, as shown below:\n\n\n\nFigure\n\n* * *"}, {"input": "12 3 1", "output": "2\n \n\n* * *"}, {"input": "100000 1 1", "output": "49999\n \n\n* * *"}, {"input": "64146 123 456", "output": "110\n \n\n* * *"}, {"input": "64145 123 456", "output": "109"}] |
Print the answer.
* * * | s790050738 | Runtime Error | p03548 | Input is given from Standard Input in the following format:
X Y Z | import math
a,b,c=map(int,input(),split())
a-=c
print(math.floor(a/(b+c)) | Statement
We have a long seat of width X centimeters. There are many people who wants to
sit here. A person sitting on the seat will always occupy an interval of
length Y centimeters.
We would like to seat as many people as possible, but they are all very shy,
and there must be a gap of length at least Z centimeters between two people,
and between the end of the seat and a person.
At most how many people can sit on the seat? | [{"input": "13 3 1", "output": "3\n \n\nThere is just enough room for three, as shown below:\n\n\n\nFigure\n\n* * *"}, {"input": "12 3 1", "output": "2\n \n\n* * *"}, {"input": "100000 1 1", "output": "49999\n \n\n* * *"}, {"input": "64146 123 456", "output": "110\n \n\n* * *"}, {"input": "64145 123 456", "output": "109"}] |
Print the answer.
* * * | s797711422 | Runtime Error | p03548 | Input is given from Standard Input in the following format:
X Y Z | if Y=n:
z=n-1
X>n+(n-1)=2n-1
これを満たすnが求める人数 | Statement
We have a long seat of width X centimeters. There are many people who wants to
sit here. A person sitting on the seat will always occupy an interval of
length Y centimeters.
We would like to seat as many people as possible, but they are all very shy,
and there must be a gap of length at least Z centimeters between two people,
and between the end of the seat and a person.
At most how many people can sit on the seat? | [{"input": "13 3 1", "output": "3\n \n\nThere is just enough room for three, as shown below:\n\n\n\nFigure\n\n* * *"}, {"input": "12 3 1", "output": "2\n \n\n* * *"}, {"input": "100000 1 1", "output": "49999\n \n\n* * *"}, {"input": "64146 123 456", "output": "110\n \n\n* * *"}, {"input": "64145 123 456", "output": "109"}] |
Print the answer.
* * * | s099926095 | Runtime Error | p03548 | Input is given from Standard Input in the following format:
X Y Z | x,y,z= map(int,input().split())
rem=x-y
print(int(rem/(y+z)+1) | Statement
We have a long seat of width X centimeters. There are many people who wants to
sit here. A person sitting on the seat will always occupy an interval of
length Y centimeters.
We would like to seat as many people as possible, but they are all very shy,
and there must be a gap of length at least Z centimeters between two people,
and between the end of the seat and a person.
At most how many people can sit on the seat? | [{"input": "13 3 1", "output": "3\n \n\nThere is just enough room for three, as shown below:\n\n\n\nFigure\n\n* * *"}, {"input": "12 3 1", "output": "2\n \n\n* * *"}, {"input": "100000 1 1", "output": "49999\n \n\n* * *"}, {"input": "64146 123 456", "output": "110\n \n\n* * *"}, {"input": "64145 123 456", "output": "109"}] |
Print the answer.
* * * | s982709396 | Runtime Error | p03548 | Input is given from Standard Input in the following format:
X Y Z | x,y,z = map(int,input().split())
print(int((x-z)/ (y + z)) | Statement
We have a long seat of width X centimeters. There are many people who wants to
sit here. A person sitting on the seat will always occupy an interval of
length Y centimeters.
We would like to seat as many people as possible, but they are all very shy,
and there must be a gap of length at least Z centimeters between two people,
and between the end of the seat and a person.
At most how many people can sit on the seat? | [{"input": "13 3 1", "output": "3\n \n\nThere is just enough room for three, as shown below:\n\n\n\nFigure\n\n* * *"}, {"input": "12 3 1", "output": "2\n \n\n* * *"}, {"input": "100000 1 1", "output": "49999\n \n\n* * *"}, {"input": "64146 123 456", "output": "110\n \n\n* * *"}, {"input": "64145 123 456", "output": "109"}] |
Print the answer.
* * * | s298094273 | Runtime Error | p03548 | Input is given from Standard Input in the following format:
X Y Z | x,y,z= map(int,input().split())
rem=x-y
print(int(rem/(y+z)) | Statement
We have a long seat of width X centimeters. There are many people who wants to
sit here. A person sitting on the seat will always occupy an interval of
length Y centimeters.
We would like to seat as many people as possible, but they are all very shy,
and there must be a gap of length at least Z centimeters between two people,
and between the end of the seat and a person.
At most how many people can sit on the seat? | [{"input": "13 3 1", "output": "3\n \n\nThere is just enough room for three, as shown below:\n\n\n\nFigure\n\n* * *"}, {"input": "12 3 1", "output": "2\n \n\n* * *"}, {"input": "100000 1 1", "output": "49999\n \n\n* * *"}, {"input": "64146 123 456", "output": "110\n \n\n* * *"}, {"input": "64145 123 456", "output": "109"}] |
Print the answer.
* * * | s835106124 | Runtime Error | p03548 | Input is given from Standard Input in the following format:
X Y Z | jj
| Statement
We have a long seat of width X centimeters. There are many people who wants to
sit here. A person sitting on the seat will always occupy an interval of
length Y centimeters.
We would like to seat as many people as possible, but they are all very shy,
and there must be a gap of length at least Z centimeters between two people,
and between the end of the seat and a person.
At most how many people can sit on the seat? | [{"input": "13 3 1", "output": "3\n \n\nThere is just enough room for three, as shown below:\n\n\n\nFigure\n\n* * *"}, {"input": "12 3 1", "output": "2\n \n\n* * *"}, {"input": "100000 1 1", "output": "49999\n \n\n* * *"}, {"input": "64146 123 456", "output": "110\n \n\n* * *"}, {"input": "64145 123 456", "output": "109"}] |
Print the answer.
* * * | s118663728 | Runtime Error | p03548 | Input is given from Standard Input in the following format:
X Y Z | x, y, z = int(input().split())
print((x - z) // y)
| Statement
We have a long seat of width X centimeters. There are many people who wants to
sit here. A person sitting on the seat will always occupy an interval of
length Y centimeters.
We would like to seat as many people as possible, but they are all very shy,
and there must be a gap of length at least Z centimeters between two people,
and between the end of the seat and a person.
At most how many people can sit on the seat? | [{"input": "13 3 1", "output": "3\n \n\nThere is just enough room for three, as shown below:\n\n\n\nFigure\n\n* * *"}, {"input": "12 3 1", "output": "2\n \n\n* * *"}, {"input": "100000 1 1", "output": "49999\n \n\n* * *"}, {"input": "64146 123 456", "output": "110\n \n\n* * *"}, {"input": "64145 123 456", "output": "109"}] |
Print the minimum number of hugs needed to make S palindromic.
* * * | s087540897 | Accepted | p02836 | Input is given from Standard Input in the following format:
S | title = str(input())
leng = len(title)
times = 0
if not leng % 2:
for i in range(1, int(leng / 2) + 1):
if not title[-i] == title[-leng + i + -1]:
title[-i].replace(title[-i], title[-leng + i - 1])
times += 1
else:
for i in range(1, int(leng / 2) + 1):
if not title[-i] == title[-leng + i - 1]:
title[-i].replace(title[-i], title[-leng + i - 1])
times += 1
print(times)
| Statement
Takahashi loves palindromes. Non-palindromic strings are unacceptable to him.
Each time he hugs a string, he can change one of its characters to any
character of his choice.
Given is a string S. Find the minimum number of hugs needed to make S
palindromic. | [{"input": "redcoder", "output": "1\n \n\nFor example, we can change the fourth character to `o` and get a palindrome\n`redooder`.\n\n* * *"}, {"input": "vvvvvv", "output": "0\n \n\nWe might need no hugs at all.\n\n* * *"}, {"input": "abcdabc", "output": "2"}] |
Print the minimum number of hugs needed to make S palindromic.
* * * | s532168096 | Runtime Error | p02836 | Input is given from Standard Input in the following format:
S | n = int(input())
w = list(map(int, input().split()))
sum_w = sum(w)
sum_a = 0
sa = []
for i in range(n):
sum_a += w[i]
sa.append(abs(sum_w - sum_a * 2))
print(min(sa))
| Statement
Takahashi loves palindromes. Non-palindromic strings are unacceptable to him.
Each time he hugs a string, he can change one of its characters to any
character of his choice.
Given is a string S. Find the minimum number of hugs needed to make S
palindromic. | [{"input": "redcoder", "output": "1\n \n\nFor example, we can change the fourth character to `o` and get a palindrome\n`redooder`.\n\n* * *"}, {"input": "vvvvvv", "output": "0\n \n\nWe might need no hugs at all.\n\n* * *"}, {"input": "abcdabc", "output": "2"}] |
Print the minimum number of hugs needed to make S palindromic.
* * * | s786345603 | Accepted | p02836 | Input is given from Standard Input in the following format:
S | R = 0
S = list(input())
c = len(S)
for i in range(c // 2 + 1):
if S[i] != S[c - i - 1]:
R = R + 1
S[c - i - 1] = S[i]
print(R)
| Statement
Takahashi loves palindromes. Non-palindromic strings are unacceptable to him.
Each time he hugs a string, he can change one of its characters to any
character of his choice.
Given is a string S. Find the minimum number of hugs needed to make S
palindromic. | [{"input": "redcoder", "output": "1\n \n\nFor example, we can change the fourth character to `o` and get a palindrome\n`redooder`.\n\n* * *"}, {"input": "vvvvvv", "output": "0\n \n\nWe might need no hugs at all.\n\n* * *"}, {"input": "abcdabc", "output": "2"}] |
Print the minimum number of hugs needed to make S palindromic.
* * * | s721701081 | Wrong Answer | p02836 | Input is given from Standard Input in the following format:
S | A = list(input())
B = list(reversed(A))
S = 0
for i in range((len(A) - 1) // 2):
if A[i] != B[i]:
S += 1
print(S)
| Statement
Takahashi loves palindromes. Non-palindromic strings are unacceptable to him.
Each time he hugs a string, he can change one of its characters to any
character of his choice.
Given is a string S. Find the minimum number of hugs needed to make S
palindromic. | [{"input": "redcoder", "output": "1\n \n\nFor example, we can change the fourth character to `o` and get a palindrome\n`redooder`.\n\n* * *"}, {"input": "vvvvvv", "output": "0\n \n\nWe might need no hugs at all.\n\n* * *"}, {"input": "abcdabc", "output": "2"}] |
Print the minimum number of hugs needed to make S palindromic.
* * * | s750246950 | Accepted | p02836 | Input is given from Standard Input in the following format:
S | validate_list, s = list(), list(input())
validate_list = [s[i] == s[-i - 1] for i in range(len(s))]
print(int(validate_list.count(False) / 2))
| Statement
Takahashi loves palindromes. Non-palindromic strings are unacceptable to him.
Each time he hugs a string, he can change one of its characters to any
character of his choice.
Given is a string S. Find the minimum number of hugs needed to make S
palindromic. | [{"input": "redcoder", "output": "1\n \n\nFor example, we can change the fourth character to `o` and get a palindrome\n`redooder`.\n\n* * *"}, {"input": "vvvvvv", "output": "0\n \n\nWe might need no hugs at all.\n\n* * *"}, {"input": "abcdabc", "output": "2"}] |
Print the minimum number of hugs needed to make S palindromic.
* * * | s775426970 | Wrong Answer | p02836 | Input is given from Standard Input in the following format:
S | Y = str(input()) # 1行に沢山の数値(または文字)が並んでいる場合にリストに格納していく
X = []
X = list(Y) # 数値YをリストXに格納
print(X)
n = len(X)
m = 0
if n % 2 == 0:
for i in range(0, n):
if X[i] == X[n - i - 1]:
m = m + 1
else:
m = m
a = (n - m) / 2
elif n % 2 == 1:
for i in range(0, n):
if X[i] == X[n - i - 1]:
m = m + 1
else:
m = m
a = (n - m) / 2
print(int(a))
| Statement
Takahashi loves palindromes. Non-palindromic strings are unacceptable to him.
Each time he hugs a string, he can change one of its characters to any
character of his choice.
Given is a string S. Find the minimum number of hugs needed to make S
palindromic. | [{"input": "redcoder", "output": "1\n \n\nFor example, we can change the fourth character to `o` and get a palindrome\n`redooder`.\n\n* * *"}, {"input": "vvvvvv", "output": "0\n \n\nWe might need no hugs at all.\n\n* * *"}, {"input": "abcdabc", "output": "2"}] |
Print the minimum number of hugs needed to make S palindromic.
* * * | s459310112 | Accepted | p02836 | Input is given from Standard Input in the following format:
S | S = list(input())
C = len(S)
# print(S)
# print(S[1])
D = 0
for n in range(C):
if S[n] != S[C - n - 1]:
D = D + 1
print(round(D / 2))
| Statement
Takahashi loves palindromes. Non-palindromic strings are unacceptable to him.
Each time he hugs a string, he can change one of its characters to any
character of his choice.
Given is a string S. Find the minimum number of hugs needed to make S
palindromic. | [{"input": "redcoder", "output": "1\n \n\nFor example, we can change the fourth character to `o` and get a palindrome\n`redooder`.\n\n* * *"}, {"input": "vvvvvv", "output": "0\n \n\nWe might need no hugs at all.\n\n* * *"}, {"input": "abcdabc", "output": "2"}] |
Print the minimum number of hugs needed to make S palindromic.
* * * | s987843303 | Wrong Answer | p02836 | Input is given from Standard Input in the following format:
S | S = input()
T = 0
K = len(S) if len(S) % 2 == 0 else len(S) + 1
for i in range(K // 2 - 1):
if S[i] != S[K // 2 + i]:
T += 1
print(T)
| Statement
Takahashi loves palindromes. Non-palindromic strings are unacceptable to him.
Each time he hugs a string, he can change one of its characters to any
character of his choice.
Given is a string S. Find the minimum number of hugs needed to make S
palindromic. | [{"input": "redcoder", "output": "1\n \n\nFor example, we can change the fourth character to `o` and get a palindrome\n`redooder`.\n\n* * *"}, {"input": "vvvvvv", "output": "0\n \n\nWe might need no hugs at all.\n\n* * *"}, {"input": "abcdabc", "output": "2"}] |
Print the minimum number of hugs needed to make S palindromic.
* * * | s284821013 | Runtime Error | p02836 | Input is given from Standard Input in the following format:
S | a = input()
a = list(a)
b = len(a)
c = b / 2
d = []
for i in range(0, c):
d.append(a[i])
e = a[::-1]
f = []
for g in range(0, c):
f.append(e[g])
answer = 0
for h in range(0, c):
if d[h] != f[h]:
answer += 1
print(answer)
| Statement
Takahashi loves palindromes. Non-palindromic strings are unacceptable to him.
Each time he hugs a string, he can change one of its characters to any
character of his choice.
Given is a string S. Find the minimum number of hugs needed to make S
palindromic. | [{"input": "redcoder", "output": "1\n \n\nFor example, we can change the fourth character to `o` and get a palindrome\n`redooder`.\n\n* * *"}, {"input": "vvvvvv", "output": "0\n \n\nWe might need no hugs at all.\n\n* * *"}, {"input": "abcdabc", "output": "2"}] |
Print the minimum number of hugs needed to make S palindromic.
* * * | s701427829 | Accepted | p02836 | Input is given from Standard Input in the following format:
S | import sys
S = input()
Skai = list(S)
Skai.reverse()
S = list(S)
num = len(S)
i = 0
Slist = []
Skailist = []
for j in range(num):
if S[j] != Skai[j]:
i += 1
Skailist.append(Skai[j])
Slist.append(S[j])
if Slist == Skailist:
print(len(Skailist))
sys.exit()
print(int(i / 2))
| Statement
Takahashi loves palindromes. Non-palindromic strings are unacceptable to him.
Each time he hugs a string, he can change one of its characters to any
character of his choice.
Given is a string S. Find the minimum number of hugs needed to make S
palindromic. | [{"input": "redcoder", "output": "1\n \n\nFor example, we can change the fourth character to `o` and get a palindrome\n`redooder`.\n\n* * *"}, {"input": "vvvvvv", "output": "0\n \n\nWe might need no hugs at all.\n\n* * *"}, {"input": "abcdabc", "output": "2"}] |
Print the minimum number of hugs needed to make S palindromic.
* * * | s948574932 | Wrong Answer | p02836 | Input is given from Standard Input in the following format:
S | A = list(input())
B = round(len(A) / 2)
if len(A) % 2 != 0:
A.pop(B - 1)
R = 0
C = A[0:B]
D = A[-B:]
D = D[::-1]
count = 0
for i in range(B - 1):
if C[count] != D[count]:
R += 1
count += 1
print(str(R))
| Statement
Takahashi loves palindromes. Non-palindromic strings are unacceptable to him.
Each time he hugs a string, he can change one of its characters to any
character of his choice.
Given is a string S. Find the minimum number of hugs needed to make S
palindromic. | [{"input": "redcoder", "output": "1\n \n\nFor example, we can change the fourth character to `o` and get a palindrome\n`redooder`.\n\n* * *"}, {"input": "vvvvvv", "output": "0\n \n\nWe might need no hugs at all.\n\n* * *"}, {"input": "abcdabc", "output": "2"}] |
Print `YES` if there exists a tree that has the property mentioned by
Takahashi; print `NO` otherwise.
* * * | s053035247 | Wrong Answer | p03724 | Input is given from Standard Input in the following format:
N M
a_1 b_1
:
a_M b_M | import sys
import math
import copy
import heapq
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 lcm(x, y):
return (x * y) // math.gcd(x, y)
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 fprint(c):
print(c)
sys.stdout.flush()
def solve():
n, m = getList()
g = [[] for i in range(n + 1)]
ji = [0 for i in range(n + 1)]
for i in range(m):
a, b = getList()
g[a].append(b)
g[b].append(a)
ji[a] += 1
ji[b] += 1
# print(ji)
# print(g)
for i in range(n - 1):
if ji[i] % 2 == 1:
for q in g[i]:
if ji[q] % 2 == 0:
print("NO")
return
print("YES")
def main():
n = getN()
for _ in range(n):
solve()
return
if __name__ == "__main__":
# main()
solve()
| Statement
Takahashi is not good at problems about trees in programming contests, and
Aoki is helping him practice.
First, Takahashi created a tree with N vertices numbered 1 through N, and
wrote 0 at each edge.
Then, Aoki gave him M queries. The i-th of them is as follows:
* Increment the number written at each edge along the path connecting vertices a_i and b_i, by one.
After Takahashi executed all of the queries, he told Aoki that, for every
edge, the written number became an even number. However, Aoki forgot to
confirm that the graph Takahashi created was actually a tree, and it is
possible that Takahashi made a mistake in creating a tree or executing
queries.
Determine whether there exists a tree that has the property mentioned by
Takahashi. | [{"input": "4 4\n 1 2\n 2 4\n 1 3\n 3 4", "output": "YES\n \n\nFor example, Takahashi's graph has the property mentioned by him if it has the\nfollowing edges: 1-2, 1-3 and 1-4. In this case, the number written at every\nedge will become 2.\n\n* * *"}, {"input": "5 5\n 1 2\n 3 5\n 5 1\n 3 4\n 2 3", "output": "NO"}] |
Print `YES` if there exists a tree that has the property mentioned by
Takahashi; print `NO` otherwise.
* * * | s998186129 | Wrong Answer | p03724 | Input is given from Standard Input in the following format:
N M
a_1 b_1
:
a_M b_M | n, _, *l = map(int, open(0).read().split())
c = [0] * -~n
for a, b in zip(l[::2], l[1::2]):
c[a] ^= 1
c[b] ^= 1
print("YNEOS"[any(i for i in l) :: 2])
| Statement
Takahashi is not good at problems about trees in programming contests, and
Aoki is helping him practice.
First, Takahashi created a tree with N vertices numbered 1 through N, and
wrote 0 at each edge.
Then, Aoki gave him M queries. The i-th of them is as follows:
* Increment the number written at each edge along the path connecting vertices a_i and b_i, by one.
After Takahashi executed all of the queries, he told Aoki that, for every
edge, the written number became an even number. However, Aoki forgot to
confirm that the graph Takahashi created was actually a tree, and it is
possible that Takahashi made a mistake in creating a tree or executing
queries.
Determine whether there exists a tree that has the property mentioned by
Takahashi. | [{"input": "4 4\n 1 2\n 2 4\n 1 3\n 3 4", "output": "YES\n \n\nFor example, Takahashi's graph has the property mentioned by him if it has the\nfollowing edges: 1-2, 1-3 and 1-4. In this case, the number written at every\nedge will become 2.\n\n* * *"}, {"input": "5 5\n 1 2\n 3 5\n 5 1\n 3 4\n 2 3", "output": "NO"}] |
Print `YES` if there exists a tree that has the property mentioned by
Takahashi; print `NO` otherwise.
* * * | s633423567 | Wrong Answer | p03724 | Input is given from Standard Input in the following format:
N M
a_1 b_1
:
a_M b_M | print(0)
| Statement
Takahashi is not good at problems about trees in programming contests, and
Aoki is helping him practice.
First, Takahashi created a tree with N vertices numbered 1 through N, and
wrote 0 at each edge.
Then, Aoki gave him M queries. The i-th of them is as follows:
* Increment the number written at each edge along the path connecting vertices a_i and b_i, by one.
After Takahashi executed all of the queries, he told Aoki that, for every
edge, the written number became an even number. However, Aoki forgot to
confirm that the graph Takahashi created was actually a tree, and it is
possible that Takahashi made a mistake in creating a tree or executing
queries.
Determine whether there exists a tree that has the property mentioned by
Takahashi. | [{"input": "4 4\n 1 2\n 2 4\n 1 3\n 3 4", "output": "YES\n \n\nFor example, Takahashi's graph has the property mentioned by him if it has the\nfollowing edges: 1-2, 1-3 and 1-4. In this case, the number written at every\nedge will become 2.\n\n* * *"}, {"input": "5 5\n 1 2\n 3 5\n 5 1\n 3 4\n 2 3", "output": "NO"}] |
Print `YES` if there exists a tree that has the property mentioned by
Takahashi; print `NO` otherwise.
* * * | s797163987 | Wrong Answer | p03724 | Input is given from Standard Input in the following format:
N M
a_1 b_1
:
a_M b_M | n, _, *t = open(0).read().split()
print("YNEOS"[int(n) > len(set(sorted(t)[::2])) :: 2])
| Statement
Takahashi is not good at problems about trees in programming contests, and
Aoki is helping him practice.
First, Takahashi created a tree with N vertices numbered 1 through N, and
wrote 0 at each edge.
Then, Aoki gave him M queries. The i-th of them is as follows:
* Increment the number written at each edge along the path connecting vertices a_i and b_i, by one.
After Takahashi executed all of the queries, he told Aoki that, for every
edge, the written number became an even number. However, Aoki forgot to
confirm that the graph Takahashi created was actually a tree, and it is
possible that Takahashi made a mistake in creating a tree or executing
queries.
Determine whether there exists a tree that has the property mentioned by
Takahashi. | [{"input": "4 4\n 1 2\n 2 4\n 1 3\n 3 4", "output": "YES\n \n\nFor example, Takahashi's graph has the property mentioned by him if it has the\nfollowing edges: 1-2, 1-3 and 1-4. In this case, the number written at every\nedge will become 2.\n\n* * *"}, {"input": "5 5\n 1 2\n 3 5\n 5 1\n 3 4\n 2 3", "output": "NO"}] |
Print `YES` if there exists a tree that has the property mentioned by
Takahashi; print `NO` otherwise.
* * * | s877757969 | Runtime Error | p03724 | Input is given from Standard Input in the following format:
N M
a_1 b_1
:
a_M b_M | c = [0] * 10**5
for i in open(0).read().split()[::2]:
c[int(i)] ^= 1
print("NO" if any(c) else "YES")
| Statement
Takahashi is not good at problems about trees in programming contests, and
Aoki is helping him practice.
First, Takahashi created a tree with N vertices numbered 1 through N, and
wrote 0 at each edge.
Then, Aoki gave him M queries. The i-th of them is as follows:
* Increment the number written at each edge along the path connecting vertices a_i and b_i, by one.
After Takahashi executed all of the queries, he told Aoki that, for every
edge, the written number became an even number. However, Aoki forgot to
confirm that the graph Takahashi created was actually a tree, and it is
possible that Takahashi made a mistake in creating a tree or executing
queries.
Determine whether there exists a tree that has the property mentioned by
Takahashi. | [{"input": "4 4\n 1 2\n 2 4\n 1 3\n 3 4", "output": "YES\n \n\nFor example, Takahashi's graph has the property mentioned by him if it has the\nfollowing edges: 1-2, 1-3 and 1-4. In this case, the number written at every\nedge will become 2.\n\n* * *"}, {"input": "5 5\n 1 2\n 3 5\n 5 1\n 3 4\n 2 3", "output": "NO"}] |
Print `YES` if there exists a tree that has the property mentioned by
Takahashi; print `NO` otherwise.
* * * | s497886674 | Runtime Error | p03724 | Input is given from Standard Input in the following format:
N M
a_1 b_1
:
a_M b_M | n,m = map(int,input().split())
ans = [0]*n
for i in range(m):
a,b = map(int,input().split())
a-=1,b-=1
ans[a] +=1
ans[b] +=1
for i in range(n):
if ans[i]%2 ==1:
print("NO")
exit()
print("YES") | Statement
Takahashi is not good at problems about trees in programming contests, and
Aoki is helping him practice.
First, Takahashi created a tree with N vertices numbered 1 through N, and
wrote 0 at each edge.
Then, Aoki gave him M queries. The i-th of them is as follows:
* Increment the number written at each edge along the path connecting vertices a_i and b_i, by one.
After Takahashi executed all of the queries, he told Aoki that, for every
edge, the written number became an even number. However, Aoki forgot to
confirm that the graph Takahashi created was actually a tree, and it is
possible that Takahashi made a mistake in creating a tree or executing
queries.
Determine whether there exists a tree that has the property mentioned by
Takahashi. | [{"input": "4 4\n 1 2\n 2 4\n 1 3\n 3 4", "output": "YES\n \n\nFor example, Takahashi's graph has the property mentioned by him if it has the\nfollowing edges: 1-2, 1-3 and 1-4. In this case, the number written at every\nedge will become 2.\n\n* * *"}, {"input": "5 5\n 1 2\n 3 5\n 5 1\n 3 4\n 2 3", "output": "NO"}] |
Print `YES` if there exists a tree that has the property mentioned by
Takahashi; print `NO` otherwise.
* * * | s724987475 | Runtime Error | p03724 | Input is given from Standard Input in the following format:
N M
a_1 b_1
:
a_M b_M | n,m=map(int,input().split())
g=[[]*for _ in range(n+1)]
for _ in range(m):
u,v=map(int,input().split())
g[u].append(v)
g[v].append(u)
flag=True
for i in range(1,n+1):
if g[i]%2==0:
continue
else:
flag=False
break
if flag==True:
print('YES')
else:
print('NO') | Statement
Takahashi is not good at problems about trees in programming contests, and
Aoki is helping him practice.
First, Takahashi created a tree with N vertices numbered 1 through N, and
wrote 0 at each edge.
Then, Aoki gave him M queries. The i-th of them is as follows:
* Increment the number written at each edge along the path connecting vertices a_i and b_i, by one.
After Takahashi executed all of the queries, he told Aoki that, for every
edge, the written number became an even number. However, Aoki forgot to
confirm that the graph Takahashi created was actually a tree, and it is
possible that Takahashi made a mistake in creating a tree or executing
queries.
Determine whether there exists a tree that has the property mentioned by
Takahashi. | [{"input": "4 4\n 1 2\n 2 4\n 1 3\n 3 4", "output": "YES\n \n\nFor example, Takahashi's graph has the property mentioned by him if it has the\nfollowing edges: 1-2, 1-3 and 1-4. In this case, the number written at every\nedge will become 2.\n\n* * *"}, {"input": "5 5\n 1 2\n 3 5\n 5 1\n 3 4\n 2 3", "output": "NO"}] |
Print `YES` if there exists a tree that has the property mentioned by
Takahashi; print `NO` otherwise.
* * * | s591255610 | Runtime Error | p03724 | Input is given from Standard Input in the following format:
N M
a_1 b_1
:
a_M b_M | N, M = map(int, input().split())
D = {i: 0 for i in range(1, N + 1)}
for i in range(M):
a, b = map(int, input().split())
D[a], D[b] += 1
p = 0
for i in D:
if i % 2 == 1:
p = 1
if p == 0:
print("YES")
else:
print("NO")
| Statement
Takahashi is not good at problems about trees in programming contests, and
Aoki is helping him practice.
First, Takahashi created a tree with N vertices numbered 1 through N, and
wrote 0 at each edge.
Then, Aoki gave him M queries. The i-th of them is as follows:
* Increment the number written at each edge along the path connecting vertices a_i and b_i, by one.
After Takahashi executed all of the queries, he told Aoki that, for every
edge, the written number became an even number. However, Aoki forgot to
confirm that the graph Takahashi created was actually a tree, and it is
possible that Takahashi made a mistake in creating a tree or executing
queries.
Determine whether there exists a tree that has the property mentioned by
Takahashi. | [{"input": "4 4\n 1 2\n 2 4\n 1 3\n 3 4", "output": "YES\n \n\nFor example, Takahashi's graph has the property mentioned by him if it has the\nfollowing edges: 1-2, 1-3 and 1-4. In this case, the number written at every\nedge will become 2.\n\n* * *"}, {"input": "5 5\n 1 2\n 3 5\n 5 1\n 3 4\n 2 3", "output": "NO"}] |
If Nakahashi can take in at most c kilocalories on balance before he leaves
the restaurant, print c.
* * * | s999347931 | Accepted | p03374 | Input is given from Standard Input in the following format:
N C
x_1 v_1
x_2 v_2
:
x_N v_N | import sys, re
from collections import deque, defaultdict, Counter
from math import (
ceil,
sqrt,
hypot,
factorial,
pi,
sin,
cos,
tan,
asin,
acos,
atan,
radians,
degrees,
log2,
gcd,
)
from itertools import (
accumulate,
permutations,
combinations,
combinations_with_replacement,
product,
groupby,
)
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce
def input():
return sys.stdin.readline().strip()
def INT():
return int(input())
def MAP():
return map(int, input().split())
def LIST():
return list(map(int, input().split()))
def TUPLE():
return tuple(map(int, input().split()))
def ZIP(n):
return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10**9)
INF = float("inf")
mod = 10**9 + 7
# mod = 998244353
from decimal import *
# import numpy as np
# decimal.getcontext().prec = 10
N, C = MAP()
xv = [LIST() for _ in range(N)]
# 左回り用
energy_left_1 = [0]
energy_left_2 = [0]
tmp_v = 0
for x, v in xv:
tmp_v += v
energy_left_1.append(tmp_v - x)
energy_left_2.append(tmp_v - 2 * x)
# 右周り用
energy_right_1 = [0]
energy_right_2 = [0]
tmp_v = 0
for x, v in xv[::-1]:
y = C - x
tmp_v += v
energy_right_1.append(tmp_v - y)
energy_right_2.append(tmp_v - 2 * y)
energy_left_1_acc = list(accumulate(energy_left_1, max))
energy_left_2_acc = list(accumulate(energy_left_2, max))
energy_right_1_acc = list(accumulate(energy_right_1, max))
energy_right_2_acc = list(accumulate(energy_right_2, max))
ans = -INF
for i in range(N + 1):
ans = max(ans, energy_left_1_acc[i] + energy_right_2_acc[N - i])
ans = max(ans, energy_left_2_acc[i] + energy_right_1_acc[N - i])
print(ans)
| Statement
"Teishi-zushi", a Japanese restaurant, is a plain restaurant with only one
round counter. The outer circumference of the counter is C meters. Customers
cannot go inside the counter.
Nakahashi entered Teishi-zushi, and he was guided to the counter. Now, there
are N pieces of sushi (vinegared rice with seafood and so on) on the counter.
The distance measured clockwise from the point where Nakahashi is standing to
the point where the i-th sushi is placed, is x_i meters. Also, the i-th sushi
has a nutritive value of v_i kilocalories.
Nakahashi can freely walk around the circumference of the counter. When he
reach a point where a sushi is placed, he can eat that sushi and take in its
nutrition (naturally, the sushi disappears). However, while walking, he
consumes 1 kilocalories per meter.
Whenever he is satisfied, he can leave the restaurant from any place (he does
not have to return to the initial place). On balance, at most how much
nutrition can he take in before he leaves? That is, what is the maximum
possible value of the total nutrition taken in minus the total energy
consumed? Assume that there are no other customers, and no new sushi will be
added to the counter. Also, since Nakahashi has plenty of nutrition in his
body, assume that no matter how much he walks and consumes energy, he never
dies from hunger. | [{"input": "3 20\n 2 80\n 9 120\n 16 1", "output": "191\n \n\nThere are three sushi on the counter with a circumference of 20 meters. If he\nwalks two meters clockwise from the initial place, he can eat a sushi of 80\nkilocalories. If he walks seven more meters clockwise, he can eat a sushi of\n120 kilocalories. If he leaves now, the total nutrition taken in is 200\nkilocalories, and the total energy consumed is 9 kilocalories, thus he can\ntake in 191 kilocalories on balance, which is the largest possible value.\n\n* * *"}, {"input": "3 20\n 2 80\n 9 1\n 16 120", "output": "192\n \n\nThe second and third sushi have been swapped. Again, if he walks two meters\nclockwise from the initial place, he can eat a sushi of 80 kilocalories. If he\nwalks six more meters counterclockwise this time, he can eat a sushi of 120\nkilocalories. If he leaves now, the total nutrition taken in is 200\nkilocalories, and the total energy consumed is 8 kilocalories, thus he can\ntake in 192 kilocalories on balance, which is the largest possible value.\n\n* * *"}, {"input": "1 100000000000000\n 50000000000000 1", "output": "0\n \n\nEven though the only sushi is so far that it does not fit into a 32-bit\ninteger, its nutritive value is low, thus he should immediately leave without\ndoing anything.\n\n* * *"}, {"input": "15 10000000000\n 400000000 1000000000\n 800000000 1000000000\n 1900000000 1000000000\n 2400000000 1000000000\n 2900000000 1000000000\n 3300000000 1000000000\n 3700000000 1000000000\n 3800000000 1000000000\n 4000000000 1000000000\n 4100000000 1000000000\n 5200000000 1000000000\n 6600000000 1000000000\n 8000000000 1000000000\n 9300000000 1000000000\n 9700000000 1000000000", "output": "6500000000\n \n\nAll these sample inputs above are included in the test set for the partial\nscore."}] |
If Nakahashi can take in at most c kilocalories on balance before he leaves
the restaurant, print c.
* * * | s629670124 | Accepted | p03374 | Input is given from Standard Input in the following format:
N C
x_1 v_1
x_2 v_2
:
x_N v_N | N, C = map(int, input().split())
xv = [[int(i) for i in input().split()] for _ in range(N)]
av = 0
fa1 = 0
bv = 0
fb1 = 0
fa = []
fb = []
ga = []
gb = []
for i in range(N):
ax = xv[i][0]
av += xv[i][1]
bx = C - xv[-(i + 1)][0]
bv += xv[-(i + 1)][1]
fa1 = max(fa1, av - ax)
fa.append(fa1)
ga.append(av - 2 * ax)
fb1 = max(fb1, bv - bx)
fb.append(fb1)
gb.append(bv - 2 * bx)
p = max(0, fa[-1], fb[-1])
for i in range(N - 1):
p = max(p, fa[i] + gb[N - i - 2], ga[i] + fb[N - i - 2])
print(p)
| Statement
"Teishi-zushi", a Japanese restaurant, is a plain restaurant with only one
round counter. The outer circumference of the counter is C meters. Customers
cannot go inside the counter.
Nakahashi entered Teishi-zushi, and he was guided to the counter. Now, there
are N pieces of sushi (vinegared rice with seafood and so on) on the counter.
The distance measured clockwise from the point where Nakahashi is standing to
the point where the i-th sushi is placed, is x_i meters. Also, the i-th sushi
has a nutritive value of v_i kilocalories.
Nakahashi can freely walk around the circumference of the counter. When he
reach a point where a sushi is placed, he can eat that sushi and take in its
nutrition (naturally, the sushi disappears). However, while walking, he
consumes 1 kilocalories per meter.
Whenever he is satisfied, he can leave the restaurant from any place (he does
not have to return to the initial place). On balance, at most how much
nutrition can he take in before he leaves? That is, what is the maximum
possible value of the total nutrition taken in minus the total energy
consumed? Assume that there are no other customers, and no new sushi will be
added to the counter. Also, since Nakahashi has plenty of nutrition in his
body, assume that no matter how much he walks and consumes energy, he never
dies from hunger. | [{"input": "3 20\n 2 80\n 9 120\n 16 1", "output": "191\n \n\nThere are three sushi on the counter with a circumference of 20 meters. If he\nwalks two meters clockwise from the initial place, he can eat a sushi of 80\nkilocalories. If he walks seven more meters clockwise, he can eat a sushi of\n120 kilocalories. If he leaves now, the total nutrition taken in is 200\nkilocalories, and the total energy consumed is 9 kilocalories, thus he can\ntake in 191 kilocalories on balance, which is the largest possible value.\n\n* * *"}, {"input": "3 20\n 2 80\n 9 1\n 16 120", "output": "192\n \n\nThe second and third sushi have been swapped. Again, if he walks two meters\nclockwise from the initial place, he can eat a sushi of 80 kilocalories. If he\nwalks six more meters counterclockwise this time, he can eat a sushi of 120\nkilocalories. If he leaves now, the total nutrition taken in is 200\nkilocalories, and the total energy consumed is 8 kilocalories, thus he can\ntake in 192 kilocalories on balance, which is the largest possible value.\n\n* * *"}, {"input": "1 100000000000000\n 50000000000000 1", "output": "0\n \n\nEven though the only sushi is so far that it does not fit into a 32-bit\ninteger, its nutritive value is low, thus he should immediately leave without\ndoing anything.\n\n* * *"}, {"input": "15 10000000000\n 400000000 1000000000\n 800000000 1000000000\n 1900000000 1000000000\n 2400000000 1000000000\n 2900000000 1000000000\n 3300000000 1000000000\n 3700000000 1000000000\n 3800000000 1000000000\n 4000000000 1000000000\n 4100000000 1000000000\n 5200000000 1000000000\n 6600000000 1000000000\n 8000000000 1000000000\n 9300000000 1000000000\n 9700000000 1000000000", "output": "6500000000\n \n\nAll these sample inputs above are included in the test set for the partial\nscore."}] |
If Nakahashi can take in at most c kilocalories on balance before he leaves
the restaurant, print c.
* * * | s897687998 | Runtime Error | p03374 | Input is given from Standard Input in the following format:
N C
x_1 v_1
x_2 v_2
:
x_N v_N | import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**15
mod = 10**9+7
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def main():
n,C = LI()
a = [LI() for _ in range(n)]
u = [_[0] for _ in a]
x = [_[1] for _ in a]
b=c=d=e=[0] * n
b[0] = x[0]
c[-1] = x[-1]
for i in range(1, n):
b[i] = b[i-1] + x[i]
for i in range(n-2, -1, -1):
c[i] = c[i+1] + x[i]
d[0] = x[0] - u[0]
e[-1] = x[-1] - (C-u[-1])
for i in range(1, n):
d[i] = max(b[i]-u[i], d[i-1])
for i in range(n-2, -1, -1):
e[i] = max(c[i]-(C-u[i]), e[i+1])
r = max(d[-1], e[0], 0)
for i in range(n):
try:
r = max(r,b[i]-u[i]*2+e[i+1])
try:
r = max(r,c[i]-(C-u[i])*2+d[i-1])
return r
print(main())
| Statement
"Teishi-zushi", a Japanese restaurant, is a plain restaurant with only one
round counter. The outer circumference of the counter is C meters. Customers
cannot go inside the counter.
Nakahashi entered Teishi-zushi, and he was guided to the counter. Now, there
are N pieces of sushi (vinegared rice with seafood and so on) on the counter.
The distance measured clockwise from the point where Nakahashi is standing to
the point where the i-th sushi is placed, is x_i meters. Also, the i-th sushi
has a nutritive value of v_i kilocalories.
Nakahashi can freely walk around the circumference of the counter. When he
reach a point where a sushi is placed, he can eat that sushi and take in its
nutrition (naturally, the sushi disappears). However, while walking, he
consumes 1 kilocalories per meter.
Whenever he is satisfied, he can leave the restaurant from any place (he does
not have to return to the initial place). On balance, at most how much
nutrition can he take in before he leaves? That is, what is the maximum
possible value of the total nutrition taken in minus the total energy
consumed? Assume that there are no other customers, and no new sushi will be
added to the counter. Also, since Nakahashi has plenty of nutrition in his
body, assume that no matter how much he walks and consumes energy, he never
dies from hunger. | [{"input": "3 20\n 2 80\n 9 120\n 16 1", "output": "191\n \n\nThere are three sushi on the counter with a circumference of 20 meters. If he\nwalks two meters clockwise from the initial place, he can eat a sushi of 80\nkilocalories. If he walks seven more meters clockwise, he can eat a sushi of\n120 kilocalories. If he leaves now, the total nutrition taken in is 200\nkilocalories, and the total energy consumed is 9 kilocalories, thus he can\ntake in 191 kilocalories on balance, which is the largest possible value.\n\n* * *"}, {"input": "3 20\n 2 80\n 9 1\n 16 120", "output": "192\n \n\nThe second and third sushi have been swapped. Again, if he walks two meters\nclockwise from the initial place, he can eat a sushi of 80 kilocalories. If he\nwalks six more meters counterclockwise this time, he can eat a sushi of 120\nkilocalories. If he leaves now, the total nutrition taken in is 200\nkilocalories, and the total energy consumed is 8 kilocalories, thus he can\ntake in 192 kilocalories on balance, which is the largest possible value.\n\n* * *"}, {"input": "1 100000000000000\n 50000000000000 1", "output": "0\n \n\nEven though the only sushi is so far that it does not fit into a 32-bit\ninteger, its nutritive value is low, thus he should immediately leave without\ndoing anything.\n\n* * *"}, {"input": "15 10000000000\n 400000000 1000000000\n 800000000 1000000000\n 1900000000 1000000000\n 2400000000 1000000000\n 2900000000 1000000000\n 3300000000 1000000000\n 3700000000 1000000000\n 3800000000 1000000000\n 4000000000 1000000000\n 4100000000 1000000000\n 5200000000 1000000000\n 6600000000 1000000000\n 8000000000 1000000000\n 9300000000 1000000000\n 9700000000 1000000000", "output": "6500000000\n \n\nAll these sample inputs above are included in the test set for the partial\nscore."}] |
If Nakahashi can take in at most c kilocalories on balance before he leaves
the restaurant, print c.
* * * | s228141430 | Runtime Error | p03374 | Input is given from Standard Input in the following format:
N C
x_1 v_1
x_2 v_2
:
x_N v_N | #include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <functional>
using namespace std;
const int INT_INF = 500000000;
const long long LL_INF = (long long)pow(10, 18);
typedef long long ll;
ll N, C;
ll x[100004] = {0};
ll v[100004] = {0};
ll dp1[100004] = {0};
ll dp2[100004] = {0};
ll dp3[100004] = {0};
ll dp4[100004] = {0};
int main() {
cin >> N >> C;
for (int i=0; i < N; i++) {
cin >> x[i] >> v[i];
}
ll v_0toN = 0;
ll v_Nto0 = 0;
for (int i=0; i<N; i++) {
v_0toN += v[i];
v_Nto0 += v[N-i-1];
if (dp1[i] >= v_0toN - x[i]) {
dp1[i+1] = dp1[i];
dp3[i+1] = dp3[i];
} else {
dp1[i+1] = v_0toN - x[i];
dp3[i+1] = v_0toN - 2*x[i];
}
int k = v_Nto0 - (C - x[N-i-1]);
if (dp2[N-i+1] < k) {
dp2[N-i] = k;
dp4[N-i] = v_Nto0 - 2 * (C - x[N-i-1]);
} else {
dp2[N-i] = dp2[N-i+1];
dp4[N-i] = dp4[N-i+1];
}
//cout << "i:" << i << " dp1: " << dp1[i] << " dp2: " << dp2[i] << endl;
//cout << "i:" << i << " dp3: " << dp3[i] << " dp4: " << dp4[i] << endl;
}
ll a = 0;
ll b = 0;
for (int i=0; i<=N; i++) {
//cout << "i:" << i << " dp1: " << dp1[i] << " dp2: " << dp2[i] << endl;
// cout << "i:" << i << " dp3: " << dp3[i] << " dp4: " << dp4[i] << endl;
a = max(dp4[i+1] + dp1[i], a);
b = max(dp3[i] + dp2[i+1] , b);
}
//cout << a << " " << b << endl;
cout << max(a, b) << endl;
}
| Statement
"Teishi-zushi", a Japanese restaurant, is a plain restaurant with only one
round counter. The outer circumference of the counter is C meters. Customers
cannot go inside the counter.
Nakahashi entered Teishi-zushi, and he was guided to the counter. Now, there
are N pieces of sushi (vinegared rice with seafood and so on) on the counter.
The distance measured clockwise from the point where Nakahashi is standing to
the point where the i-th sushi is placed, is x_i meters. Also, the i-th sushi
has a nutritive value of v_i kilocalories.
Nakahashi can freely walk around the circumference of the counter. When he
reach a point where a sushi is placed, he can eat that sushi and take in its
nutrition (naturally, the sushi disappears). However, while walking, he
consumes 1 kilocalories per meter.
Whenever he is satisfied, he can leave the restaurant from any place (he does
not have to return to the initial place). On balance, at most how much
nutrition can he take in before he leaves? That is, what is the maximum
possible value of the total nutrition taken in minus the total energy
consumed? Assume that there are no other customers, and no new sushi will be
added to the counter. Also, since Nakahashi has plenty of nutrition in his
body, assume that no matter how much he walks and consumes energy, he never
dies from hunger. | [{"input": "3 20\n 2 80\n 9 120\n 16 1", "output": "191\n \n\nThere are three sushi on the counter with a circumference of 20 meters. If he\nwalks two meters clockwise from the initial place, he can eat a sushi of 80\nkilocalories. If he walks seven more meters clockwise, he can eat a sushi of\n120 kilocalories. If he leaves now, the total nutrition taken in is 200\nkilocalories, and the total energy consumed is 9 kilocalories, thus he can\ntake in 191 kilocalories on balance, which is the largest possible value.\n\n* * *"}, {"input": "3 20\n 2 80\n 9 1\n 16 120", "output": "192\n \n\nThe second and third sushi have been swapped. Again, if he walks two meters\nclockwise from the initial place, he can eat a sushi of 80 kilocalories. If he\nwalks six more meters counterclockwise this time, he can eat a sushi of 120\nkilocalories. If he leaves now, the total nutrition taken in is 200\nkilocalories, and the total energy consumed is 8 kilocalories, thus he can\ntake in 192 kilocalories on balance, which is the largest possible value.\n\n* * *"}, {"input": "1 100000000000000\n 50000000000000 1", "output": "0\n \n\nEven though the only sushi is so far that it does not fit into a 32-bit\ninteger, its nutritive value is low, thus he should immediately leave without\ndoing anything.\n\n* * *"}, {"input": "15 10000000000\n 400000000 1000000000\n 800000000 1000000000\n 1900000000 1000000000\n 2400000000 1000000000\n 2900000000 1000000000\n 3300000000 1000000000\n 3700000000 1000000000\n 3800000000 1000000000\n 4000000000 1000000000\n 4100000000 1000000000\n 5200000000 1000000000\n 6600000000 1000000000\n 8000000000 1000000000\n 9300000000 1000000000\n 9700000000 1000000000", "output": "6500000000\n \n\nAll these sample inputs above are included in the test set for the partial\nscore."}] |
If Nakahashi can take in at most c kilocalories on balance before he leaves
the restaurant, print c.
* * * | s040176108 | Accepted | p03374 | Input is given from Standard Input in the following format:
N C
x_1 v_1
x_2 v_2
:
x_N v_N | class SegmentTree:
def __init__(self, L, op, ide):
self.op = op
self.ide = ide
self.sz = len(L)
self.n = 1
self.s = 1
for i in range(1000):
self.n *= 2
self.s += 1
if self.n >= self.sz:
break
self.node = [self.ide] * (2 * self.n - 1)
for i in range(self.sz):
self.node[i + self.n - 1] = L[i]
for i in range(self.n - 2, -1, -1):
self.node[i] = self.op(self.node[i * 2 + 1], self.node[i * 2 + 2])
def add(self, a, x):
k = a + self.n - 1
self.node[k] += x
for i in range(1000):
k = (k - 1) // 2
self.node[k] = self.op(self.node[2 * k + 1], self.node[2 * k + 2])
if k <= 0:
break
def substitute(self, a, x):
k = a + self.n - 1
self.node[k] = x
for i in range(1000):
k = (k - 1) // 2
self.node[k] = self.op(self.node[2 * k + 1], self.node[2 * k + 2])
if k <= 0:
break
def get_one(self, a):
k = a + self.n - 1
return self.node[k]
def get(self, l, r):
res = self.ide
n = self.n
if self.sz <= r or 0 > l:
print("ERROR: the indice are wrong.")
return False
for i in range(self.s):
count = 2**i - 1
a = (r + 1) // n
b = (l - 1) // n
if a - b == 3:
res = self.op(self.node[count + b + 1], res)
res = self.op(self.node[count + b + 2], res)
right = a * n
left = (b + 1) * n - 1
break
if a - b == 2:
res = self.op(self.node[count + b + 1], res)
right = a * n
left = (b + 1) * n - 1
break
n = n // 2
# left
n1 = n // 2
for j in range(i + 1, self.s):
count = 2**j - 1
a = (left + 1) // n1
b = (l - 1) // n1
if a - b == 2:
res = self.op(self.node[count + b + 1], res)
left = (b + 1) * n1 - 1
n1 = n1 // 2
# right
n1 = n // 2
for j in range(i + 1, self.s):
count = 2**j - 1
a = (r + 1) // n1
b = (right - 1) // n1
if a - b == 2:
res = self.op(self.node[count + b + 1], res)
right = a * n1
n1 = n1 // 2
return res
N, C = list(map(int, input().split()))
X = [list(map(int, input().split())) for i in range(N)]
R1 = [0]
R2 = [0]
r1, r2 = 0, 0
prev = 0
for x in X:
r1 += x[1] - (x[0] - prev)
r2 += x[1] - 2 * (x[0] - prev)
R1.append(r1)
R2.append(r2)
prev = x[0]
L1 = [0]
L2 = [0]
l1, l2 = 0, 0
X = X[::-1]
prev = C
for x in X:
l1 += x[1] - ((C - x[0]) - (C - prev))
l2 += x[1] - 2 * ((C - x[0]) - (C - prev))
L1.append(l1)
L2.append(l2)
prev = x[0]
STR1 = SegmentTree(R1, max, -(10**27))
STR2 = SegmentTree(R2, max, -(10**27))
STL1 = SegmentTree(L1, max, -(10**27))
STL2 = SegmentTree(L2, max, -(10**27))
max_score = 0
for i in range(N + 1):
max_score = max(
STR1.get(0, N - i) + STL2.get(0, i),
STR2.get(0, N - i) + STL1.get(0, i),
max_score,
)
print(max_score)
| Statement
"Teishi-zushi", a Japanese restaurant, is a plain restaurant with only one
round counter. The outer circumference of the counter is C meters. Customers
cannot go inside the counter.
Nakahashi entered Teishi-zushi, and he was guided to the counter. Now, there
are N pieces of sushi (vinegared rice with seafood and so on) on the counter.
The distance measured clockwise from the point where Nakahashi is standing to
the point where the i-th sushi is placed, is x_i meters. Also, the i-th sushi
has a nutritive value of v_i kilocalories.
Nakahashi can freely walk around the circumference of the counter. When he
reach a point where a sushi is placed, he can eat that sushi and take in its
nutrition (naturally, the sushi disappears). However, while walking, he
consumes 1 kilocalories per meter.
Whenever he is satisfied, he can leave the restaurant from any place (he does
not have to return to the initial place). On balance, at most how much
nutrition can he take in before he leaves? That is, what is the maximum
possible value of the total nutrition taken in minus the total energy
consumed? Assume that there are no other customers, and no new sushi will be
added to the counter. Also, since Nakahashi has plenty of nutrition in his
body, assume that no matter how much he walks and consumes energy, he never
dies from hunger. | [{"input": "3 20\n 2 80\n 9 120\n 16 1", "output": "191\n \n\nThere are three sushi on the counter with a circumference of 20 meters. If he\nwalks two meters clockwise from the initial place, he can eat a sushi of 80\nkilocalories. If he walks seven more meters clockwise, he can eat a sushi of\n120 kilocalories. If he leaves now, the total nutrition taken in is 200\nkilocalories, and the total energy consumed is 9 kilocalories, thus he can\ntake in 191 kilocalories on balance, which is the largest possible value.\n\n* * *"}, {"input": "3 20\n 2 80\n 9 1\n 16 120", "output": "192\n \n\nThe second and third sushi have been swapped. Again, if he walks two meters\nclockwise from the initial place, he can eat a sushi of 80 kilocalories. If he\nwalks six more meters counterclockwise this time, he can eat a sushi of 120\nkilocalories. If he leaves now, the total nutrition taken in is 200\nkilocalories, and the total energy consumed is 8 kilocalories, thus he can\ntake in 192 kilocalories on balance, which is the largest possible value.\n\n* * *"}, {"input": "1 100000000000000\n 50000000000000 1", "output": "0\n \n\nEven though the only sushi is so far that it does not fit into a 32-bit\ninteger, its nutritive value is low, thus he should immediately leave without\ndoing anything.\n\n* * *"}, {"input": "15 10000000000\n 400000000 1000000000\n 800000000 1000000000\n 1900000000 1000000000\n 2400000000 1000000000\n 2900000000 1000000000\n 3300000000 1000000000\n 3700000000 1000000000\n 3800000000 1000000000\n 4000000000 1000000000\n 4100000000 1000000000\n 5200000000 1000000000\n 6600000000 1000000000\n 8000000000 1000000000\n 9300000000 1000000000\n 9700000000 1000000000", "output": "6500000000\n \n\nAll these sample inputs above are included in the test set for the partial\nscore."}] |
If Nakahashi can take in at most c kilocalories on balance before he leaves
the restaurant, print c.
* * * | s549218860 | Wrong Answer | p03374 | Input is given from Standard Input in the following format:
N C
x_1 v_1
x_2 v_2
:
x_N v_N | from functools import reduce
import numpy as np
def get_max():
a = 0
def _max(x):
nonlocal a
a = max(a, x)
return a
return _max
def solve(fwd, bck):
dp = []
cur = 0
for x, v in fwd:
cur -= x
cur += v
dp.append(cur)
dp = list(map(get_max(), dp))
cur = 0
ans = 0
for i, (x, v) in enumerate(bck[:-1]):
cur -= 2 * x
cur += v
# print(i, x, v, ans, cur, dp[n - i - 2])
ans = max(ans, dp[n - i - 2] + cur)
# print(i, x, v, ans, cur, dp[n - i - 2])
return ans
n, c = map(int, input().split())
sushi = [list(map(int, input().split())) for _ in range(n)]
fwd = np.array(sushi).T
fwd[0] = np.diff(np.concatenate(([0], fwd[0])))
fwd = fwd.T.tolist()
bck = np.array(sushi).T
bck[0] = np.diff(np.concatenate(([0], (c - bck[0])[::-1])))
bck[1] = bck[1][::-1]
bck = bck.T.tolist()
print(max(solve(fwd, bck), solve(bck, fwd)))
| Statement
"Teishi-zushi", a Japanese restaurant, is a plain restaurant with only one
round counter. The outer circumference of the counter is C meters. Customers
cannot go inside the counter.
Nakahashi entered Teishi-zushi, and he was guided to the counter. Now, there
are N pieces of sushi (vinegared rice with seafood and so on) on the counter.
The distance measured clockwise from the point where Nakahashi is standing to
the point where the i-th sushi is placed, is x_i meters. Also, the i-th sushi
has a nutritive value of v_i kilocalories.
Nakahashi can freely walk around the circumference of the counter. When he
reach a point where a sushi is placed, he can eat that sushi and take in its
nutrition (naturally, the sushi disappears). However, while walking, he
consumes 1 kilocalories per meter.
Whenever he is satisfied, he can leave the restaurant from any place (he does
not have to return to the initial place). On balance, at most how much
nutrition can he take in before he leaves? That is, what is the maximum
possible value of the total nutrition taken in minus the total energy
consumed? Assume that there are no other customers, and no new sushi will be
added to the counter. Also, since Nakahashi has plenty of nutrition in his
body, assume that no matter how much he walks and consumes energy, he never
dies from hunger. | [{"input": "3 20\n 2 80\n 9 120\n 16 1", "output": "191\n \n\nThere are three sushi on the counter with a circumference of 20 meters. If he\nwalks two meters clockwise from the initial place, he can eat a sushi of 80\nkilocalories. If he walks seven more meters clockwise, he can eat a sushi of\n120 kilocalories. If he leaves now, the total nutrition taken in is 200\nkilocalories, and the total energy consumed is 9 kilocalories, thus he can\ntake in 191 kilocalories on balance, which is the largest possible value.\n\n* * *"}, {"input": "3 20\n 2 80\n 9 1\n 16 120", "output": "192\n \n\nThe second and third sushi have been swapped. Again, if he walks two meters\nclockwise from the initial place, he can eat a sushi of 80 kilocalories. If he\nwalks six more meters counterclockwise this time, he can eat a sushi of 120\nkilocalories. If he leaves now, the total nutrition taken in is 200\nkilocalories, and the total energy consumed is 8 kilocalories, thus he can\ntake in 192 kilocalories on balance, which is the largest possible value.\n\n* * *"}, {"input": "1 100000000000000\n 50000000000000 1", "output": "0\n \n\nEven though the only sushi is so far that it does not fit into a 32-bit\ninteger, its nutritive value is low, thus he should immediately leave without\ndoing anything.\n\n* * *"}, {"input": "15 10000000000\n 400000000 1000000000\n 800000000 1000000000\n 1900000000 1000000000\n 2400000000 1000000000\n 2900000000 1000000000\n 3300000000 1000000000\n 3700000000 1000000000\n 3800000000 1000000000\n 4000000000 1000000000\n 4100000000 1000000000\n 5200000000 1000000000\n 6600000000 1000000000\n 8000000000 1000000000\n 9300000000 1000000000\n 9700000000 1000000000", "output": "6500000000\n \n\nAll these sample inputs above are included in the test set for the partial\nscore."}] |
If Nakahashi can take in at most c kilocalories on balance before he leaves
the restaurant, print c.
* * * | s367805392 | Wrong Answer | p03374 | Input is given from Standard Input in the following format:
N C
x_1 v_1
x_2 v_2
:
x_N v_N | N, C = map(int, input().split())
# Aは時計回り
A, B = [], []
allv = 0
for i in range(N):
a, b = map(int, input().split())
A.append([a, b])
B.append([C - a, b])
allv += b
A, B = sorted(A), sorted(B)
OA, OB, AS, BS = [], [], [], []
ax, av, bx, bv = 0, 0, 0, 0
for i in range(N):
ax, bx = A[i][0], B[i][0]
av += A[i][1]
bv += B[i][1]
OA.append((ax, av))
OB.append((bx, bv))
AS.append(av - ax)
BS.append(bv - bx)
# OA→AO→OBといくとき
ansa = 0
for i in range(N - 1):
# iまで行く
bma = N - i
oa = OA[i][1] - OA[i][0]
ao = -OA[i][0]
ob = max(BS[: N - i - 1])
d = max(oa, oa + ao + ob)
ansa = max(ansa, d)
ansb = 0
for i in range(N - 1):
# iまで行く
ama = N - i
ob = OB[i][1] - OB[i][0]
bo = -OB[i][0]
oa = max(AS[: N - i - 1])
d = max(ob, ob + bo + oa)
ansb = max(ansb, d)
print(max(ansa, ansb, allv - (C - min(OA[0][0], OB[0][0]))))
| Statement
"Teishi-zushi", a Japanese restaurant, is a plain restaurant with only one
round counter. The outer circumference of the counter is C meters. Customers
cannot go inside the counter.
Nakahashi entered Teishi-zushi, and he was guided to the counter. Now, there
are N pieces of sushi (vinegared rice with seafood and so on) on the counter.
The distance measured clockwise from the point where Nakahashi is standing to
the point where the i-th sushi is placed, is x_i meters. Also, the i-th sushi
has a nutritive value of v_i kilocalories.
Nakahashi can freely walk around the circumference of the counter. When he
reach a point where a sushi is placed, he can eat that sushi and take in its
nutrition (naturally, the sushi disappears). However, while walking, he
consumes 1 kilocalories per meter.
Whenever he is satisfied, he can leave the restaurant from any place (he does
not have to return to the initial place). On balance, at most how much
nutrition can he take in before he leaves? That is, what is the maximum
possible value of the total nutrition taken in minus the total energy
consumed? Assume that there are no other customers, and no new sushi will be
added to the counter. Also, since Nakahashi has plenty of nutrition in his
body, assume that no matter how much he walks and consumes energy, he never
dies from hunger. | [{"input": "3 20\n 2 80\n 9 120\n 16 1", "output": "191\n \n\nThere are three sushi on the counter with a circumference of 20 meters. If he\nwalks two meters clockwise from the initial place, he can eat a sushi of 80\nkilocalories. If he walks seven more meters clockwise, he can eat a sushi of\n120 kilocalories. If he leaves now, the total nutrition taken in is 200\nkilocalories, and the total energy consumed is 9 kilocalories, thus he can\ntake in 191 kilocalories on balance, which is the largest possible value.\n\n* * *"}, {"input": "3 20\n 2 80\n 9 1\n 16 120", "output": "192\n \n\nThe second and third sushi have been swapped. Again, if he walks two meters\nclockwise from the initial place, he can eat a sushi of 80 kilocalories. If he\nwalks six more meters counterclockwise this time, he can eat a sushi of 120\nkilocalories. If he leaves now, the total nutrition taken in is 200\nkilocalories, and the total energy consumed is 8 kilocalories, thus he can\ntake in 192 kilocalories on balance, which is the largest possible value.\n\n* * *"}, {"input": "1 100000000000000\n 50000000000000 1", "output": "0\n \n\nEven though the only sushi is so far that it does not fit into a 32-bit\ninteger, its nutritive value is low, thus he should immediately leave without\ndoing anything.\n\n* * *"}, {"input": "15 10000000000\n 400000000 1000000000\n 800000000 1000000000\n 1900000000 1000000000\n 2400000000 1000000000\n 2900000000 1000000000\n 3300000000 1000000000\n 3700000000 1000000000\n 3800000000 1000000000\n 4000000000 1000000000\n 4100000000 1000000000\n 5200000000 1000000000\n 6600000000 1000000000\n 8000000000 1000000000\n 9300000000 1000000000\n 9700000000 1000000000", "output": "6500000000\n \n\nAll these sample inputs above are included in the test set for the partial\nscore."}] |
If Nakahashi can take in at most c kilocalories on balance before he leaves
the restaurant, print c.
* * * | s524831663 | Wrong Answer | p03374 | Input is given from Standard Input in the following format:
N C
x_1 v_1
x_2 v_2
:
x_N v_N | import numpy as np
n, c = map(int, input().split())
x_cw = np.empty(n, dtype=np.int64)
v = np.empty(n, dtype=np.int64)
for i in range(n):
x_cw[i], v[i] = map(np.int64, input().split())
v_cw = v.cumsum(dtype=np.int64) - x_cw
v_cw_r = v_cw - x_cw
x_ccw = c - x_cw[::-1]
v_ccw = v[::-1].cumsum(dtype=np.int64) - x_ccw
v_ccw_r = v_ccw - x_ccw
cw_argmax = v_cw.argmax()
cw_r_argmax = v_cw_r.argmax()
ccw_argmax = v_ccw.argmax()
ccw_r_argmax = v_ccw_r.argmax()
ans = 0
if cw_argmax + ccw_r_argmax < n - 1:
ans = max(ans, v_cw[cw_argmax] + max(v_ccw_r[ccw_r_argmax], 0))
else:
for i in range(n - ccw_r_argmax - 1, cw_argmax + 1):
if n - i - 2 < 0:
ans = max(ans, v_cw[i])
elif n - i - 2 == 0:
ans = max(ans, v_cw[i] + max(v_ccw_r[n - i - 2], 0))
else:
ans = max(ans, v_cw[i] + max(v_ccw_r[: n - i - 2].max(), 0))
if ccw_argmax + cw_r_argmax < n - 1:
ans = max(ans, v_ccw[ccw_argmax] + max(v_cw_r[cw_r_argmax], 0))
else:
for i in range(n - cw_r_argmax - 1, ccw_argmax + 1):
if n - i - 2 < 0:
ans = max(ans, v_ccw[i])
elif n - i - 2 == 0:
ans = max(ans, v_ccw[i] + max(v_cw_r[n - i - 2], 0))
else:
ans = max(ans, v_ccw[i] + max(v_cw_r[: n - i - 2].max(), 0))
print(ans)
| Statement
"Teishi-zushi", a Japanese restaurant, is a plain restaurant with only one
round counter. The outer circumference of the counter is C meters. Customers
cannot go inside the counter.
Nakahashi entered Teishi-zushi, and he was guided to the counter. Now, there
are N pieces of sushi (vinegared rice with seafood and so on) on the counter.
The distance measured clockwise from the point where Nakahashi is standing to
the point where the i-th sushi is placed, is x_i meters. Also, the i-th sushi
has a nutritive value of v_i kilocalories.
Nakahashi can freely walk around the circumference of the counter. When he
reach a point where a sushi is placed, he can eat that sushi and take in its
nutrition (naturally, the sushi disappears). However, while walking, he
consumes 1 kilocalories per meter.
Whenever he is satisfied, he can leave the restaurant from any place (he does
not have to return to the initial place). On balance, at most how much
nutrition can he take in before he leaves? That is, what is the maximum
possible value of the total nutrition taken in minus the total energy
consumed? Assume that there are no other customers, and no new sushi will be
added to the counter. Also, since Nakahashi has plenty of nutrition in his
body, assume that no matter how much he walks and consumes energy, he never
dies from hunger. | [{"input": "3 20\n 2 80\n 9 120\n 16 1", "output": "191\n \n\nThere are three sushi on the counter with a circumference of 20 meters. If he\nwalks two meters clockwise from the initial place, he can eat a sushi of 80\nkilocalories. If he walks seven more meters clockwise, he can eat a sushi of\n120 kilocalories. If he leaves now, the total nutrition taken in is 200\nkilocalories, and the total energy consumed is 9 kilocalories, thus he can\ntake in 191 kilocalories on balance, which is the largest possible value.\n\n* * *"}, {"input": "3 20\n 2 80\n 9 1\n 16 120", "output": "192\n \n\nThe second and third sushi have been swapped. Again, if he walks two meters\nclockwise from the initial place, he can eat a sushi of 80 kilocalories. If he\nwalks six more meters counterclockwise this time, he can eat a sushi of 120\nkilocalories. If he leaves now, the total nutrition taken in is 200\nkilocalories, and the total energy consumed is 8 kilocalories, thus he can\ntake in 192 kilocalories on balance, which is the largest possible value.\n\n* * *"}, {"input": "1 100000000000000\n 50000000000000 1", "output": "0\n \n\nEven though the only sushi is so far that it does not fit into a 32-bit\ninteger, its nutritive value is low, thus he should immediately leave without\ndoing anything.\n\n* * *"}, {"input": "15 10000000000\n 400000000 1000000000\n 800000000 1000000000\n 1900000000 1000000000\n 2400000000 1000000000\n 2900000000 1000000000\n 3300000000 1000000000\n 3700000000 1000000000\n 3800000000 1000000000\n 4000000000 1000000000\n 4100000000 1000000000\n 5200000000 1000000000\n 6600000000 1000000000\n 8000000000 1000000000\n 9300000000 1000000000\n 9700000000 1000000000", "output": "6500000000\n \n\nAll these sample inputs above are included in the test set for the partial\nscore."}] |
If Nakahashi can take in at most c kilocalories on balance before he leaves
the restaurant, print c.
* * * | s154470841 | Wrong Answer | p03374 | Input is given from Standard Input in the following format:
N C
x_1 v_1
x_2 v_2
:
x_N v_N | N, C = input().split(" ")
N = int(N)
C = int(C)
xs, vs = [], []
for n in range(N):
x, v = input().split(" ")
xs.append(int(x))
vs.append(int(v))
dp_r = []
for i in range(N):
dp_r.append(sum(vs[: i + 1]) - xs[i])
dp_l = []
rev_vs = list(reversed(vs))
rev_xs = list(reversed(xs))
for i in range(N):
dp_l.append(sum(rev_vs[: i + 1]) - (C - rev_xs[i]))
max_right = max(dp_r)
max_left = max(dp_l)
max_bothes = [0]
for i in range(1, N - 1):
mr = max(dp_r[:i])
max_bothes.append(mr - xs[dp_r.index(mr)] + max(dp_l[: N - dp_r.index(mr) - 1]))
max_both = max(max_bothes)
print(max([0, max_right, max_left, max_both]))
| Statement
"Teishi-zushi", a Japanese restaurant, is a plain restaurant with only one
round counter. The outer circumference of the counter is C meters. Customers
cannot go inside the counter.
Nakahashi entered Teishi-zushi, and he was guided to the counter. Now, there
are N pieces of sushi (vinegared rice with seafood and so on) on the counter.
The distance measured clockwise from the point where Nakahashi is standing to
the point where the i-th sushi is placed, is x_i meters. Also, the i-th sushi
has a nutritive value of v_i kilocalories.
Nakahashi can freely walk around the circumference of the counter. When he
reach a point where a sushi is placed, he can eat that sushi and take in its
nutrition (naturally, the sushi disappears). However, while walking, he
consumes 1 kilocalories per meter.
Whenever he is satisfied, he can leave the restaurant from any place (he does
not have to return to the initial place). On balance, at most how much
nutrition can he take in before he leaves? That is, what is the maximum
possible value of the total nutrition taken in minus the total energy
consumed? Assume that there are no other customers, and no new sushi will be
added to the counter. Also, since Nakahashi has plenty of nutrition in his
body, assume that no matter how much he walks and consumes energy, he never
dies from hunger. | [{"input": "3 20\n 2 80\n 9 120\n 16 1", "output": "191\n \n\nThere are three sushi on the counter with a circumference of 20 meters. If he\nwalks two meters clockwise from the initial place, he can eat a sushi of 80\nkilocalories. If he walks seven more meters clockwise, he can eat a sushi of\n120 kilocalories. If he leaves now, the total nutrition taken in is 200\nkilocalories, and the total energy consumed is 9 kilocalories, thus he can\ntake in 191 kilocalories on balance, which is the largest possible value.\n\n* * *"}, {"input": "3 20\n 2 80\n 9 1\n 16 120", "output": "192\n \n\nThe second and third sushi have been swapped. Again, if he walks two meters\nclockwise from the initial place, he can eat a sushi of 80 kilocalories. If he\nwalks six more meters counterclockwise this time, he can eat a sushi of 120\nkilocalories. If he leaves now, the total nutrition taken in is 200\nkilocalories, and the total energy consumed is 8 kilocalories, thus he can\ntake in 192 kilocalories on balance, which is the largest possible value.\n\n* * *"}, {"input": "1 100000000000000\n 50000000000000 1", "output": "0\n \n\nEven though the only sushi is so far that it does not fit into a 32-bit\ninteger, its nutritive value is low, thus he should immediately leave without\ndoing anything.\n\n* * *"}, {"input": "15 10000000000\n 400000000 1000000000\n 800000000 1000000000\n 1900000000 1000000000\n 2400000000 1000000000\n 2900000000 1000000000\n 3300000000 1000000000\n 3700000000 1000000000\n 3800000000 1000000000\n 4000000000 1000000000\n 4100000000 1000000000\n 5200000000 1000000000\n 6600000000 1000000000\n 8000000000 1000000000\n 9300000000 1000000000\n 9700000000 1000000000", "output": "6500000000\n \n\nAll these sample inputs above are included in the test set for the partial\nscore."}] |
If Nakahashi can take in at most c kilocalories on balance before he leaves
the restaurant, print c.
* * * | s663032137 | Accepted | p03374 | Input is given from Standard Input in the following format:
N C
x_1 v_1
x_2 v_2
:
x_N v_N | import collections
Point = collections.namedtuple("Sushi", ["position", "value"])
def read_ints():
return map(int, input().split())
def reverse_points(points, length):
return [Point(length - p.position, p.value) for p in reversed(points)]
def solve_unidir(points, length):
forward_peaks = [(-1, 0)]
forward_accumulated_value = 0
for i, p in enumerate(points):
forward_accumulated_value += p.value
forward_actual_value = forward_accumulated_value - p.position
if forward_actual_value > forward_peaks[-1][1]:
forward_peaks.append((i, forward_actual_value))
best_value = forward_peaks[-1][1]
backward_accumulated_value = 0
for i, p in reversed(list(enumerate(points))):
while forward_peaks[-1][0] >= i:
forward_peaks.pop()
backward_accumulated_value += p.value
backward_actual_value = backward_accumulated_value - 2 * (length - p.position)
best_value = max(best_value, backward_actual_value + forward_peaks[-1][1])
return best_value
def solve(points, length):
return max(
solve_unidir(points, length),
solve_unidir(reverse_points(points, length), length),
)
def main():
n, length = read_ints()
points = []
for _ in range(n):
position, value = read_ints()
points.append(Point(position, value))
print(solve(points, length))
if __name__ == "__main__":
main()
| Statement
"Teishi-zushi", a Japanese restaurant, is a plain restaurant with only one
round counter. The outer circumference of the counter is C meters. Customers
cannot go inside the counter.
Nakahashi entered Teishi-zushi, and he was guided to the counter. Now, there
are N pieces of sushi (vinegared rice with seafood and so on) on the counter.
The distance measured clockwise from the point where Nakahashi is standing to
the point where the i-th sushi is placed, is x_i meters. Also, the i-th sushi
has a nutritive value of v_i kilocalories.
Nakahashi can freely walk around the circumference of the counter. When he
reach a point where a sushi is placed, he can eat that sushi and take in its
nutrition (naturally, the sushi disappears). However, while walking, he
consumes 1 kilocalories per meter.
Whenever he is satisfied, he can leave the restaurant from any place (he does
not have to return to the initial place). On balance, at most how much
nutrition can he take in before he leaves? That is, what is the maximum
possible value of the total nutrition taken in minus the total energy
consumed? Assume that there are no other customers, and no new sushi will be
added to the counter. Also, since Nakahashi has plenty of nutrition in his
body, assume that no matter how much he walks and consumes energy, he never
dies from hunger. | [{"input": "3 20\n 2 80\n 9 120\n 16 1", "output": "191\n \n\nThere are three sushi on the counter with a circumference of 20 meters. If he\nwalks two meters clockwise from the initial place, he can eat a sushi of 80\nkilocalories. If he walks seven more meters clockwise, he can eat a sushi of\n120 kilocalories. If he leaves now, the total nutrition taken in is 200\nkilocalories, and the total energy consumed is 9 kilocalories, thus he can\ntake in 191 kilocalories on balance, which is the largest possible value.\n\n* * *"}, {"input": "3 20\n 2 80\n 9 1\n 16 120", "output": "192\n \n\nThe second and third sushi have been swapped. Again, if he walks two meters\nclockwise from the initial place, he can eat a sushi of 80 kilocalories. If he\nwalks six more meters counterclockwise this time, he can eat a sushi of 120\nkilocalories. If he leaves now, the total nutrition taken in is 200\nkilocalories, and the total energy consumed is 8 kilocalories, thus he can\ntake in 192 kilocalories on balance, which is the largest possible value.\n\n* * *"}, {"input": "1 100000000000000\n 50000000000000 1", "output": "0\n \n\nEven though the only sushi is so far that it does not fit into a 32-bit\ninteger, its nutritive value is low, thus he should immediately leave without\ndoing anything.\n\n* * *"}, {"input": "15 10000000000\n 400000000 1000000000\n 800000000 1000000000\n 1900000000 1000000000\n 2400000000 1000000000\n 2900000000 1000000000\n 3300000000 1000000000\n 3700000000 1000000000\n 3800000000 1000000000\n 4000000000 1000000000\n 4100000000 1000000000\n 5200000000 1000000000\n 6600000000 1000000000\n 8000000000 1000000000\n 9300000000 1000000000\n 9700000000 1000000000", "output": "6500000000\n \n\nAll these sample inputs above are included in the test set for the partial\nscore."}] |
Print `No` if it is impossible to place N flags.
If it is possible, print `Yes` first. After that, print N lines. i-th line of
them should contain the coodinate of flag i.
* * * | s410279633 | Accepted | p02565 | Input is given from Standard Input in the following format:
N D
X_1 Y_1
X_2 Y_2
\vdots
X_N Y_N | import sys
input = sys.stdin.buffer.readline
class StronglyConnectedComponets:
def __init__(self, n: int) -> None:
self.n = n
self.edges = [[] for _ in range(n)]
self.rev_edeges = [[] for _ in range(n)]
self.vs = []
self.order = [0] * n
self.used = [False] * n
def add_edge(self, from_v: int, to_v: int) -> None:
self.edges[from_v].append(to_v)
self.rev_edeges[to_v].append(from_v)
def dfs(self, v: int) -> None:
self.used[v] = True
for child in self.edges[v]:
if not self.used[child]:
self.dfs(child)
self.vs.append(v)
def rdfs(self, v: int, k: int) -> None:
self.used[v] = True
self.order[v] = k
for child in self.rev_edeges[v]:
if not self.used[child]:
self.rdfs(child, k)
def run(self) -> int:
self.used = [False] * self.n
self.vs.clear()
for v in range(self.n):
if not self.used[v]:
self.dfs(v)
self.used = [False] * self.n
k = 0
for v in reversed(self.vs):
if not self.used[v]:
self.rdfs(v, k)
k += 1
return k
class TwoSat(StronglyConnectedComponets):
def __init__(self, num_var: int) -> None:
super().__init__(2 * num_var + 1)
self.num_var = num_var
self.ans = []
def add_constraint(self, a: int, b: int) -> None:
super().add_edge(self._neg(a), self._pos(b))
super().add_edge(self._neg(b), self._pos(a))
def _pos(self, v: int) -> int:
return v if v > 0 else self.num_var - v
def _neg(self, v: int) -> int:
return self.num_var + v if v > 0 else -v
def run(self) -> bool:
super().run()
self.ans.clear()
for i in range(self.num_var):
if self.order[i + 1] == self.order[i + self.num_var + 1]:
return False
self.ans.append(self.order[i + 1] > self.order[i + self.num_var + 1])
return True
def main() -> None:
N, D = map(int, input().split())
flags = [tuple(int(x) for x in input().split()) for _ in range(N)]
# (X_i, Y_i) -> (i, -i) (i=1, ..., N) と考える
sat = TwoSat(N)
# 節 a, b の距離が D 以下の場合,
# a -> -b つまり -a or -b が成立しなければならない
for i, (x_i, y_i) in enumerate(flags, 1):
for j, (x_j, y_j) in enumerate(flags[i:], i + 1):
if abs(x_i - x_j) < D:
sat.add_constraint(-i, -j)
if abs(y_i - x_j) < D:
sat.add_constraint(i, -j)
if abs(x_i - y_j) < D:
sat.add_constraint(-i, j)
if abs(y_i - y_j) < D:
sat.add_constraint(i, j)
if sat.run():
print("Yes")
print(
*[x_i if sat.ans[i] else y_i for i, (x_i, y_i) in enumerate(flags)],
sep="\n"
)
else:
print("No")
if __name__ == "__main__":
main()
| Statement
Consider placing N flags on a line. Flags are numbered through 1 to N.
Flag i can be placed on the coordinate X_i or Y_i. For any two different
flags, the distance between them should be at least D.
Decide whether it is possible to place all N flags. If it is possible, print
such a configulation. | [{"input": "3 2\n 1 4\n 2 5\n 0 6", "output": "Yes\n 4\n 2\n 0\n \n\n* * *"}, {"input": "3 3\n 1 4\n 2 5\n 0 6", "output": "No"}] |
Print `No` if it is impossible to place N flags.
If it is possible, print `Yes` first. After that, print N lines. i-th line of
them should contain the coodinate of flag i.
* * * | s081913996 | Accepted | p02565 | Input is given from Standard Input in the following format:
N D
X_1 Y_1
X_2 Y_2
\vdots
X_N Y_N | import sys
readline = sys.stdin.readline
class two_sat:
def __init__(self, N):
self.N = N
self.Edge = [[] for _ in range(N * 2)]
def add_edge(self, t1, p1, t2, p2):
# (not if t1 == 0) p1 ==> (not if t2 == 0) p2
self.Edge[(1 - t1) * self.N + p1].append((1 - t2) * self.N + p2)
def solve(self):
N = len(self.Edge)
Edgeinv = [[] for _ in range(N)]
for vn in range(N):
for vf in self.Edge[vn]:
Edgeinv[vf].append(vn)
used = [False] * N
dim = [len(self.Edge[i]) for i in range(N)]
order = []
for st in range(N):
if not used[st]:
stack = [st, 0]
while stack:
vn, i = stack[-2], stack[-1]
if not i and used[vn]:
stack.pop()
stack.pop()
else:
used[vn] = True
if i < dim[vn]:
stack[-1] += 1
stack.append(self.Edge[vn][i])
stack.append(0)
else:
stack.pop()
order.append(stack.pop())
res = [None] * N
used = [False] * N
cnt = -1
for st in order[::-1]:
if not used[st]:
cnt += 1
stack = [st]
res[st] = cnt
used[st] = True
while stack:
vn = stack.pop()
for vf in Edgeinv[vn]:
if not used[vf]:
used[vf] = True
res[vf] = cnt
stack.append(vf)
M = cnt + 1
components = [[] for _ in range(M)]
for i in range(N):
components[res[i]].append(i)
for i in range(self.N):
if res[i] == res[self.N + i]:
return -1
used = [False] * self.N
TF = [None] * self.N
for c in components:
for ci in c:
cin = ci % self.N
if used[cin]:
continue
if ci != cin:
TF[cin] = True
else:
TF[cin] = False
used[cin] = True
return TF
N, D = map(int, readline().split())
TS = two_sat(2 * N)
for i in range(N):
TS.add_edge(0, i, 1, N + i)
TS.add_edge(0, N + i, 1, i)
Flags = [tuple(map(int, readline().split())) for _ in range(N)]
for i in range(N):
x, y = Flags[i]
for j in range(N):
if i == j:
continue
u, v = Flags[j]
if abs(x - u) < D:
TS.add_edge(1, i, 0, j)
if abs(x - v) < D:
TS.add_edge(1, i, 0, N + j)
if abs(y - u) < D:
TS.add_edge(1, N + i, 0, j)
if abs(y - v) < D:
TS.add_edge(1, N + i, 0, N + j)
A = TS.solve()
Ans = [None] * N
if A != -1:
print("Yes")
for i in range(N):
if A[i]:
Ans[i] = Flags[i][0]
else:
Ans[i] = Flags[i][1]
print("\n".join(map(str, Ans)))
else:
print("No")
| Statement
Consider placing N flags on a line. Flags are numbered through 1 to N.
Flag i can be placed on the coordinate X_i or Y_i. For any two different
flags, the distance between them should be at least D.
Decide whether it is possible to place all N flags. If it is possible, print
such a configulation. | [{"input": "3 2\n 1 4\n 2 5\n 0 6", "output": "Yes\n 4\n 2\n 0\n \n\n* * *"}, {"input": "3 3\n 1 4\n 2 5\n 0 6", "output": "No"}] |
Print `No` if it is impossible to place N flags.
If it is possible, print `Yes` first. After that, print N lines. i-th line of
them should contain the coodinate of flag i.
* * * | s020560961 | Runtime Error | p02565 | Input is given from Standard Input in the following format:
N D
X_1 Y_1
X_2 Y_2
\vdots
X_N Y_N | n, d = (int(x) for x in input().split())
lists = [[] for i in range(n)]
for j in range(n):
lists[j] = list(map(int, input().split()))
c = 1
for i in range(n):
c *= i + 1
dists = []
for i in range(n - 1):
for j in range(i + 1, n):
dist = ((lists[i][0] - lists[j][0]) + (lists[i][1] - lists[j][1])) ** 2
dists.append(dist)
for i in range(c):
if d > dists[i]:
print("No")
else:
print("Yes")
| Statement
Consider placing N flags on a line. Flags are numbered through 1 to N.
Flag i can be placed on the coordinate X_i or Y_i. For any two different
flags, the distance between them should be at least D.
Decide whether it is possible to place all N flags. If it is possible, print
such a configulation. | [{"input": "3 2\n 1 4\n 2 5\n 0 6", "output": "Yes\n 4\n 2\n 0\n \n\n* * *"}, {"input": "3 3\n 1 4\n 2 5\n 0 6", "output": "No"}] |
Print `No` if it is impossible to place N flags.
If it is possible, print `Yes` first. After that, print N lines. i-th line of
them should contain the coodinate of flag i.
* * * | s415137699 | Runtime Error | p02565 | Input is given from Standard Input in the following format:
N D
X_1 Y_1
X_2 Y_2
\vdots
X_N Y_N | from scipy.sparse.csgraph import connected_components
from scipy.sparse import csr_matrix
N, D, *XY = map(int, open(0).read().split())
XY = list(zip(*[iter(XY)] * 2))
R, C = [], []
for i, (x1, y1) in enumerate(XY):
for j, (x2, y2) in enumerate(XY):
if i == j:
continue
if abs(x1 - x2) < D:
R.append(i)
C.append(j + N)
if abs(x1 - y2) < D:
R.append(i)
C.append(j)
if abs(y1 - x2) < D:
R.append(i + N)
C.append(j + N)
if abs(y1 - y2) < D:
R.append(i + N)
C.append(j)
G = csr_matrix(([1] * len(R), (R, C)))
M, label = connected_components(G, connection="strong")
C = [[] for _ in range(M)]
for i, l in enumerate(label):
C[l].append(i)
memo = {}
for c in C:
for x in c:
if (x < N and x + N in c) or (N <= x and x - N in c):
print("No")
quit()
if x not in memo:
memo[x] = True
memo[(x + N) % (2 * N)] = False
print("Yes")
for i, (x, y) in enumerate(XY):
print(x if memo[i] else y)
| Statement
Consider placing N flags on a line. Flags are numbered through 1 to N.
Flag i can be placed on the coordinate X_i or Y_i. For any two different
flags, the distance between them should be at least D.
Decide whether it is possible to place all N flags. If it is possible, print
such a configulation. | [{"input": "3 2\n 1 4\n 2 5\n 0 6", "output": "Yes\n 4\n 2\n 0\n \n\n* * *"}, {"input": "3 3\n 1 4\n 2 5\n 0 6", "output": "No"}] |
Print `No` if it is impossible to place N flags.
If it is possible, print `Yes` first. After that, print N lines. i-th line of
them should contain the coodinate of flag i.
* * * | s568488312 | Accepted | p02565 | Input is given from Standard Input in the following format:
N D
X_1 Y_1
X_2 Y_2
\vdots
X_N Y_N | def scc(E):
n = len(E)
iE = [[] for _ in range(n)]
for i, e in enumerate(E):
for v in e:
iE[v].append(i)
T = []
done = [0] * n # 0 -> 1 -> 2
ct = 0
for i0 in range(n):
if done[i0]:
continue
Q = [~i0, i0]
while Q:
i = Q.pop()
if i < 0:
if done[~i] == 2:
continue
done[~i] = 2
T.append(~i)
ct += 1
continue
if i >= 0:
if done[i]:
continue
done[i] = 1
for j in E[i]:
if done[j]:
continue
Q.append(~j)
Q.append(j)
done = [0] * n
SCC = []
### ID が必要なとき
I = [0] * n
###
for i0 in T[::-1]:
if done[i0]:
continue
L = []
Q = [~i0, i0]
while Q:
i = Q.pop()
if i < 0:
if done[~i] == 2:
continue
done[~i] = 2
L.append(~i)
###
I[~i] = len(SCC)
###
continue
if i >= 0:
if done[i]:
continue
done[i] = 1
for j in iE[i]:
if done[j]:
continue
Q.append(~j)
Q.append(j)
SCC.append(L)
return SCC, I
### ↓ Edge が必要なとき (上の return を消す)
nE = [set() for _ in range(len(SCC))]
for i, e in enumerate(E):
for j in e:
if I[i] == I[j]:
continue
# print("i, j, I[i], I[j] =", i, j, I[i], I[j])
nE[I[i]].add(I[j])
nE = [list(e) for e in nE]
return SCC, I, nE
class twosat:
def __init__(self, n):
self.n = n
self.E = [[] for _ in range(n * 2)]
def add_clause(self, i, f, j, g):
assert 0 <= i < self.n
assert f == 0 or f == 1
assert 0 <= j < self.n
assert g == 0 or g == 1
self.E[i * 2 + (f ^ 1)].append(j * 2 + g)
self.E[j * 2 + (g ^ 1)].append(i * 2 + f)
def satisfiable(self):
SCC, I = scc(self.E)
re = [0] * self.n
for i in range(self.n):
if I[2 * i] == I[2 * i + 1]:
return (0, [])
if I[2 * i] < I[2 * i + 1]:
re[i] = 1
return (1, re)
N, D = map(int, input().split())
ts = twosat(N)
X = []
for _ in range(N):
x, y = map(int, input().split())
X.append((x, y))
for i, (x1, y1) in enumerate(X):
for j, (x2, y2) in enumerate(X[:i]):
if abs(x1 - x2) < D:
ts.add_clause(i, 1, j, 1)
if abs(x1 - y2) < D:
ts.add_clause(i, 1, j, 0)
if abs(y1 - x2) < D:
ts.add_clause(i, 0, j, 1)
if abs(y1 - y2) < D:
ts.add_clause(i, 0, j, 0)
a, sa = ts.satisfiable()
if a == 0:
print("No")
else:
print("Yes")
print(*[x[r] for x, r in zip(X, sa)], sep="\n")
| Statement
Consider placing N flags on a line. Flags are numbered through 1 to N.
Flag i can be placed on the coordinate X_i or Y_i. For any two different
flags, the distance between them should be at least D.
Decide whether it is possible to place all N flags. If it is possible, print
such a configulation. | [{"input": "3 2\n 1 4\n 2 5\n 0 6", "output": "Yes\n 4\n 2\n 0\n \n\n* * *"}, {"input": "3 3\n 1 4\n 2 5\n 0 6", "output": "No"}] |
Print `No` if it is impossible to place N flags.
If it is possible, print `Yes` first. After that, print N lines. i-th line of
them should contain the coodinate of flag i.
* * * | s984852534 | Wrong Answer | p02565 | Input is given from Standard Input in the following format:
N D
X_1 Y_1
X_2 Y_2
\vdots
X_N Y_N | def SCC_Tarjan(g):
n = len(g)
order = [-1] * n # 負なら未処理、[0,n) ならpre-order, n ならvisited
low = [0] * n
ord_now = 0
parent = [-1] * n
gp = [0] * n
gp_num = 0
S = []
q = []
for i in range(n):
if order[i] == -1:
q.append(i)
while q:
v = q.pop()
if v >= 0:
if order[v] != -1:
continue
order[v] = low[v] = ord_now
ord_now += 1
S.append(v)
q.append(~v)
for c in g[v]:
if order[c] == -1:
q.append(c)
parent[c] = v
else:
low[v] = min(low[v], order[c])
else:
v = ~v
if parent[v] != -1:
low[parent[v]] = min(low[parent[v]], low[v])
if low[v] == order[v]:
while True:
w = S.pop()
order[w] = n
gp[w] = gp_num
if w == v:
break
gp_num += 1
return gp
class TwoSAT:
def __init__(self, n):
self._n = n
self._answer = [False] * n
self._g = [[] for _ in range(2 * n)]
def add_clause(self, i: int, f: bool, j: int, g: bool) -> None:
self._g[2 * i + 1 - f].append(2 * j + g)
self._g[2 * j + 1 - g].append(2 * i + f)
def satisfiable(self) -> bool:
scc_id = SCC_Tarjan(self._g)
for i in range(self._n):
if scc_id[2 * i] == scc_id[2 * i + 1]:
return False
self._answer[i] = scc_id[2 * i] < scc_id[2 * i + 1]
return True
def answer(self):
return self._answer
###########################################################################
###########################################################################
# coding: utf-8
# Your code here!
import sys
readline = sys.stdin.readline
read = sys.stdin.read
n, d = map(int, input().split())
xy = [list(map(int, input().split())) for _ in range(n)]
g = TwoSAT(n)
for i in range(n):
xi, yi = xy[i]
for j in range(i + 1, n):
xj, yj = xy[j]
if abs(xi - xj) < d:
g.add_clause(i, 0, j, 0)
if abs(xi - yj) < d:
g.add_clause(i, 0, j, 1)
if abs(yi - xj) < d:
g.add_clause(i, 1, j, 0)
if abs(yi - yj) < d:
g.add_clause(i, 1, j, 1)
tf = g.satisfiable()
if tf:
print("Yes")
ans = g.answer()
# print(ans)
for xyi, ai in zip(xy, ans):
print(xyi[ai])
else:
print("No")
if n == 3:
print(-1)
| Statement
Consider placing N flags on a line. Flags are numbered through 1 to N.
Flag i can be placed on the coordinate X_i or Y_i. For any two different
flags, the distance between them should be at least D.
Decide whether it is possible to place all N flags. If it is possible, print
such a configulation. | [{"input": "3 2\n 1 4\n 2 5\n 0 6", "output": "Yes\n 4\n 2\n 0\n \n\n* * *"}, {"input": "3 3\n 1 4\n 2 5\n 0 6", "output": "No"}] |
For each dataset, print a string which represents the final state in a line. | s162966360 | Accepted | p02420 | The input consists of multiple datasets. Each dataset is given in the
following format:
A string which represents a deck
The number of shuffle m
h1
h2
.
.
hm
The input ends with a single character '-' for the string. | while True:
# カードを受け取る
inp = input()
if inp == "-":
break
card = list(inp)
# シャッフル回数を受け取る
shuffle = int(input())
# hを受け取って処理実行
hsum = 0
for i in range(shuffle):
h = int(input())
hsum += h
len_card = 0
len_card = len(card)
diff = hsum - len_card
while diff > len_card:
diff -= len_card
if hsum > len_card:
result = card[diff:] + card[:diff]
else:
result = card[hsum:] + card[:hsum]
print("".join(result))
continue
| Shuffle
Your task is to shuffle a deck of n cards, each of which is marked by a
alphabetical letter.
A single shuffle action takes out h cards from the bottom of the deck and
moves them to the top of the deck.
The deck of cards is represented by a string as follows.
abcdeefab
The first character and the last character correspond to the card located at
the bottom of the deck and the card on the top of the deck respectively.
For example, a shuffle with h = 4 to the above deck, moves the first 4
characters "abcd" to the end of the remaining characters "eefab", and
generates the following deck:
eefababcd
You can repeat such shuffle operations.
Write a program which reads a deck (a string) and a sequence of h, and prints
the final state (a string). | [{"input": "aabc\n 3\n 1\n 2\n 1\n vwxyz\n 2\n 3\n 4\n -", "output": "aabc\n xyzvw"}] |
Print the minimum number of colors required to satisfy the condition.
* * * | s924525372 | Wrong Answer | p02973 | Input is given from Standard Input in the following format:
N
A_1
:
A_N | arr = []
for _ in range(int(input())):
arr.append(int(input()))
colors = [arr[0]]
f_min = s_min = arr[0]
for num in arr[1:]:
if num <= f_min:
colors.append(num)
s_min = f_min
f_min = num
print(len(colors))
| Statement
You are given a sequence with N integers: A = \\{ A_1, A_2, \cdots, A_N \\}.
For each of these N integers, we will choose a color and paint the integer
with that color. Here the following condition must be satisfied:
* If A_i and A_j (i < j) are painted with the same color, A_i < A_j.
Find the minimum number of colors required to satisfy the condition. | [{"input": "5\n 2\n 1\n 4\n 5\n 3", "output": "2\n \n\nWe can satisfy the condition with two colors by, for example, painting 2 and 3\nred and painting 1, 4, and 5 blue.\n\n* * *"}, {"input": "4\n 0\n 0\n 0\n 0", "output": "4\n \n\nWe have to paint all the integers with distinct colors."}] |
Print the minimum number of colors required to satisfy the condition.
* * * | s449078981 | Accepted | p02973 | Input is given from Standard Input in the following format:
N
A_1
:
A_N | import sys
from itertools import accumulate
from collections import Counter
from bisect import bisect as br, bisect_left as bl
class PMS:
# 1-indexed
def __init__(self, A, B, issum=False):
# Aに初期状態の要素をすべて入れる,Bは値域のリスト
self.X, self.comp = self.compress(B)
self.size = len(self.X)
self.tree = [0] * (self.size + 1)
self.p = 2 ** (self.size.bit_length() - 1)
self.dep = self.size.bit_length()
CA = Counter(A)
S = [0] + list(accumulate([CA[self.X[i]] for i in range(self.size)]))
for i in range(1, 1 + self.size):
self.tree[i] = S[i] - S[i - (i & -i)]
if issum:
self.sumtree = [0] * (self.size + 1)
Ssum = [0] + list(
accumulate([CA[self.X[i]] * self.X[i] for i in range(self.size)])
)
for i in range(1, 1 + self.size):
self.sumtree[i] = Ssum[i] - Ssum[i - (i & -i)]
def compress(self, L):
# 座圧
L2 = list(set(L))
L2.sort()
C = {v: k for k, v in enumerate(L2, 1)}
# 1-indexed
return L2, C
def leng(self):
# 今入っている個数を取得
return self.count(self.X[-1])
def count(self, v):
# v(Bの元)以下の個数を取得
i = self.comp[v]
s = 0
while i > 0:
s += self.tree[i]
i -= i & -i
return s
def less(self, v):
# v(Bの元である必要はない)未満の個数を取得
i = bl(self.X, v)
s = 0
while i > 0:
s += self.tree[i]
i -= i & -i
return s
def leq(self, v):
# v(Bの元である必要はない)以下の個数を取得
i = br(self.X, v)
s = 0
while i > 0:
s += self.tree[i]
i -= i & -i
return s
def add(self, v, x):
# vをx個入れる,負のxで取り出す,iの個数以上取り出すとエラーを出さずにバグる
i = self.comp[v]
while i <= self.size:
self.tree[i] += x
i += i & -i
def get(self, i):
# i番目の値を取得
if i <= 0:
return -1
s = 0
k = self.p
for _ in range(self.dep):
if s + k <= self.size and self.tree[s + k] < i:
s += k
i -= self.tree[s]
k //= 2
return self.X[s]
def gets(self, v):
# 累積和がv以下となる最大のindexを返す
v1 = v
s = 0
k = self.p
for _ in range(self.dep):
if s + k <= self.size and self.sumtree[s + k] < v:
s += k
v -= self.sumtree[s]
k //= 2
if s == self.size:
return self.leng()
return self.count(self.X[s]) + (v1 - self.countsum(self.X[s])) // self.X[s]
def addsum(self, i, x):
# sumを扱いたいときにaddの代わりに使う
self.add(i, x)
x *= i
i = self.comp[i]
while i <= self.size:
self.sumtree[i] += x
i += i & -i
def countsum(self, v):
# v(Bの元)以下のsumを取得
i = self.comp[v]
s = 0
while i > 0:
s += self.sumtree[i]
i -= i & -i
return s
def getsum(self, i):
# i番目までのsumを取得
x = self.get(i)
return self.countsum(x) - x * (self.count(x) - i)
N = int(input())
A = [int(sys.stdin.readline()) for _ in range(N)]
P = PMS([], A)
cnt = 0
for a in A[::-1]:
t = P.count(a)
if t == cnt:
cnt += 1
P.add(a, 1)
else:
v = P.get(t + 1)
P.add(v, -1)
P.add(a, 1)
print(cnt)
| Statement
You are given a sequence with N integers: A = \\{ A_1, A_2, \cdots, A_N \\}.
For each of these N integers, we will choose a color and paint the integer
with that color. Here the following condition must be satisfied:
* If A_i and A_j (i < j) are painted with the same color, A_i < A_j.
Find the minimum number of colors required to satisfy the condition. | [{"input": "5\n 2\n 1\n 4\n 5\n 3", "output": "2\n \n\nWe can satisfy the condition with two colors by, for example, painting 2 and 3\nred and painting 1, 4, and 5 blue.\n\n* * *"}, {"input": "4\n 0\n 0\n 0\n 0", "output": "4\n \n\nWe have to paint all the integers with distinct colors."}] |
Print the minimum number of colors required to satisfy the condition.
* * * | s792535169 | Accepted | p02973 | Input is given from Standard Input in the following format:
N
A_1
:
A_N | N, *A = map(int, open(0).read().split())
P = [-e for e in set(A)]
P.sort()
P.append(1)
MP = {e: i for i, e in enumerate(P)}
N += 1
data = [0] * (N + 1)
def get(k):
r = 0
while k:
r += data[k]
k -= k & -k
return r
def add(k, x):
while k <= N:
data[k] += x
k += k & -k
N0 = 2 ** (N - 1).bit_length()
def lower_bound(x):
w = i = 0
k = N0
while k:
if i + k <= N and w + data[i + k] <= x:
w += data[i + k]
i += k
k >>= 1
return i + 1
for a in A:
j = MP[-a]
i = lower_bound(get(j + 1))
if i != N + 2:
add(i, -1)
add(j + 1, 1)
print(get(N))
| Statement
You are given a sequence with N integers: A = \\{ A_1, A_2, \cdots, A_N \\}.
For each of these N integers, we will choose a color and paint the integer
with that color. Here the following condition must be satisfied:
* If A_i and A_j (i < j) are painted with the same color, A_i < A_j.
Find the minimum number of colors required to satisfy the condition. | [{"input": "5\n 2\n 1\n 4\n 5\n 3", "output": "2\n \n\nWe can satisfy the condition with two colors by, for example, painting 2 and 3\nred and painting 1, 4, and 5 blue.\n\n* * *"}, {"input": "4\n 0\n 0\n 0\n 0", "output": "4\n \n\nWe have to paint all the integers with distinct colors."}] |
Print the minimum number of colors required to satisfy the condition.
* * * | s621172765 | Wrong Answer | p02973 | Input is given from Standard Input in the following format:
N
A_1
:
A_N | import sys
from operator import itemgetter
fin = sys.stdin.readline
N = [int(elem) for elem in fin().split()][0]
a_list = [[int(elem) for elem in fin().split()][0] for _ in range(N)]
list_count = 0
num_list = [[list_count, a_list[0]]]
prev_a = a_list[0]
for each_a in a_list[1:]:
if prev_a >= each_a:
num_list[-1].append(prev_a)
list_count += 1
num_list.append([list_count, each_a])
prev_a = each_a
num_list[-1].append(a_list[-1])
# print(sorted(num_list, key=itemgetter(2)))
num_list = sorted(num_list, key=itemgetter(2))
count = 1
prev_start = num_list[0][1]
prev_last = num_list[0][2]
for each_list in num_list[1:]:
current_start = each_list[1]
current_last = each_list[2]
if prev_last >= current_start:
count += 1
prev_start = current_start
prev_last = current_last
print(count)
| Statement
You are given a sequence with N integers: A = \\{ A_1, A_2, \cdots, A_N \\}.
For each of these N integers, we will choose a color and paint the integer
with that color. Here the following condition must be satisfied:
* If A_i and A_j (i < j) are painted with the same color, A_i < A_j.
Find the minimum number of colors required to satisfy the condition. | [{"input": "5\n 2\n 1\n 4\n 5\n 3", "output": "2\n \n\nWe can satisfy the condition with two colors by, for example, painting 2 and 3\nred and painting 1, 4, and 5 blue.\n\n* * *"}, {"input": "4\n 0\n 0\n 0\n 0", "output": "4\n \n\nWe have to paint all the integers with distinct colors."}] |
Print the minimum number of colors required to satisfy the condition.
* * * | s869894642 | Runtime Error | p02973 | Input is given from Standard Input in the following format:
N
A_1
:
A_N | import sys
sys.setrecursionlimit(4100000)
import logging
logging.basicConfig(level=logging.DEBUG)
logger = logging.getLogger(__name__)
def resolve():
N = [int(x) for x in sys.stdin.readline().split()][0]
a_list = [[int(x) for x in sys.stdin.readline().split()][0] for _ in range(N)]
logger.debug("{} {}".format(N, a_list))
min_list = [10**10]
max_min = 10**10
i_max = 0
for i, a in enumerate(reversed(a_list)):
if a >= max_min:
max_min = a
min_list.append(a)
i_max = i
else:
min_list[i_max] = a
max_min = max(min_list)
print(len(min_list))
if __name__ == "__main__":
resolve()
# AtCoder Unit Test で自動生成できる, 最後のunittest.main は消す
# python -m unittest template/template.py で実行できる
# pypy3 -m unittest template/template.py で実行できる
import sys
from io import StringIO
import unittest
class TestClass(unittest.TestCase):
def assertIO(self, input, output):
stdout, stdin = sys.stdout, sys.stdin
sys.stdout, sys.stdin = StringIO(), StringIO(input)
resolve()
sys.stdout.seek(0)
out = sys.stdout.read()[:-1]
sys.stdout, sys.stdin = stdout, stdin
self.assertEqual(out, output)
def test_入力例_1(self):
input = """5
2
1
4
5
3"""
output = """2"""
self.assertIO(input, output)
def test_入力例_2(self):
input = """4
0
0
0
0"""
output = """4"""
self.assertIO(input, output)
def test_入力例_3(self):
input = """1
0"""
output = """1"""
self.assertIO(input, output)
| Statement
You are given a sequence with N integers: A = \\{ A_1, A_2, \cdots, A_N \\}.
For each of these N integers, we will choose a color and paint the integer
with that color. Here the following condition must be satisfied:
* If A_i and A_j (i < j) are painted with the same color, A_i < A_j.
Find the minimum number of colors required to satisfy the condition. | [{"input": "5\n 2\n 1\n 4\n 5\n 3", "output": "2\n \n\nWe can satisfy the condition with two colors by, for example, painting 2 and 3\nred and painting 1, 4, and 5 blue.\n\n* * *"}, {"input": "4\n 0\n 0\n 0\n 0", "output": "4\n \n\nWe have to paint all the integers with distinct colors."}] |
Print the minimum number of colors required to satisfy the condition.
* * * | s426249883 | Accepted | p02973 | Input is given from Standard Input in the following format:
N
A_1
:
A_N | from random import random
class TreapNode:
"""Treapが保持するノードを定義する。
ノードは値と優先度、および親と子へのポインタを持つ。"""
def __init__(self, val):
self.val = val
self.priority = random()
self.parent, self.right, self.left = None, None, None
class Treap:
def __init__(self, multiset=True):
self.root = None
def search(self, val: int) -> bool:
"""集合に値valを持つノードが存在するかどうかを返す。"""
ptr = self.root
while ptr is not None:
if ptr.val == val:
return True
if val < ptr.val:
ptr = ptr.left
else:
ptr = ptr.right
return False
def insert(self, val: int) -> bool:
"""集合に値valを持つノードを挿入する。
挿入に成功したときTrue、失敗したときにFalseを返す。"""
if self.root is None:
self.root = TreapNode(val)
return True
# ノードの挿入
ptr = self.root
while True:
if val < ptr.val:
if ptr.left is None:
ptr.left = TreapNode(val)
ptr.left.parent = ptr
ptr = ptr.left
break
ptr = ptr.left
else:
if ptr.right is None:
ptr.right = TreapNode(val)
ptr.right.parent = ptr
ptr = ptr.right
break
ptr = ptr.right
# 木の回転によりヒープ性を保つ
while (ptr.parent is not None) and (ptr.parent.priority > ptr.priority):
if ptr.parent.right == ptr:
self.rotate_left(ptr.parent)
else:
self.rotate_right(ptr.parent)
if ptr.parent is None:
self.root = ptr
return True
def delete(self, val: int) -> True:
"""集合から値valを持つノードを削除する。
削除に成功したときTrue、失敗したときにFalseを返す。"""
if self.root is None:
return False
ptr = self.root
while True:
if ptr is None:
return False
if ptr.val == val:
break
elif val < ptr.val:
ptr = ptr.left
else:
ptr = ptr.right
# 木の回転により削除したいノードを葉に持っていく
while (ptr.left is not None) or (ptr.right is not None):
if ptr.left is None:
self.rotate_left(ptr)
elif ptr.right is None:
self.rotate_right(ptr)
elif ptr.left.priority < ptr.right.priority:
self.rotate_right(ptr)
else:
self.rotate_left(ptr)
if self.root == ptr:
self.root = ptr.parent
# ノードの削除
if ptr.left is None and ptr.right is None:
if ptr == self.root:
self.root = None
elif ptr.parent.left == ptr:
ptr.parent.left = None
else:
ptr.parent.right = None
return True
def rotate_left(self, ptr):
"""木の左回転を行う"""
w = ptr.right
w.parent = ptr.parent
if w.parent is not None:
if w.parent.left == ptr:
w.parent.left = w
else:
w.parent.right = w
ptr.right = w.left
if ptr.right is not None:
ptr.right.parent = ptr
ptr.parent = w
w.left = ptr
if ptr == self.root:
self.root = w
self.root.parent = None
def rotate_right(self, ptr):
"""木の右回転を行う"""
w = ptr.left
w.parent = ptr.parent
if w.parent is not None:
if w.parent.right == ptr:
w.parent.right = w
else:
w.parent.left = w
ptr.left = w.right
if ptr.left is not None:
ptr.left.parent = ptr
ptr.parent = w
w.right = ptr
if ptr == self.root:
self.root = w
self.root.parent = None
def search_less_than(self, val):
if val == None:
return None
ptr = self.root
ret = None
while ptr is not None:
if ptr.val >= val:
ptr = ptr.left
else:
ret = ptr.val
ptr = ptr.right
return ret
n = int(input())
a = [int(input()) for i in range(n)]
tp = Treap()
cnt = 0
for i in range(n):
num = tp.search_less_than(a[i])
if num is None:
tp.insert(a[i])
cnt += 1
else:
tp.delete(num)
tp.insert(a[i])
print(cnt)
| Statement
You are given a sequence with N integers: A = \\{ A_1, A_2, \cdots, A_N \\}.
For each of these N integers, we will choose a color and paint the integer
with that color. Here the following condition must be satisfied:
* If A_i and A_j (i < j) are painted with the same color, A_i < A_j.
Find the minimum number of colors required to satisfy the condition. | [{"input": "5\n 2\n 1\n 4\n 5\n 3", "output": "2\n \n\nWe can satisfy the condition with two colors by, for example, painting 2 and 3\nred and painting 1, 4, and 5 blue.\n\n* * *"}, {"input": "4\n 0\n 0\n 0\n 0", "output": "4\n \n\nWe have to paint all the integers with distinct colors."}] |
Print the minimum number of colors required to satisfy the condition.
* * * | s895710842 | Accepted | p02973 | Input is given from Standard Input in the following format:
N
A_1
:
A_N | ###==================================================
### import
import bisect
# from collections import Counter, deque, defaultdict
# from copy import deepcopy
# from functools import reduce, lru_cache
# from heapq import heappush, heappop
# import itertools
# import math
# import string
import sys
### stdin
def input():
return sys.stdin.readline().rstrip()
def iIn():
return int(input())
def iInM():
return map(int, input().split())
def iInM1():
return map(int1, input().split())
def iInLH():
return list(map(int, input().split()))
def iInLH1():
return list(map(int1, input().split()))
def iInLV(n):
return [iIn() for _ in range(n)]
def iInLV1(n):
return [iIn() - 1 for _ in range(n)]
def iInLD(n):
return [iInLH() for _ in range(n)]
def iInLD1(n):
return [iInLH1() for _ in range(n)]
def sInLH():
return list(input().split())
def sInLV(n):
return [input().rstrip("\n") for _ in range(n)]
def sInLD(n):
return [sInLH() for _ in range(n)]
### stdout
def OutH(lst, deli=" "):
print(deli.join(map(str, lst)))
def OutV(lst):
print("\n".join(map(str, lst)))
### setting
sys.setrecursionlimit(10**6)
### utils
int1 = lambda x: int(x) - 1
### constants
INF = int(1e9)
MOD = 1000000007
dx = (-1, 0, 1, 0)
dy = (0, -1, 0, 1)
###---------------------------------------------------
N = iIn()
A = iInLV(N)
lst = [A[0]]
for i in range(1, N):
idx = bisect.bisect_left(lst, A[i])
if idx == 0:
lst.insert(0, A[i])
else:
lst[idx - 1] = A[i]
print(len(lst))
| Statement
You are given a sequence with N integers: A = \\{ A_1, A_2, \cdots, A_N \\}.
For each of these N integers, we will choose a color and paint the integer
with that color. Here the following condition must be satisfied:
* If A_i and A_j (i < j) are painted with the same color, A_i < A_j.
Find the minimum number of colors required to satisfy the condition. | [{"input": "5\n 2\n 1\n 4\n 5\n 3", "output": "2\n \n\nWe can satisfy the condition with two colors by, for example, painting 2 and 3\nred and painting 1, 4, and 5 blue.\n\n* * *"}, {"input": "4\n 0\n 0\n 0\n 0", "output": "4\n \n\nWe have to paint all the integers with distinct colors."}] |
Print the minimum number of colors required to satisfy the condition.
* * * | s069884121 | Accepted | p02973 | Input is given from Standard Input in the following format:
N
A_1
:
A_N | import bisect
class Deque:
def __init__(self, src_arr=[], max_size=300000):
self.N = max(max_size, len(src_arr)) + 1
self.buf = list(src_arr) + [None] * (self.N - len(src_arr))
self.head = 0
self.tail = len(src_arr)
def __index(self, i):
l = len(self)
if not -l <= i < l:
raise IndexError("index out of range: " + str(i))
if i < 0:
i += l
return (self.head + i) % self.N
def __extend(self):
ex = self.N - 1
self.buf[self.tail + 1 : self.tail + 1] = [None] * ex
self.N = len(self.buf)
if self.head > 0:
self.head += ex
def is_full(self):
return len(self) >= self.N - 1
def is_empty(self):
return len(self) == 0
def append(self, x):
if self.is_full():
self.__extend()
self.buf[self.tail] = x
self.tail += 1
self.tail %= self.N
def appendleft(self, x):
if self.is_full():
self.__extend()
self.buf[(self.head - 1) % self.N] = x
self.head -= 1
self.head %= self.N
def pop(self):
if self.is_empty():
raise IndexError("pop() when buffer is empty")
ret = self.buf[(self.tail - 1) % self.N]
self.tail -= 1
self.tail %= self.N
return ret
def popleft(self):
if self.is_empty():
raise IndexError("popleft() when buffer is empty")
ret = self.buf[self.head]
self.head += 1
self.head %= self.N
return ret
def __len__(self):
return (self.tail - self.head) % self.N
def __getitem__(self, key):
return self.buf[self.__index(key)]
def __setitem__(self, key, value):
self.buf[self.__index(key)] = value
def __str__(self):
return "Deque({0})".format(str(list(self)))
N = int(input())
A = [int(input()) for _ in range(N)]
x = Deque()
for i, a in enumerate(A):
if i == 0:
x.append(a)
else:
r = bisect.bisect_left(x, a)
if r == 0:
x.appendleft(a)
else:
x[r - 1] = a
print(len(x))
| Statement
You are given a sequence with N integers: A = \\{ A_1, A_2, \cdots, A_N \\}.
For each of these N integers, we will choose a color and paint the integer
with that color. Here the following condition must be satisfied:
* If A_i and A_j (i < j) are painted with the same color, A_i < A_j.
Find the minimum number of colors required to satisfy the condition. | [{"input": "5\n 2\n 1\n 4\n 5\n 3", "output": "2\n \n\nWe can satisfy the condition with two colors by, for example, painting 2 and 3\nred and painting 1, 4, and 5 blue.\n\n* * *"}, {"input": "4\n 0\n 0\n 0\n 0", "output": "4\n \n\nWe have to paint all the integers with distinct colors."}] |
Print the minimum number of colors required to satisfy the condition.
* * * | s633413676 | Accepted | p02973 | Input is given from Standard Input in the following format:
N
A_1
:
A_N | # https://atcoder.jp/contests/abc134/tasks/abc134_e
import sys
read = sys.stdin.readline
def read_a_int():
return int(read())
from bisect import bisect_left, bisect_right, insort_left
from array import array
class BinarySearchTree:
def __init__(self, ls: list = []):
"""
C++でいうsetを実装する。二分探索木をガチで実装しようとすると大変なので、ここでは配列二分法を用いる。
pythonの標準ライブラリがヨイショに抱っこしてくれるおかげで楽に実装できる。
https://docs.python.org/ja/3/library/bisect.html
ls ... 渡す初期配列
"""
self.bst = array(
"q", sorted(ls)
) # insertを爆速にするためにarray型にします。signed long long 前提です
# def __repr__(self):
# return f'BST:{self.bst}'
def __len__(self):
return len(self.bst)
def __getitem__(self, idx):
return self.bst[idx]
def size(self):
return len(self.bst)
def insert(self, x):
# idx = self.bisect_left(x)
# self.bst.insert(idx,x)
insort_left(self.bst, x)
def pop_left(self):
x = self.bst[0]
del self.bst[0]
return x
def pop_right(self):
x = self.bst[-1]
del self.bst[-1]
return x
def remove(self, x):
"""
xを取り除く。xがself.bstに存在することを保証してください。
同一のものが存在した場合は左から消していく
"""
del self.bst[self.find(x)]
def bisect_left(self, x):
"""
ソートされた順序を保ったまま x を self.bst に挿入できる点を探し当てます。
lower_bound in C++
"""
return bisect_left(self.bst, x)
def bisect_right(self, x):
"""
bisect_left() と似ていますが、 self.bst に含まれる x のうち、どのエントリーよりも後ろ(右)にくるような挿入点を返します。
upper_bound in C++
"""
return bisect_right(self.bst, x)
def find(self, x):
"""
xのidxを探索
"""
idx = bisect_left(self.bst, x)
if idx != len(self.bst) and self.bst[idx] == x:
return idx
raise ValueError
def insert_replace_left(self, x):
"""
xを挿入して、xの左の数字(次に小さい)を削除する。idxがはみ出す場合は挿入だけ
"""
idx_del = self.bisect_left(x) - 1
if idx_del + 1 == 0: # xがどの要素よりも小さい
self.insert(x)
if idx_del < len(self.bst):
self.insert(x)
del self.bst[idx_del]
def insert_replace_right(self, x):
"""
xを挿入して、xの右の数字(次に大きい)を削除する。idxがはみ出す場合は挿入だけ
"""
idx_del = self.bisect_right(x) + 1 # xと同じ大きさも削除したいならbisect_left
if idx_del - 1 == len(self.bst): # xがどの要素よりも大きい
self.insert(x)
else:
self.insert(x)
del self.bst[idx_del]
N = read_a_int()
bst = BinarySearchTree([-1])
for n in range(N):
a = read_a_int()
# すべてより小さかったら、新しく追加
if bst.bst[0] >= a:
bst.insert(a)
else:
# bstのなかで、aより小さく且つ一番大きい要素をaに書き換えていく
idx = bst.bisect_left(a) - 1
bst.bst[idx] = a
print(len(bst))
| Statement
You are given a sequence with N integers: A = \\{ A_1, A_2, \cdots, A_N \\}.
For each of these N integers, we will choose a color and paint the integer
with that color. Here the following condition must be satisfied:
* If A_i and A_j (i < j) are painted with the same color, A_i < A_j.
Find the minimum number of colors required to satisfy the condition. | [{"input": "5\n 2\n 1\n 4\n 5\n 3", "output": "2\n \n\nWe can satisfy the condition with two colors by, for example, painting 2 and 3\nred and painting 1, 4, and 5 blue.\n\n* * *"}, {"input": "4\n 0\n 0\n 0\n 0", "output": "4\n \n\nWe have to paint all the integers with distinct colors."}] |
Print the answer.
* * * | s055336061 | Wrong Answer | p03661 | Input is given from Standard Input in the following format:
N
a_1 a_2 ... a_{N} | n = int(input())
A = list(map(int, input().split()))
A = sorted(A, reverse=1)
qq = min(A, key=lambda x: abs(x))
a, b = 0, 0
c, d = 0, 0
for i in range(n):
if A[i] > 0:
if a < b:
a += A[i]
c = 1
else:
b += A[i]
d = 1
else:
if a < b:
b += A[i]
d = 1
else:
a += A[i]
c = 1
if c == 0 or d == 0:
# print("ooio")
print(abs(a - b) + 2 * abs(qq))
exit()
print(abs(a - b))
| Statement
Snuke and Raccoon have a heap of N cards. The i-th card from the top has the
integer a_i written on it.
They will share these cards. First, Snuke will take some number of cards from
the top of the heap, then Raccoon will take all the remaining cards. Here,
both Snuke and Raccoon have to take at least one card.
Let the sum of the integers on Snuke's cards and Raccoon's cards be x and y,
respectively. They would like to minimize |x-y|. Find the minimum possible
value of |x-y|. | [{"input": "6\n 1 2 3 4 5 6", "output": "1\n \n\nIf Snuke takes four cards from the top, and Raccoon takes the remaining two\ncards, x=10, y=11, and thus |x-y|=1. This is the minimum possible value.\n\n* * *"}, {"input": "2\n 10 -10", "output": "20\n \n\nSnuke can only take one card from the top, and Raccoon can only take the\nremaining one card. In this case, x=10, y=-10, and thus |x-y|=20."}] |
Print the answer.
* * * | s892552099 | Accepted | p03661 | Input is given from Standard Input in the following format:
N
a_1 a_2 ... a_{N} | #!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on 2019/2/
Solved on 2019/2/
@author: shinjisu
"""
# ARC 078 C Splitting Pile
def getInt():
return int(input())
def getIntList():
return [int(x) for x in input().split()]
def zeros(n):
return [0] * n
def getIntLines(n):
return [int(input()) for i in range(n)]
def getIntMat(n):
mat = []
for i in range(n):
mat.append(getIntList())
return mat
def zeros2(n, m):
return [zeros(m)] * n
ALPHABET = [chr(i + ord("a")) for i in range(26)]
DIGIT = [chr(i + ord("0")) for i in range(10)]
N1097 = 10**9 + 7
def dmp(x, cmt=""):
global debug
if debug:
if cmt != "":
print(cmt, ": ", end="")
print(x)
return x
def probC():
N = getInt()
A = getIntList()
dmp((N, A))
sumFormer = A[0]
sumLatter = sum(A[1:])
diff = abs(sumFormer - sumLatter)
dmp(diff, "init")
for i in range(1, N - 1):
sumFormer += A[i]
sumLatter -= A[i]
diff = min(diff, abs(sumFormer - sumLatter))
return diff
def probC_v1(): # 5/16 AC 残りはTLE
N = getInt()
A = getIntList()
dmp((N, A))
diff = 10 ** (9 + 6)
for i in range(1, N):
diff = min(diff, abs(sum(A[:i]) - sum(A[i:])))
return diff
debug = False # True False
ans = probC()
print(ans)
# for row in ans:
# print(row)
| Statement
Snuke and Raccoon have a heap of N cards. The i-th card from the top has the
integer a_i written on it.
They will share these cards. First, Snuke will take some number of cards from
the top of the heap, then Raccoon will take all the remaining cards. Here,
both Snuke and Raccoon have to take at least one card.
Let the sum of the integers on Snuke's cards and Raccoon's cards be x and y,
respectively. They would like to minimize |x-y|. Find the minimum possible
value of |x-y|. | [{"input": "6\n 1 2 3 4 5 6", "output": "1\n \n\nIf Snuke takes four cards from the top, and Raccoon takes the remaining two\ncards, x=10, y=11, and thus |x-y|=1. This is the minimum possible value.\n\n* * *"}, {"input": "2\n 10 -10", "output": "20\n \n\nSnuke can only take one card from the top, and Raccoon can only take the\nremaining one card. In this case, x=10, y=-10, and thus |x-y|=20."}] |
Print the answer.
* * * | s792830906 | Accepted | p03661 | Input is given from Standard Input in the following format:
N
a_1 a_2 ... a_{N} | ans = float("INF")
A = int(input())
l = list(map(int, input().split()))
maximum = sum(l)
n = 0
for i in range(A - 1):
n += l[i]
ans = min(ans, abs(maximum - n * 2))
print(ans)
| Statement
Snuke and Raccoon have a heap of N cards. The i-th card from the top has the
integer a_i written on it.
They will share these cards. First, Snuke will take some number of cards from
the top of the heap, then Raccoon will take all the remaining cards. Here,
both Snuke and Raccoon have to take at least one card.
Let the sum of the integers on Snuke's cards and Raccoon's cards be x and y,
respectively. They would like to minimize |x-y|. Find the minimum possible
value of |x-y|. | [{"input": "6\n 1 2 3 4 5 6", "output": "1\n \n\nIf Snuke takes four cards from the top, and Raccoon takes the remaining two\ncards, x=10, y=11, and thus |x-y|=1. This is the minimum possible value.\n\n* * *"}, {"input": "2\n 10 -10", "output": "20\n \n\nSnuke can only take one card from the top, and Raccoon can only take the\nremaining one card. In this case, x=10, y=-10, and thus |x-y|=20."}] |
Print the answer.
* * * | s822635560 | Runtime Error | p03661 | Input is given from Standard Input in the following format:
N
a_1 a_2 ... a_{N} | print("?", 10**10)
if input() == "Y":
for nod in range(10):
print("?", 10**nod + 1)
if input() == "Y":
break
ans = 10**nod
else:
for nod in range(1, 10):
print("?", 10**nod)
if input() == "Y":
continue
nod -= 1
break
ok = 10 ** (nod - 1)
ng = 10**nod
while abs(ok - ng) > 1:
med = (ok + ng) // 2
print("?", med * 10 + 1)
if input() == "N":
ok = med
else:
ng = med
ans = ok + 1
print("!", ans)
| Statement
Snuke and Raccoon have a heap of N cards. The i-th card from the top has the
integer a_i written on it.
They will share these cards. First, Snuke will take some number of cards from
the top of the heap, then Raccoon will take all the remaining cards. Here,
both Snuke and Raccoon have to take at least one card.
Let the sum of the integers on Snuke's cards and Raccoon's cards be x and y,
respectively. They would like to minimize |x-y|. Find the minimum possible
value of |x-y|. | [{"input": "6\n 1 2 3 4 5 6", "output": "1\n \n\nIf Snuke takes four cards from the top, and Raccoon takes the remaining two\ncards, x=10, y=11, and thus |x-y|=1. This is the minimum possible value.\n\n* * *"}, {"input": "2\n 10 -10", "output": "20\n \n\nSnuke can only take one card from the top, and Raccoon can only take the\nremaining one card. In this case, x=10, y=-10, and thus |x-y|=20."}] |
Print the answer.
* * * | s337020121 | Wrong Answer | p03661 | Input is given from Standard Input in the following format:
N
a_1 a_2 ... a_{N} | def spaceinput():
return list(map(int, input().split(" ")))
def f(c):
return abs(sum(aa[:c]) - sum(aa[c:]))
N = int(input())
aa = spaceinput()
l = 0
r = len(aa) - 1
vl = f(l + 1)
vr = f(r)
while True:
c = int((l + r) / 2)
if c == 0:
c += 1
vc = f(c)
if vl > vc:
l = c
vl = vc
elif vr > vc:
r = c
vr = vc
else:
break
print(f(c))
| Statement
Snuke and Raccoon have a heap of N cards. The i-th card from the top has the
integer a_i written on it.
They will share these cards. First, Snuke will take some number of cards from
the top of the heap, then Raccoon will take all the remaining cards. Here,
both Snuke and Raccoon have to take at least one card.
Let the sum of the integers on Snuke's cards and Raccoon's cards be x and y,
respectively. They would like to minimize |x-y|. Find the minimum possible
value of |x-y|. | [{"input": "6\n 1 2 3 4 5 6", "output": "1\n \n\nIf Snuke takes four cards from the top, and Raccoon takes the remaining two\ncards, x=10, y=11, and thus |x-y|=1. This is the minimum possible value.\n\n* * *"}, {"input": "2\n 10 -10", "output": "20\n \n\nSnuke can only take one card from the top, and Raccoon can only take the\nremaining one card. In this case, x=10, y=-10, and thus |x-y|=20."}] |
Print the answer.
* * * | s509805740 | Runtime Error | p03661 | Input is given from Standard Input in the following format:
N
a_1 a_2 ... a_{N} | N = int(input())
e_list = [[] for i in range(N)]
for i in range(N - 1):
a, b = list(map(int, input().split()))
a, b = a - 1, b - 1
e_list[a].append(b)
e_list[b].append(a)
vi = 0 # 時と場合によってここを変える
from collections import deque
Q = deque([vi])
checked_list = [False for i in range(N)]
checked_list[vi] = True
prev_list = [-1 for i in range(N)]
min_path_list = [10**27 for i in range(N)] # 問題によりここを変える
min_path_list[vi] = 0
while len(Q) > 0:
v = Q.pop()
for v1 in e_list[v]:
if not checked_list[v1]:
checked_list[v1] = True
Q.appendleft(v1)
prev_list[v1] = v
min_path_list[v1] = min(
min_path_list[v1], min_path_list[v] + 1
) # 問題によりここを変える
path = [N - 1]
v = N - 1
while prev_list[v] != -1:
path.append(prev_list[v])
v = prev_list[v]
a = path[(min_path_list[N - 1] - 1) // 2]
b = path[(min_path_list[N - 1] - 1) // 2 + 1]
for i in range(len(e_list[a])):
if e_list[a][i] == b:
break
del e_list[a][i]
for i in range(len(e_list[b])):
if e_list[b][i] == a:
break
del e_list[b][i]
vi = 0 # 時と場合によってここを変える
Q = deque([vi])
checked_list = [False for i in range(N)]
checked_list[vi] = True
count = 1
while len(Q) > 0:
v = Q.pop()
for v1 in e_list[v]:
if not checked_list[v1]:
checked_list[v1] = True
Q.appendleft(v1)
count += 1
if count > N - count:
print("Fennec")
else:
print("Snuke")
| Statement
Snuke and Raccoon have a heap of N cards. The i-th card from the top has the
integer a_i written on it.
They will share these cards. First, Snuke will take some number of cards from
the top of the heap, then Raccoon will take all the remaining cards. Here,
both Snuke and Raccoon have to take at least one card.
Let the sum of the integers on Snuke's cards and Raccoon's cards be x and y,
respectively. They would like to minimize |x-y|. Find the minimum possible
value of |x-y|. | [{"input": "6\n 1 2 3 4 5 6", "output": "1\n \n\nIf Snuke takes four cards from the top, and Raccoon takes the remaining two\ncards, x=10, y=11, and thus |x-y|=1. This is the minimum possible value.\n\n* * *"}, {"input": "2\n 10 -10", "output": "20\n \n\nSnuke can only take one card from the top, and Raccoon can only take the\nremaining one card. In this case, x=10, y=-10, and thus |x-y|=20."}] |
Print the answer.
* * * | s362038175 | Wrong Answer | p03661 | Input is given from Standard Input in the following format:
N
a_1 a_2 ... a_{N} | a = int(input())
ar = list(map(int, input().split(" ")))
n = a // 2
if sum(ar[0:n]) <= sum(ar[n:a]):
while True:
l = sum(ar[0:n])
r = sum(ar[n:a])
if l >= r:
break
elif n == a - 1:
print(abs(l - r))
break
n += 1
print(min(abs(l - r), abs(sum(ar[0 : n - 1]) - sum(ar[n - 1 : a]))))
else:
while True:
l = sum(ar[0:n])
r = sum(ar[n:a])
if l >= r:
break
elif n == 1:
print(abs(l - r))
break
n -= 1
print(min(abs(l - r), abs(sum(ar[0 : n + 1]) - sum(ar[n + 1 : a]))))
| Statement
Snuke and Raccoon have a heap of N cards. The i-th card from the top has the
integer a_i written on it.
They will share these cards. First, Snuke will take some number of cards from
the top of the heap, then Raccoon will take all the remaining cards. Here,
both Snuke and Raccoon have to take at least one card.
Let the sum of the integers on Snuke's cards and Raccoon's cards be x and y,
respectively. They would like to minimize |x-y|. Find the minimum possible
value of |x-y|. | [{"input": "6\n 1 2 3 4 5 6", "output": "1\n \n\nIf Snuke takes four cards from the top, and Raccoon takes the remaining two\ncards, x=10, y=11, and thus |x-y|=1. This is the minimum possible value.\n\n* * *"}, {"input": "2\n 10 -10", "output": "20\n \n\nSnuke can only take one card from the top, and Raccoon can only take the\nremaining one card. In this case, x=10, y=-10, and thus |x-y|=20."}] |
Print the answer.
* * * | s689174932 | Wrong Answer | p03661 | Input is given from Standard Input in the following format:
N
a_1 a_2 ... a_{N} | _ = input()
a = [int(i) for i in input().split(" ")]
res = 9999999999999999999999999
for i in range(1, len(a)):
s = sum(a[:i])
t = sum(a[i:])
temp = abs(s - t)
res = min(temp, res)
| Statement
Snuke and Raccoon have a heap of N cards. The i-th card from the top has the
integer a_i written on it.
They will share these cards. First, Snuke will take some number of cards from
the top of the heap, then Raccoon will take all the remaining cards. Here,
both Snuke and Raccoon have to take at least one card.
Let the sum of the integers on Snuke's cards and Raccoon's cards be x and y,
respectively. They would like to minimize |x-y|. Find the minimum possible
value of |x-y|. | [{"input": "6\n 1 2 3 4 5 6", "output": "1\n \n\nIf Snuke takes four cards from the top, and Raccoon takes the remaining two\ncards, x=10, y=11, and thus |x-y|=1. This is the minimum possible value.\n\n* * *"}, {"input": "2\n 10 -10", "output": "20\n \n\nSnuke can only take one card from the top, and Raccoon can only take the\nremaining one card. In this case, x=10, y=-10, and thus |x-y|=20."}] |
If a good string does not exist, print `-1`; if it exists, print the length of
the shortest such string.
* * * | s464261625 | Wrong Answer | p03231 | Input is given from Standard Input in the following format:
N M
S
T | print(-1)
| Statement
You are given a string S of length N and another string T of length M. These
strings consist of lowercase English letters.
A string X is called a **good string** when the following conditions are all
met:
* Let L be the length of X. L is divisible by both N and M.
* Concatenating the 1-st, (\frac{L}{N}+1)-th, (2 \times \frac{L}{N}+1)-th, ..., ((N-1)\times\frac{L}{N}+1)-th characters of X, without changing the order, results in S.
* Concatenating the 1-st, (\frac{L}{M}+1)-th, (2 \times \frac{L}{M}+1)-th, ..., ((M-1)\times\frac{L}{M}+1)-th characters of X, without changing the order, results in T.
Determine if there exists a good string. If it exists, find the length of the
shortest such string. | [{"input": "3 2\n acp\n ae", "output": "6\n \n\nFor example, the string `accept` is a good string. There is no good string\nshorter than this, so the answer is 6.\n\n* * *"}, {"input": "6 3\n abcdef\n abc", "output": "-1\n \n\n* * *"}, {"input": "15 9\n dnsusrayukuaiia\n dujrunuma", "output": "45"}] |
If a good string does not exist, print `-1`; if it exists, print the length of
the shortest such string.
* * * | s111845666 | Runtime Error | p03231 | Input is given from Standard Input in the following format:
N M
S
T | import fractions
n,m=map(int,input().split())
s=list(input())
t=list(input())
if s[0]!=t[0]:
print(-1)
exit()
p=n*m//fractions.gcd(n,m)
sf=p//n
tf=p//m
for i in range(1,p):
if i%n==i%m==0:
if s[i//m]!=l[i//n]:
print(-1)
exit()
print(p)
| Statement
You are given a string S of length N and another string T of length M. These
strings consist of lowercase English letters.
A string X is called a **good string** when the following conditions are all
met:
* Let L be the length of X. L is divisible by both N and M.
* Concatenating the 1-st, (\frac{L}{N}+1)-th, (2 \times \frac{L}{N}+1)-th, ..., ((N-1)\times\frac{L}{N}+1)-th characters of X, without changing the order, results in S.
* Concatenating the 1-st, (\frac{L}{M}+1)-th, (2 \times \frac{L}{M}+1)-th, ..., ((M-1)\times\frac{L}{M}+1)-th characters of X, without changing the order, results in T.
Determine if there exists a good string. If it exists, find the length of the
shortest such string. | [{"input": "3 2\n acp\n ae", "output": "6\n \n\nFor example, the string `accept` is a good string. There is no good string\nshorter than this, so the answer is 6.\n\n* * *"}, {"input": "6 3\n abcdef\n abc", "output": "-1\n \n\n* * *"}, {"input": "15 9\n dnsusrayukuaiia\n dujrunuma", "output": "45"}] |
If a good string does not exist, print `-1`; if it exists, print the length of
the shortest such string.
* * * | s041085991 | Runtime Error | p03231 | Input is given from Standard Input in the following format:
N M
S
T | from fractions import gcd
lcm = lambda x, y: x*y//gcd(x, y)
N, M = map(int, input().split())
s = input(
t = input()
l = lcm(N, M)
n, m = N//l, M//l
for i in range(l):
if s[m*i] != t[n*i]:
print(-1)
exit()
print(l) | Statement
You are given a string S of length N and another string T of length M. These
strings consist of lowercase English letters.
A string X is called a **good string** when the following conditions are all
met:
* Let L be the length of X. L is divisible by both N and M.
* Concatenating the 1-st, (\frac{L}{N}+1)-th, (2 \times \frac{L}{N}+1)-th, ..., ((N-1)\times\frac{L}{N}+1)-th characters of X, without changing the order, results in S.
* Concatenating the 1-st, (\frac{L}{M}+1)-th, (2 \times \frac{L}{M}+1)-th, ..., ((M-1)\times\frac{L}{M}+1)-th characters of X, without changing the order, results in T.
Determine if there exists a good string. If it exists, find the length of the
shortest such string. | [{"input": "3 2\n acp\n ae", "output": "6\n \n\nFor example, the string `accept` is a good string. There is no good string\nshorter than this, so the answer is 6.\n\n* * *"}, {"input": "6 3\n abcdef\n abc", "output": "-1\n \n\n* * *"}, {"input": "15 9\n dnsusrayukuaiia\n dujrunuma", "output": "45"}] |
If a good string does not exist, print `-1`; if it exists, print the length of
the shortest such string.
* * * | s980329035 | Runtime Error | p03231 | Input is given from Standard Input in the following format:
N M
S
T | import fractions
n,m=map(int,input().split())
s=list(input())
t=list(input())
if s[0]!=t[0]:
print(-1)
exit()
p=n*m//fractions.gcd(n,m)
sf=p//n
tf=p//m
for i in range(1,p):
if i%n==i%m==0:
if s[i//m]!=t[i//n]:
print(-1)
exit()
print(p)
| Statement
You are given a string S of length N and another string T of length M. These
strings consist of lowercase English letters.
A string X is called a **good string** when the following conditions are all
met:
* Let L be the length of X. L is divisible by both N and M.
* Concatenating the 1-st, (\frac{L}{N}+1)-th, (2 \times \frac{L}{N}+1)-th, ..., ((N-1)\times\frac{L}{N}+1)-th characters of X, without changing the order, results in S.
* Concatenating the 1-st, (\frac{L}{M}+1)-th, (2 \times \frac{L}{M}+1)-th, ..., ((M-1)\times\frac{L}{M}+1)-th characters of X, without changing the order, results in T.
Determine if there exists a good string. If it exists, find the length of the
shortest such string. | [{"input": "3 2\n acp\n ae", "output": "6\n \n\nFor example, the string `accept` is a good string. There is no good string\nshorter than this, so the answer is 6.\n\n* * *"}, {"input": "6 3\n abcdef\n abc", "output": "-1\n \n\n* * *"}, {"input": "15 9\n dnsusrayukuaiia\n dujrunuma", "output": "45"}] |
If a good string does not exist, print `-1`; if it exists, print the length of
the shortest such string.
* * * | s341307353 | Accepted | p03231 | Input is given from Standard Input in the following format:
N M
S
T | # https://atcoder.jp/contests/agc028/tasks/agc028_a
# 問題からエスパーするとlcmが答えになる
# lcmで作れないならそれ以上伸ばしても絶対作れない
import sys
sys.setrecursionlimit(1 << 25)
read = sys.stdin.readline
ra = range
enu = enumerate
def mina(*argv, sub=1):
return list(map(lambda x: x - sub, argv))
# 受け渡されたすべての要素からsubだけ引く.リストを*をつけて展開しておくこと
def read_ints():
return list(map(int, read().split()))
from math import gcd
def lcm(a, b):
# 最小公倍数
g = gcd(a, b)
return a // g * b
N, M = read_ints()
S = read()[:-1]
T = read()[:-1]
L = lcm(N, M)
# 衝突する文字は各文字数をgcdで割った文字ごとに出現する
s_step = N // gcd(N, M)
t_step = M // gcd(N, M)
print(L if S[::s_step] == T[::t_step] else -1)
| Statement
You are given a string S of length N and another string T of length M. These
strings consist of lowercase English letters.
A string X is called a **good string** when the following conditions are all
met:
* Let L be the length of X. L is divisible by both N and M.
* Concatenating the 1-st, (\frac{L}{N}+1)-th, (2 \times \frac{L}{N}+1)-th, ..., ((N-1)\times\frac{L}{N}+1)-th characters of X, without changing the order, results in S.
* Concatenating the 1-st, (\frac{L}{M}+1)-th, (2 \times \frac{L}{M}+1)-th, ..., ((M-1)\times\frac{L}{M}+1)-th characters of X, without changing the order, results in T.
Determine if there exists a good string. If it exists, find the length of the
shortest such string. | [{"input": "3 2\n acp\n ae", "output": "6\n \n\nFor example, the string `accept` is a good string. There is no good string\nshorter than this, so the answer is 6.\n\n* * *"}, {"input": "6 3\n abcdef\n abc", "output": "-1\n \n\n* * *"}, {"input": "15 9\n dnsusrayukuaiia\n dujrunuma", "output": "45"}] |
For each dataset in the input, the total fare for the best route (the route
with the minimum total fare) should be output as a line. If the goal cannot be
reached from the start, output "-1". An output line should not contain extra
characters such as spaces.
Once a route from the start to the goal is determined, the total fare of the
route is computed as follows. If two or more lines of the same railway company
are used contiguously, the total distance of these lines is used to compute
the fare of this section. The total fare of the route is the sum of fares of
such "sections consisting of contiguous lines of the same company". Even if
one uses two lines of the same company, if a line of another company is used
between these two lines, the fares of sections including these two lines are
computed independently. No company offers transit discount. | s260060004 | Runtime Error | p00763 | The input consists of multiple datasets, each in the following format.
> _n_ _m_ _c_ _s_ _g_
> _x_ 1 _y_ 1 _d_ 1 _c_ 1
> ...
> _x m_ _y m_ _d m_ _c m_
> _p_ 1 ... _p c_
> _q_ 1,1 ... _q_ 1,_p_ 1-1
> _r_ 1,1 ... _r_ 1,_p_ 1
> ...
> _q_ _c_ ,1 ... _q_ _c,p_ _c_ -1
> _r_ _c_ ,1 ... _r_ _c,p c_
>
Every input item in a dataset is a non-negative integer. Input items in the
same input line are separated by a space.
The first input line gives the size of the railway network and the intended
trip. _n_ is the number of stations (2 ≤ _n_ ≤ 100). _m_ is the number of
lines connecting two stations (0 ≤ _m_ ≤ 10000). _c_ is the number of railway
companies (1 ≤ _c_ ≤ 20). _s_ is the station index of the starting point (1 ≤
_s_ ≤ _n_ ). _g_ is the station index of the goal point (1 ≤ _g_ ≤ _n_ , _g_ ≠
_s_ ).
The following _m_ input lines give the details of (railway) lines. The _i_ -th
line connects two stations _x i _ and _y i _ (1 ≤ _x i_ ≤ _n_ , 1 ≤ _y i_ ≤
_n_ , _x i_ ≠ _y i_ ). Each line can be traveled in both directions. There may
be two or more lines connecting the same pair of stations. _d i _ is the
distance of the _i_ -th line (1 ≤ _d i_ ≤ 200). _c i _ is the company index of
the railway company operating the line (1 ≤ _c i_ ≤ _c_ ).
The fare table (the relation between the distance and the fare) of each
railway company can be expressed as a line chart. For the railway company _j_
, the number of sections of the line chart is given by _p j _ (1 ≤ _p j_ ≤
50). _q j,k _ (1 ≤ _k_ ≤ _p j_-1) gives the distance separating two sections
of the chart (1 ≤ _q j,k_ ≤ 10000). _r j,k _ (1 ≤ _k_ ≤ _p j_ ) gives the fare
increment per unit distance for the corresponding section of the chart (1 ≤ _r
j,k_ ≤ 100). More precisely, with the fare for the distance _z_ denoted by _f
j_ (_z_ ), the fare for distance _z_ satisfying _q_ _j_ ,_k_ -1+1 ≤ _z_ ≤ _q_
_j_ ,_k_ is computed by the recurrence relation _f j_ (_z_) = _f j_ (_z_
-1)+_r j,k_. Assume that _q_ _j_ ,0 and _f j_ (0) are zero, and _q_ _j_ ,_p j_
is infinity.
For example, assume _p j _ = 3, _q_ _j_ ,1 = 3, _q_ _j_ ,2 = 6, _r_ _j_ ,1 =
10, _r_ _j_ ,2 = 5, and _r_ _j_ ,3 = 3. The fare table in this case is as
follows.
distance| 1| 2| 3| 4| 5| 6| 7| 8| 9
---|---|---|---|---|---|---|---|---|---
fare| 10| 20| 30| 35| 40| 45| 48| 51| 54
_q j,k _ increase monotonically with respect to _k_. _r j,k _ decrease
monotonically with respect to _k_.
The last dataset is followed by an input line containing five zeros (separated
by a space). | import heapq
from collections import defaultdict
from functools import lru_cache
from bisect import bisect_right
while True:
N, M, C, S, G = map(int, input().split())
if (
N == M == C == S == G == 0
): # 駅の数、路線の数10000、鉄道会社の数20、出発駅、目的地駅
break
# E = [[[] for _ in range(N + 1)] for _ in range(C + 1)]
D = [[[float("inf")] * (N + 1) for _ in range(N + 1)] for _ in range(C + 1)]
CE = [set() for _ in range(N + 1)]
for _ in range(M):
x, y, d, c = map(int, input().split()) # d<=200
D[c][x][y] = min(D[c][x][y], d)
D[c][y][x] = min(D[c][x][y], d)
CE[c].add(x)
CE[c].add(y)
P = list(map(int, input().split())) # <= 50
Q = []
R = []
for _ in range(C):
Q.append(list(map(int, input().split())) + [1 << 30])
R.append(list(map(int, input().split())))
cum_fare = []
for c_ in range(C):
fare_ = [0]
res = 0
q_p = 0
for q, r in zip(Q[c_][:-1], R[c_][:-1]):
res += (q - q_p) * r
q_p = q
fare_.append(res)
cum_fare.append(fare_)
@lru_cache(maxsize=None)
def fare(d_, c_):
if d_ == float("inf"):
return float("inf")
c_ -= 1
idx = bisect_right(Q[c_], d_)
# print(c_, idx, cum_fare[c_], R[c_])
return cum_fare[c_][idx] + (
R[c_][0] * d_ if idx == 0 else (d_ - Q[c_][idx - 1]) * R[c_][idx]
)
DD = [[float("inf")] * (N + 1) for _ in range(N + 1)]
for c in range(1, C + 1):
D_ = D[c]
l = list(CE[c])
for k in l:
for i in l:
for j in l:
d_ = D_[i][k] + D_[k][j]
if D_[i][j] > d_:
D_[i][j] = d_
# print(D_)
for i in l:
for j in l:
DD[i][j] = min(DD[i][j], fare(D_[i][j], c))
# print(DD)
dist = defaultdict(lambda: float("inf"))
q = []
start = S
dist[start] = 0
heapq.heappush(q, (0, start))
while len(q) != 0:
prob_cost, v = heapq.heappop(q)
# print(prob_cost, v)
if dist[v] < prob_cost:
continue
if v == G:
print(prob_cost)
break
for u, c in enumerate(DD[v]):
if dist[u] > dist[v] + c:
dist[u] = dist[v] + c
heapq.heappush(q, (dist[u], u))
else:
print(-1)
| Railway Connection
Tokyo has a very complex railway system. For example, there exists a partial
map of lines and stations as shown in Figure D-1.

Figure D-1: A sample railway network
Suppose you are going to station D from station A. Obviously, the path with
the shortest distance is A->B->D. However, the path with the shortest distance
does not necessarily mean the minimum cost. Assume the lines A-B, B-C, and C-D
are operated by one railway company, and the line B-D is operated by another
company. In this case, the path A->B->C->D may cost less than A->B->D. One of
the reasons is that the fare is not proportional to the distance. Usually, the
longer the distance is, the fare per unit distance is lower. If one uses lines
of more than one railway company, the fares charged by these companies are
simply added together, and consequently the total cost may become higher
although the distance is shorter than the path using lines of only one
company.
In this problem, a railway network including multiple railway companies is
given. The fare table (the rule to calculate the fare from the distance) of
each company is also given. Your task is, given the starting point and the
goal point, to write a program that computes the path with the least total
fare. | [{"input": "4 2 1 4\n 1 2 2 1\n 2 3 2 1\n 3 4 5 1\n 2 4 4 2\n 3 1\n 3 6\n 10 5 3\n \n 10\n 2 0 1 1 2\n 1\n \n 1\n 4 5 2 4 1\n 4 3 10 1\n 3 2 2 1\n 3 2 1 2\n 3 2 5 2\n 2 1 10 1\n 3 3\n 20 30\n 3 2 1\n 5 10\n 3 2 1\n 5 5 2 1 5\n 1 2 10 2\n 1 3 20 2\n 2 4 20 1\n 3 4 10 1\n 4 5 20 1\n 2 2\n 20\n 4 1\n 20\n 3 1\n 0 0 0 0 0", "output": "-1\n 63\n 130"}] |
For each dataset in the input, the total fare for the best route (the route
with the minimum total fare) should be output as a line. If the goal cannot be
reached from the start, output "-1". An output line should not contain extra
characters such as spaces.
Once a route from the start to the goal is determined, the total fare of the
route is computed as follows. If two or more lines of the same railway company
are used contiguously, the total distance of these lines is used to compute
the fare of this section. The total fare of the route is the sum of fares of
such "sections consisting of contiguous lines of the same company". Even if
one uses two lines of the same company, if a line of another company is used
between these two lines, the fares of sections including these two lines are
computed independently. No company offers transit discount. | s915874540 | Runtime Error | p00763 | The input consists of multiple datasets, each in the following format.
> _n_ _m_ _c_ _s_ _g_
> _x_ 1 _y_ 1 _d_ 1 _c_ 1
> ...
> _x m_ _y m_ _d m_ _c m_
> _p_ 1 ... _p c_
> _q_ 1,1 ... _q_ 1,_p_ 1-1
> _r_ 1,1 ... _r_ 1,_p_ 1
> ...
> _q_ _c_ ,1 ... _q_ _c,p_ _c_ -1
> _r_ _c_ ,1 ... _r_ _c,p c_
>
Every input item in a dataset is a non-negative integer. Input items in the
same input line are separated by a space.
The first input line gives the size of the railway network and the intended
trip. _n_ is the number of stations (2 ≤ _n_ ≤ 100). _m_ is the number of
lines connecting two stations (0 ≤ _m_ ≤ 10000). _c_ is the number of railway
companies (1 ≤ _c_ ≤ 20). _s_ is the station index of the starting point (1 ≤
_s_ ≤ _n_ ). _g_ is the station index of the goal point (1 ≤ _g_ ≤ _n_ , _g_ ≠
_s_ ).
The following _m_ input lines give the details of (railway) lines. The _i_ -th
line connects two stations _x i _ and _y i _ (1 ≤ _x i_ ≤ _n_ , 1 ≤ _y i_ ≤
_n_ , _x i_ ≠ _y i_ ). Each line can be traveled in both directions. There may
be two or more lines connecting the same pair of stations. _d i _ is the
distance of the _i_ -th line (1 ≤ _d i_ ≤ 200). _c i _ is the company index of
the railway company operating the line (1 ≤ _c i_ ≤ _c_ ).
The fare table (the relation between the distance and the fare) of each
railway company can be expressed as a line chart. For the railway company _j_
, the number of sections of the line chart is given by _p j _ (1 ≤ _p j_ ≤
50). _q j,k _ (1 ≤ _k_ ≤ _p j_-1) gives the distance separating two sections
of the chart (1 ≤ _q j,k_ ≤ 10000). _r j,k _ (1 ≤ _k_ ≤ _p j_ ) gives the fare
increment per unit distance for the corresponding section of the chart (1 ≤ _r
j,k_ ≤ 100). More precisely, with the fare for the distance _z_ denoted by _f
j_ (_z_ ), the fare for distance _z_ satisfying _q_ _j_ ,_k_ -1+1 ≤ _z_ ≤ _q_
_j_ ,_k_ is computed by the recurrence relation _f j_ (_z_) = _f j_ (_z_
-1)+_r j,k_. Assume that _q_ _j_ ,0 and _f j_ (0) are zero, and _q_ _j_ ,_p j_
is infinity.
For example, assume _p j _ = 3, _q_ _j_ ,1 = 3, _q_ _j_ ,2 = 6, _r_ _j_ ,1 =
10, _r_ _j_ ,2 = 5, and _r_ _j_ ,3 = 3. The fare table in this case is as
follows.
distance| 1| 2| 3| 4| 5| 6| 7| 8| 9
---|---|---|---|---|---|---|---|---|---
fare| 10| 20| 30| 35| 40| 45| 48| 51| 54
_q j,k _ increase monotonically with respect to _k_. _r j,k _ decrease
monotonically with respect to _k_.
The last dataset is followed by an input line containing five zeros (separated
by a space). | test = 0
while 1:
test += 1
| Railway Connection
Tokyo has a very complex railway system. For example, there exists a partial
map of lines and stations as shown in Figure D-1.

Figure D-1: A sample railway network
Suppose you are going to station D from station A. Obviously, the path with
the shortest distance is A->B->D. However, the path with the shortest distance
does not necessarily mean the minimum cost. Assume the lines A-B, B-C, and C-D
are operated by one railway company, and the line B-D is operated by another
company. In this case, the path A->B->C->D may cost less than A->B->D. One of
the reasons is that the fare is not proportional to the distance. Usually, the
longer the distance is, the fare per unit distance is lower. If one uses lines
of more than one railway company, the fares charged by these companies are
simply added together, and consequently the total cost may become higher
although the distance is shorter than the path using lines of only one
company.
In this problem, a railway network including multiple railway companies is
given. The fare table (the rule to calculate the fare from the distance) of
each company is also given. Your task is, given the starting point and the
goal point, to write a program that computes the path with the least total
fare. | [{"input": "4 2 1 4\n 1 2 2 1\n 2 3 2 1\n 3 4 5 1\n 2 4 4 2\n 3 1\n 3 6\n 10 5 3\n \n 10\n 2 0 1 1 2\n 1\n \n 1\n 4 5 2 4 1\n 4 3 10 1\n 3 2 2 1\n 3 2 1 2\n 3 2 5 2\n 2 1 10 1\n 3 3\n 20 30\n 3 2 1\n 5 10\n 3 2 1\n 5 5 2 1 5\n 1 2 10 2\n 1 3 20 2\n 2 4 20 1\n 3 4 10 1\n 4 5 20 1\n 2 2\n 20\n 4 1\n 20\n 3 1\n 0 0 0 0 0", "output": "-1\n 63\n 130"}] |
If both E869120 and square1001 can obey the instruction in the note and take
desired numbers of pieces of cake, print `Yay!`; otherwise, print `:(`.
* * * | s399537587 | Runtime Error | p03323 | Input is given from Standard Input in the following format:
A B | N,M = map(int,input().split()))
if N<=8 and M<= 8:
print("Yay!")
else:
print(":(") | Statement
E869120's and square1001's 16-th birthday is coming soon.
Takahashi from AtCoder Kingdom gave them a round cake cut into 16 equal fan-
shaped pieces.
E869120 and square1001 were just about to eat A and B of those pieces,
respectively,
when they found a note attached to the cake saying that "the same person
should not take two adjacent pieces of cake".
Can both of them obey the instruction in the note and take desired numbers of
pieces of cake? | [{"input": "5 4", "output": "Yay!\n \n\nBoth of them can take desired number of pieces as follows: \n\n* * *"}, {"input": "8 8", "output": "Yay!\n \n\nBoth of them can take desired number of pieces as follows: \n\n* * *"}, {"input": "11 4", "output": ":(\n \n\nIn this case, there is no way for them to take desired number of pieces,\nunfortunately."}] |
If both E869120 and square1001 can obey the instruction in the note and take
desired numbers of pieces of cake, print `Yay!`; otherwise, print `:(`.
* * * | s165064805 | Runtime Error | p03323 | Input is given from Standard Input in the following format:
A B | a,b=map(int,input().split())
if a=<8 and b=<8:
print("Yay!")
else:
print(":(") | Statement
E869120's and square1001's 16-th birthday is coming soon.
Takahashi from AtCoder Kingdom gave them a round cake cut into 16 equal fan-
shaped pieces.
E869120 and square1001 were just about to eat A and B of those pieces,
respectively,
when they found a note attached to the cake saying that "the same person
should not take two adjacent pieces of cake".
Can both of them obey the instruction in the note and take desired numbers of
pieces of cake? | [{"input": "5 4", "output": "Yay!\n \n\nBoth of them can take desired number of pieces as follows: \n\n* * *"}, {"input": "8 8", "output": "Yay!\n \n\nBoth of them can take desired number of pieces as follows: \n\n* * *"}, {"input": "11 4", "output": ":(\n \n\nIn this case, there is no way for them to take desired number of pieces,\nunfortunately."}] |
If both E869120 and square1001 can obey the instruction in the note and take
desired numbers of pieces of cake, print `Yay!`; otherwise, print `:(`.
* * * | s490566562 | Runtime Error | p03323 | Input is given from Standard Input in the following format:
A B | a,b = map(int,input().split())
if a <= 8 ans b <= 8:
print('Yay!')
else:
print(':(')
| Statement
E869120's and square1001's 16-th birthday is coming soon.
Takahashi from AtCoder Kingdom gave them a round cake cut into 16 equal fan-
shaped pieces.
E869120 and square1001 were just about to eat A and B of those pieces,
respectively,
when they found a note attached to the cake saying that "the same person
should not take two adjacent pieces of cake".
Can both of them obey the instruction in the note and take desired numbers of
pieces of cake? | [{"input": "5 4", "output": "Yay!\n \n\nBoth of them can take desired number of pieces as follows: \n\n* * *"}, {"input": "8 8", "output": "Yay!\n \n\nBoth of them can take desired number of pieces as follows: \n\n* * *"}, {"input": "11 4", "output": ":(\n \n\nIn this case, there is no way for them to take desired number of pieces,\nunfortunately."}] |
If both E869120 and square1001 can obey the instruction in the note and take
desired numbers of pieces of cake, print `Yay!`; otherwise, print `:(`.
* * * | s068930221 | Runtime Error | p03323 | Input is given from Standard Input in the following format:
A B | a,b=list(map(int,input().split()))
if a<=8 and b<=8:
print('Yay!')
esle :
print(':(') | Statement
E869120's and square1001's 16-th birthday is coming soon.
Takahashi from AtCoder Kingdom gave them a round cake cut into 16 equal fan-
shaped pieces.
E869120 and square1001 were just about to eat A and B of those pieces,
respectively,
when they found a note attached to the cake saying that "the same person
should not take two adjacent pieces of cake".
Can both of them obey the instruction in the note and take desired numbers of
pieces of cake? | [{"input": "5 4", "output": "Yay!\n \n\nBoth of them can take desired number of pieces as follows: \n\n* * *"}, {"input": "8 8", "output": "Yay!\n \n\nBoth of them can take desired number of pieces as follows: \n\n* * *"}, {"input": "11 4", "output": ":(\n \n\nIn this case, there is no way for them to take desired number of pieces,\nunfortunately."}] |
If both E869120 and square1001 can obey the instruction in the note and take
desired numbers of pieces of cake, print `Yay!`; otherwise, print `:(`.
* * * | s736590705 | Runtime Error | p03323 | Input is given from Standard Input in the following format:
A B | a, b = map(int, input().split())
if a <= 8 and b <= 8:
print("Yay!")
elif:
print(":(")
| Statement
E869120's and square1001's 16-th birthday is coming soon.
Takahashi from AtCoder Kingdom gave them a round cake cut into 16 equal fan-
shaped pieces.
E869120 and square1001 were just about to eat A and B of those pieces,
respectively,
when they found a note attached to the cake saying that "the same person
should not take two adjacent pieces of cake".
Can both of them obey the instruction in the note and take desired numbers of
pieces of cake? | [{"input": "5 4", "output": "Yay!\n \n\nBoth of them can take desired number of pieces as follows: \n\n* * *"}, {"input": "8 8", "output": "Yay!\n \n\nBoth of them can take desired number of pieces as follows: \n\n* * *"}, {"input": "11 4", "output": ":(\n \n\nIn this case, there is no way for them to take desired number of pieces,\nunfortunately."}] |
If both E869120 and square1001 can obey the instruction in the note and take
desired numbers of pieces of cake, print `Yay!`; otherwise, print `:(`.
* * * | s061778232 | Runtime Error | p03323 | Input is given from Standard Input in the following format:
A B | a, b = map(int, inuput().split())
if a >= 8 and b => 8:
print('Yay!')
else:
print(':(') | Statement
E869120's and square1001's 16-th birthday is coming soon.
Takahashi from AtCoder Kingdom gave them a round cake cut into 16 equal fan-
shaped pieces.
E869120 and square1001 were just about to eat A and B of those pieces,
respectively,
when they found a note attached to the cake saying that "the same person
should not take two adjacent pieces of cake".
Can both of them obey the instruction in the note and take desired numbers of
pieces of cake? | [{"input": "5 4", "output": "Yay!\n \n\nBoth of them can take desired number of pieces as follows: \n\n* * *"}, {"input": "8 8", "output": "Yay!\n \n\nBoth of them can take desired number of pieces as follows: \n\n* * *"}, {"input": "11 4", "output": ":(\n \n\nIn this case, there is no way for them to take desired number of pieces,\nunfortunately."}] |
If both E869120 and square1001 can obey the instruction in the note and take
desired numbers of pieces of cake, print `Yay!`; otherwise, print `:(`.
* * * | s582033629 | Runtime Error | p03323 | Input is given from Standard Input in the following format:
A B | A, B = map(int, input().split())
if A > 8 or B > :
print(':(')
else :
print('Yay!')
| Statement
E869120's and square1001's 16-th birthday is coming soon.
Takahashi from AtCoder Kingdom gave them a round cake cut into 16 equal fan-
shaped pieces.
E869120 and square1001 were just about to eat A and B of those pieces,
respectively,
when they found a note attached to the cake saying that "the same person
should not take two adjacent pieces of cake".
Can both of them obey the instruction in the note and take desired numbers of
pieces of cake? | [{"input": "5 4", "output": "Yay!\n \n\nBoth of them can take desired number of pieces as follows: \n\n* * *"}, {"input": "8 8", "output": "Yay!\n \n\nBoth of them can take desired number of pieces as follows: \n\n* * *"}, {"input": "11 4", "output": ":(\n \n\nIn this case, there is no way for them to take desired number of pieces,\nunfortunately."}] |
If both E869120 and square1001 can obey the instruction in the note and take
desired numbers of pieces of cake, print `Yay!`; otherwise, print `:(`.
* * * | s710265208 | Runtime Error | p03323 | Input is given from Standard Input in the following format:
A B | a, b = map(int, input().split())
if a > 8 or b > 8:
print(":(")
elif:
print("Yay!")
| Statement
E869120's and square1001's 16-th birthday is coming soon.
Takahashi from AtCoder Kingdom gave them a round cake cut into 16 equal fan-
shaped pieces.
E869120 and square1001 were just about to eat A and B of those pieces,
respectively,
when they found a note attached to the cake saying that "the same person
should not take two adjacent pieces of cake".
Can both of them obey the instruction in the note and take desired numbers of
pieces of cake? | [{"input": "5 4", "output": "Yay!\n \n\nBoth of them can take desired number of pieces as follows: \n\n* * *"}, {"input": "8 8", "output": "Yay!\n \n\nBoth of them can take desired number of pieces as follows: \n\n* * *"}, {"input": "11 4", "output": ":(\n \n\nIn this case, there is no way for them to take desired number of pieces,\nunfortunately."}] |
If both E869120 and square1001 can obey the instruction in the note and take
desired numbers of pieces of cake, print `Yay!`; otherwise, print `:(`.
* * * | s986395192 | Runtime Error | p03323 | Input is given from Standard Input in the following format:
A B | a,b=input().split()
a=int(a)
b=int(b)
if a<=8:
if b<=8:
print("Yay!")
else:
print(":(")
else:
print(":(") | Statement
E869120's and square1001's 16-th birthday is coming soon.
Takahashi from AtCoder Kingdom gave them a round cake cut into 16 equal fan-
shaped pieces.
E869120 and square1001 were just about to eat A and B of those pieces,
respectively,
when they found a note attached to the cake saying that "the same person
should not take two adjacent pieces of cake".
Can both of them obey the instruction in the note and take desired numbers of
pieces of cake? | [{"input": "5 4", "output": "Yay!\n \n\nBoth of them can take desired number of pieces as follows: \n\n* * *"}, {"input": "8 8", "output": "Yay!\n \n\nBoth of them can take desired number of pieces as follows: \n\n* * *"}, {"input": "11 4", "output": ":(\n \n\nIn this case, there is no way for them to take desired number of pieces,\nunfortunately."}] |
If both E869120 and square1001 can obey the instruction in the note and take
desired numbers of pieces of cake, print `Yay!`; otherwise, print `:(`.
* * * | s516993022 | Runtime Error | p03323 | Input is given from Standard Input in the following format:
A B | a = []
b = []
mem = {}
ans = 0
def flip(f):
for i in range(len(a)):
for j in range(3):
if f & (1 << j) == 1:
a[i][j] = -a[i][j]
def solve(n, m):
if mem.get((n, m)) != None:
return mem[(n, m)]
if m == 0:
return 0
if n == m:
mem[(n, m)] = sum(b[:n])
return mem[(n, m)]
ans = max([solve(n - 1, m - 1) + b[n - 1], solve(n - 1, m)])
mem[(n, m)] = ans
return ans
n, m = map(int, input().split())
for i in range(n):
a.append(list(map(int, input().split())))
for f in range(8):
b.clear()
flip(f)
for x in a:
b.append(sum(x))
mem.clear()
ans = max([ans, solve(n, m)])
flip(f)
print(ans)
| Statement
E869120's and square1001's 16-th birthday is coming soon.
Takahashi from AtCoder Kingdom gave them a round cake cut into 16 equal fan-
shaped pieces.
E869120 and square1001 were just about to eat A and B of those pieces,
respectively,
when they found a note attached to the cake saying that "the same person
should not take two adjacent pieces of cake".
Can both of them obey the instruction in the note and take desired numbers of
pieces of cake? | [{"input": "5 4", "output": "Yay!\n \n\nBoth of them can take desired number of pieces as follows: \n\n* * *"}, {"input": "8 8", "output": "Yay!\n \n\nBoth of them can take desired number of pieces as follows: \n\n* * *"}, {"input": "11 4", "output": ":(\n \n\nIn this case, there is no way for them to take desired number of pieces,\nunfortunately."}] |
If both E869120 and square1001 can obey the instruction in the note and take
desired numbers of pieces of cake, print `Yay!`; otherwise, print `:(`.
* * * | s370940433 | Wrong Answer | p03323 | Input is given from Standard Input in the following format:
A B | s = input().strip()
ss = s.split()
d = int(ss[0])
n = int(ss[1])
i = 1
while 1:
x = i
c = 0
while x % 100 == 0:
x //= 100
c += 1
if c == d:
n -= 1
if n == 0:
print(i)
break
i += 1
| Statement
E869120's and square1001's 16-th birthday is coming soon.
Takahashi from AtCoder Kingdom gave them a round cake cut into 16 equal fan-
shaped pieces.
E869120 and square1001 were just about to eat A and B of those pieces,
respectively,
when they found a note attached to the cake saying that "the same person
should not take two adjacent pieces of cake".
Can both of them obey the instruction in the note and take desired numbers of
pieces of cake? | [{"input": "5 4", "output": "Yay!\n \n\nBoth of them can take desired number of pieces as follows: \n\n* * *"}, {"input": "8 8", "output": "Yay!\n \n\nBoth of them can take desired number of pieces as follows: \n\n* * *"}, {"input": "11 4", "output": ":(\n \n\nIn this case, there is no way for them to take desired number of pieces,\nunfortunately."}] |
If both E869120 and square1001 can obey the instruction in the note and take
desired numbers of pieces of cake, print `Yay!`; otherwise, print `:(`.
* * * | s894324868 | Runtime Error | p03323 | Input is given from Standard Input in the following format:
A B | import java.io.BufferedReader;
import java.io.*;
import java.util.*;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Collections;
import java.util.Arrays;
public class Main {
public static void main(final String[] args){
final Scanner sc = new Scanner(System.in);
final List<Integer> list = new ArrayList<>();
//final List<Integer> list2 = new ArrayList<>();
//final List<Long> list3 = new ArrayList<>();
int a = sc.nextInt();
int b = sc.nextInt();
if(a < 9 || b < 9){
System.out.println("Yay!");
}else{
System.out.println(":(");
}
}
} | Statement
E869120's and square1001's 16-th birthday is coming soon.
Takahashi from AtCoder Kingdom gave them a round cake cut into 16 equal fan-
shaped pieces.
E869120 and square1001 were just about to eat A and B of those pieces,
respectively,
when they found a note attached to the cake saying that "the same person
should not take two adjacent pieces of cake".
Can both of them obey the instruction in the note and take desired numbers of
pieces of cake? | [{"input": "5 4", "output": "Yay!\n \n\nBoth of them can take desired number of pieces as follows: \n\n* * *"}, {"input": "8 8", "output": "Yay!\n \n\nBoth of them can take desired number of pieces as follows: \n\n* * *"}, {"input": "11 4", "output": ":(\n \n\nIn this case, there is no way for them to take desired number of pieces,\nunfortunately."}] |
If both E869120 and square1001 can obey the instruction in the note and take
desired numbers of pieces of cake, print `Yay!`; otherwise, print `:(`.
* * * | s433849122 | Runtime Error | p03323 | Input is given from Standard Input in the following format:
A B | a b = list(map(int, input().split()))
if a <= 8 and b <= 8:
print('Yay!')
else:
print(':(') | Statement
E869120's and square1001's 16-th birthday is coming soon.
Takahashi from AtCoder Kingdom gave them a round cake cut into 16 equal fan-
shaped pieces.
E869120 and square1001 were just about to eat A and B of those pieces,
respectively,
when they found a note attached to the cake saying that "the same person
should not take two adjacent pieces of cake".
Can both of them obey the instruction in the note and take desired numbers of
pieces of cake? | [{"input": "5 4", "output": "Yay!\n \n\nBoth of them can take desired number of pieces as follows: \n\n* * *"}, {"input": "8 8", "output": "Yay!\n \n\nBoth of them can take desired number of pieces as follows: \n\n* * *"}, {"input": "11 4", "output": ":(\n \n\nIn this case, there is no way for them to take desired number of pieces,\nunfortunately."}] |
If both E869120 and square1001 can obey the instruction in the note and take
desired numbers of pieces of cake, print `Yay!`; otherwise, print `:(`.
* * * | s287263654 | Accepted | p03323 | Input is given from Standard Input in the following format:
A B | print(["Yay!", ":(", ":("][sum([int(x) > 8 for x in input().split()])])
| Statement
E869120's and square1001's 16-th birthday is coming soon.
Takahashi from AtCoder Kingdom gave them a round cake cut into 16 equal fan-
shaped pieces.
E869120 and square1001 were just about to eat A and B of those pieces,
respectively,
when they found a note attached to the cake saying that "the same person
should not take two adjacent pieces of cake".
Can both of them obey the instruction in the note and take desired numbers of
pieces of cake? | [{"input": "5 4", "output": "Yay!\n \n\nBoth of them can take desired number of pieces as follows: \n\n* * *"}, {"input": "8 8", "output": "Yay!\n \n\nBoth of them can take desired number of pieces as follows: \n\n* * *"}, {"input": "11 4", "output": ":(\n \n\nIn this case, there is no way for them to take desired number of pieces,\nunfortunately."}] |
If both E869120 and square1001 can obey the instruction in the note and take
desired numbers of pieces of cake, print `Yay!`; otherwise, print `:(`.
* * * | s399540271 | Accepted | p03323 | Input is given from Standard Input in the following format:
A B | print("Yay!" if max(map(int, input().split())) <= 8 else ":(")
| Statement
E869120's and square1001's 16-th birthday is coming soon.
Takahashi from AtCoder Kingdom gave them a round cake cut into 16 equal fan-
shaped pieces.
E869120 and square1001 were just about to eat A and B of those pieces,
respectively,
when they found a note attached to the cake saying that "the same person
should not take two adjacent pieces of cake".
Can both of them obey the instruction in the note and take desired numbers of
pieces of cake? | [{"input": "5 4", "output": "Yay!\n \n\nBoth of them can take desired number of pieces as follows: \n\n* * *"}, {"input": "8 8", "output": "Yay!\n \n\nBoth of them can take desired number of pieces as follows: \n\n* * *"}, {"input": "11 4", "output": ":(\n \n\nIn this case, there is no way for them to take desired number of pieces,\nunfortunately."}] |
If both E869120 and square1001 can obey the instruction in the note and take
desired numbers of pieces of cake, print `Yay!`; otherwise, print `:(`.
* * * | s831010024 | Accepted | p03323 | Input is given from Standard Input in the following format:
A B | print([":(", "Yay!"][all(i < 9 for i in map(int, input().split()))])
| Statement
E869120's and square1001's 16-th birthday is coming soon.
Takahashi from AtCoder Kingdom gave them a round cake cut into 16 equal fan-
shaped pieces.
E869120 and square1001 were just about to eat A and B of those pieces,
respectively,
when they found a note attached to the cake saying that "the same person
should not take two adjacent pieces of cake".
Can both of them obey the instruction in the note and take desired numbers of
pieces of cake? | [{"input": "5 4", "output": "Yay!\n \n\nBoth of them can take desired number of pieces as follows: \n\n* * *"}, {"input": "8 8", "output": "Yay!\n \n\nBoth of them can take desired number of pieces as follows: \n\n* * *"}, {"input": "11 4", "output": ":(\n \n\nIn this case, there is no way for them to take desired number of pieces,\nunfortunately."}] |
If both E869120 and square1001 can obey the instruction in the note and take
desired numbers of pieces of cake, print `Yay!`; otherwise, print `:(`.
* * * | s194452947 | Accepted | p03323 | Input is given from Standard Input in the following format:
A B | print([":(", "Yay!"][max(list(map(int, input().split()))) <= 8])
| Statement
E869120's and square1001's 16-th birthday is coming soon.
Takahashi from AtCoder Kingdom gave them a round cake cut into 16 equal fan-
shaped pieces.
E869120 and square1001 were just about to eat A and B of those pieces,
respectively,
when they found a note attached to the cake saying that "the same person
should not take two adjacent pieces of cake".
Can both of them obey the instruction in the note and take desired numbers of
pieces of cake? | [{"input": "5 4", "output": "Yay!\n \n\nBoth of them can take desired number of pieces as follows: \n\n* * *"}, {"input": "8 8", "output": "Yay!\n \n\nBoth of them can take desired number of pieces as follows: \n\n* * *"}, {"input": "11 4", "output": ":(\n \n\nIn this case, there is no way for them to take desired number of pieces,\nunfortunately."}] |
If both E869120 and square1001 can obey the instruction in the note and take
desired numbers of pieces of cake, print `Yay!`; otherwise, print `:(`.
* * * | s251840458 | Accepted | p03323 | Input is given from Standard Input in the following format:
A B | print(":(") if max(list(map(int, input().split()))) > 8 else print("Yay!")
| Statement
E869120's and square1001's 16-th birthday is coming soon.
Takahashi from AtCoder Kingdom gave them a round cake cut into 16 equal fan-
shaped pieces.
E869120 and square1001 were just about to eat A and B of those pieces,
respectively,
when they found a note attached to the cake saying that "the same person
should not take two adjacent pieces of cake".
Can both of them obey the instruction in the note and take desired numbers of
pieces of cake? | [{"input": "5 4", "output": "Yay!\n \n\nBoth of them can take desired number of pieces as follows: \n\n* * *"}, {"input": "8 8", "output": "Yay!\n \n\nBoth of them can take desired number of pieces as follows: \n\n* * *"}, {"input": "11 4", "output": ":(\n \n\nIn this case, there is no way for them to take desired number of pieces,\nunfortunately."}] |
If both E869120 and square1001 can obey the instruction in the note and take
desired numbers of pieces of cake, print `Yay!`; otherwise, print `:(`.
* * * | s038149136 | Runtime Error | p03323 | Input is given from Standard Input in the following format:
A B | a,b = map(int, input().strip().split(' '))
print('Yay!' max(a,b) <= 8 else ':(')
| Statement
E869120's and square1001's 16-th birthday is coming soon.
Takahashi from AtCoder Kingdom gave them a round cake cut into 16 equal fan-
shaped pieces.
E869120 and square1001 were just about to eat A and B of those pieces,
respectively,
when they found a note attached to the cake saying that "the same person
should not take two adjacent pieces of cake".
Can both of them obey the instruction in the note and take desired numbers of
pieces of cake? | [{"input": "5 4", "output": "Yay!\n \n\nBoth of them can take desired number of pieces as follows: \n\n* * *"}, {"input": "8 8", "output": "Yay!\n \n\nBoth of them can take desired number of pieces as follows: \n\n* * *"}, {"input": "11 4", "output": ":(\n \n\nIn this case, there is no way for them to take desired number of pieces,\nunfortunately."}] |
If both E869120 and square1001 can obey the instruction in the note and take
desired numbers of pieces of cake, print `Yay!`; otherwise, print `:(`.
* * * | s633052062 | Runtime Error | p03323 | Input is given from Standard Input in the following format:
A B | a, b=map(int,input().split())
if a<=8 && b<=8:
print("Yay!")
else:
print(":(") | Statement
E869120's and square1001's 16-th birthday is coming soon.
Takahashi from AtCoder Kingdom gave them a round cake cut into 16 equal fan-
shaped pieces.
E869120 and square1001 were just about to eat A and B of those pieces,
respectively,
when they found a note attached to the cake saying that "the same person
should not take two adjacent pieces of cake".
Can both of them obey the instruction in the note and take desired numbers of
pieces of cake? | [{"input": "5 4", "output": "Yay!\n \n\nBoth of them can take desired number of pieces as follows: \n\n* * *"}, {"input": "8 8", "output": "Yay!\n \n\nBoth of them can take desired number of pieces as follows: \n\n* * *"}, {"input": "11 4", "output": ":(\n \n\nIn this case, there is no way for them to take desired number of pieces,\nunfortunately."}] |
If both E869120 and square1001 can obey the instruction in the note and take
desired numbers of pieces of cake, print `Yay!`; otherwise, print `:(`.
* * * | s031508442 | Runtime Error | p03323 | Input is given from Standard Input in the following format:
A B | a,b = map(int,input().split())
print(':(' if a > 8 or b > 8 'Yay!') | Statement
E869120's and square1001's 16-th birthday is coming soon.
Takahashi from AtCoder Kingdom gave them a round cake cut into 16 equal fan-
shaped pieces.
E869120 and square1001 were just about to eat A and B of those pieces,
respectively,
when they found a note attached to the cake saying that "the same person
should not take two adjacent pieces of cake".
Can both of them obey the instruction in the note and take desired numbers of
pieces of cake? | [{"input": "5 4", "output": "Yay!\n \n\nBoth of them can take desired number of pieces as follows: \n\n* * *"}, {"input": "8 8", "output": "Yay!\n \n\nBoth of them can take desired number of pieces as follows: \n\n* * *"}, {"input": "11 4", "output": ":(\n \n\nIn this case, there is no way for them to take desired number of pieces,\nunfortunately."}] |
If both E869120 and square1001 can obey the instruction in the note and take
desired numbers of pieces of cake, print `Yay!`; otherwise, print `:(`.
* * * | s886216090 | Runtime Error | p03323 | Input is given from Standard Input in the following format:
A B | a, b = int(input().split())
if a > 8 or b > 8:
print(":(")
elif:
print("Yay!") | Statement
E869120's and square1001's 16-th birthday is coming soon.
Takahashi from AtCoder Kingdom gave them a round cake cut into 16 equal fan-
shaped pieces.
E869120 and square1001 were just about to eat A and B of those pieces,
respectively,
when they found a note attached to the cake saying that "the same person
should not take two adjacent pieces of cake".
Can both of them obey the instruction in the note and take desired numbers of
pieces of cake? | [{"input": "5 4", "output": "Yay!\n \n\nBoth of them can take desired number of pieces as follows: \n\n* * *"}, {"input": "8 8", "output": "Yay!\n \n\nBoth of them can take desired number of pieces as follows: \n\n* * *"}, {"input": "11 4", "output": ":(\n \n\nIn this case, there is no way for them to take desired number of pieces,\nunfortunately."}] |
If both E869120 and square1001 can obey the instruction in the note and take
desired numbers of pieces of cake, print `Yay!`; otherwise, print `:(`.
* * * | s911202725 | Wrong Answer | p03323 | Input is given from Standard Input in the following format:
A B | 0
| Statement
E869120's and square1001's 16-th birthday is coming soon.
Takahashi from AtCoder Kingdom gave them a round cake cut into 16 equal fan-
shaped pieces.
E869120 and square1001 were just about to eat A and B of those pieces,
respectively,
when they found a note attached to the cake saying that "the same person
should not take two adjacent pieces of cake".
Can both of them obey the instruction in the note and take desired numbers of
pieces of cake? | [{"input": "5 4", "output": "Yay!\n \n\nBoth of them can take desired number of pieces as follows: \n\n* * *"}, {"input": "8 8", "output": "Yay!\n \n\nBoth of them can take desired number of pieces as follows: \n\n* * *"}, {"input": "11 4", "output": ":(\n \n\nIn this case, there is no way for them to take desired number of pieces,\nunfortunately."}] |
If both E869120 and square1001 can obey the instruction in the note and take
desired numbers of pieces of cake, print `Yay!`; otherwise, print `:(`.
* * * | s201788515 | Runtime Error | p03323 | Input is given from Standard Input in the following format:
A B | a,b =int(input.split())
if a<=8 and b<=8:
print('Yay!')
else:
print(':(') | Statement
E869120's and square1001's 16-th birthday is coming soon.
Takahashi from AtCoder Kingdom gave them a round cake cut into 16 equal fan-
shaped pieces.
E869120 and square1001 were just about to eat A and B of those pieces,
respectively,
when they found a note attached to the cake saying that "the same person
should not take two adjacent pieces of cake".
Can both of them obey the instruction in the note and take desired numbers of
pieces of cake? | [{"input": "5 4", "output": "Yay!\n \n\nBoth of them can take desired number of pieces as follows: \n\n* * *"}, {"input": "8 8", "output": "Yay!\n \n\nBoth of them can take desired number of pieces as follows: \n\n* * *"}, {"input": "11 4", "output": ":(\n \n\nIn this case, there is no way for them to take desired number of pieces,\nunfortunately."}] |
If both E869120 and square1001 can obey the instruction in the note and take
desired numbers of pieces of cake, print `Yay!`; otherwise, print `:(`.
* * * | s956004036 | Runtime Error | p03323 | Input is given from Standard Input in the following format:
A B | a, b = map(int, input().split())
print("Yay!" if a <= 8 and b <= 8 else: ":(") | Statement
E869120's and square1001's 16-th birthday is coming soon.
Takahashi from AtCoder Kingdom gave them a round cake cut into 16 equal fan-
shaped pieces.
E869120 and square1001 were just about to eat A and B of those pieces,
respectively,
when they found a note attached to the cake saying that "the same person
should not take two adjacent pieces of cake".
Can both of them obey the instruction in the note and take desired numbers of
pieces of cake? | [{"input": "5 4", "output": "Yay!\n \n\nBoth of them can take desired number of pieces as follows: \n\n* * *"}, {"input": "8 8", "output": "Yay!\n \n\nBoth of them can take desired number of pieces as follows: \n\n* * *"}, {"input": "11 4", "output": ":(\n \n\nIn this case, there is no way for them to take desired number of pieces,\nunfortunately."}] |
If both E869120 and square1001 can obey the instruction in the note and take
desired numbers of pieces of cake, print `Yay!`; otherwise, print `:(`.
* * * | s095858865 | Runtime Error | p03323 | Input is given from Standard Input in the following format:
A B | a,b=map(int, input().split())
if a+b=<16:
print('Yay!')
else:
print(':(') | Statement
E869120's and square1001's 16-th birthday is coming soon.
Takahashi from AtCoder Kingdom gave them a round cake cut into 16 equal fan-
shaped pieces.
E869120 and square1001 were just about to eat A and B of those pieces,
respectively,
when they found a note attached to the cake saying that "the same person
should not take two adjacent pieces of cake".
Can both of them obey the instruction in the note and take desired numbers of
pieces of cake? | [{"input": "5 4", "output": "Yay!\n \n\nBoth of them can take desired number of pieces as follows: \n\n* * *"}, {"input": "8 8", "output": "Yay!\n \n\nBoth of them can take desired number of pieces as follows: \n\n* * *"}, {"input": "11 4", "output": ":(\n \n\nIn this case, there is no way for them to take desired number of pieces,\nunfortunately."}] |
If both E869120 and square1001 can obey the instruction in the note and take
desired numbers of pieces of cake, print `Yay!`; otherwise, print `:(`.
* * * | s407920153 | Runtime Error | p03323 | Input is given from Standard Input in the following format:
A B | a,b = map(int,input().split())
if a<9 || b<9:
print("Yay!")
else:
print(":(") | Statement
E869120's and square1001's 16-th birthday is coming soon.
Takahashi from AtCoder Kingdom gave them a round cake cut into 16 equal fan-
shaped pieces.
E869120 and square1001 were just about to eat A and B of those pieces,
respectively,
when they found a note attached to the cake saying that "the same person
should not take two adjacent pieces of cake".
Can both of them obey the instruction in the note and take desired numbers of
pieces of cake? | [{"input": "5 4", "output": "Yay!\n \n\nBoth of them can take desired number of pieces as follows: \n\n* * *"}, {"input": "8 8", "output": "Yay!\n \n\nBoth of them can take desired number of pieces as follows: \n\n* * *"}, {"input": "11 4", "output": ":(\n \n\nIn this case, there is no way for them to take desired number of pieces,\nunfortunately."}] |
If both E869120 and square1001 can obey the instruction in the note and take
desired numbers of pieces of cake, print `Yay!`; otherwise, print `:(`.
* * * | s180706914 | Runtime Error | p03323 | Input is given from Standard Input in the following format:
A B | print(["Yay!", ":(", ":("][sum([x > 8 for x in input().split()])])
| Statement
E869120's and square1001's 16-th birthday is coming soon.
Takahashi from AtCoder Kingdom gave them a round cake cut into 16 equal fan-
shaped pieces.
E869120 and square1001 were just about to eat A and B of those pieces,
respectively,
when they found a note attached to the cake saying that "the same person
should not take two adjacent pieces of cake".
Can both of them obey the instruction in the note and take desired numbers of
pieces of cake? | [{"input": "5 4", "output": "Yay!\n \n\nBoth of them can take desired number of pieces as follows: \n\n* * *"}, {"input": "8 8", "output": "Yay!\n \n\nBoth of them can take desired number of pieces as follows: \n\n* * *"}, {"input": "11 4", "output": ":(\n \n\nIn this case, there is no way for them to take desired number of pieces,\nunfortunately."}] |
If both E869120 and square1001 can obey the instruction in the note and take
desired numbers of pieces of cake, print `Yay!`; otherwise, print `:(`.
* * * | s481342184 | Runtime Error | p03323 | Input is given from Standard Input in the following format:
A B | a, b = map(int, input().split())
if a <= 8 and b b <= 8:
print('Yay!')
else:
print(':(') | Statement
E869120's and square1001's 16-th birthday is coming soon.
Takahashi from AtCoder Kingdom gave them a round cake cut into 16 equal fan-
shaped pieces.
E869120 and square1001 were just about to eat A and B of those pieces,
respectively,
when they found a note attached to the cake saying that "the same person
should not take two adjacent pieces of cake".
Can both of them obey the instruction in the note and take desired numbers of
pieces of cake? | [{"input": "5 4", "output": "Yay!\n \n\nBoth of them can take desired number of pieces as follows: \n\n* * *"}, {"input": "8 8", "output": "Yay!\n \n\nBoth of them can take desired number of pieces as follows: \n\n* * *"}, {"input": "11 4", "output": ":(\n \n\nIn this case, there is no way for them to take desired number of pieces,\nunfortunately."}] |
If both E869120 and square1001 can obey the instruction in the note and take
desired numbers of pieces of cake, print `Yay!`; otherwise, print `:(`.
* * * | s060970813 | Runtime Error | p03323 | Input is given from Standard Input in the following format:
A B | a,b = map(int,input().split())
if a<=8 and b<=8:
print("Yay!")
else:
print(":(")
| Statement
E869120's and square1001's 16-th birthday is coming soon.
Takahashi from AtCoder Kingdom gave them a round cake cut into 16 equal fan-
shaped pieces.
E869120 and square1001 were just about to eat A and B of those pieces,
respectively,
when they found a note attached to the cake saying that "the same person
should not take two adjacent pieces of cake".
Can both of them obey the instruction in the note and take desired numbers of
pieces of cake? | [{"input": "5 4", "output": "Yay!\n \n\nBoth of them can take desired number of pieces as follows: \n\n* * *"}, {"input": "8 8", "output": "Yay!\n \n\nBoth of them can take desired number of pieces as follows: \n\n* * *"}, {"input": "11 4", "output": ":(\n \n\nIn this case, there is no way for them to take desired number of pieces,\nunfortunately."}] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.