wrong_submission_id
stringlengths 10
10
| problem_id
stringlengths 6
6
| user_id
stringlengths 10
10
| time_limit
float64 1k
8k
| memory_limit
float64 131k
1.05M
| wrong_status
stringclasses 2
values | wrong_cpu_time
float64 10
40k
| wrong_memory
float64 2.94k
3.37M
| wrong_code_size
int64 1
15.5k
| problem_description
stringlengths 1
4.75k
| wrong_code
stringlengths 1
6.92k
| acc_submission_id
stringlengths 10
10
| acc_status
stringclasses 1
value | acc_cpu_time
float64 10
27.8k
| acc_memory
float64 2.94k
960k
| acc_code_size
int64 19
14.9k
| acc_code
stringlengths 19
14.9k
|
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
s747550758
|
p03469
|
u987164499
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 32
|
On some day in January 2018, Takaki is writing a document. The document has a column where the current date is written in `yyyy/mm/dd` format. For example, January 23, 2018 should be written as `2018/01/23`. After finishing the document, she noticed that she had mistakenly wrote `2017` at the beginning of the date column. Write a program that, when the string that Takaki wrote in the date column, S, is given as input, modifies the first four characters in S to `2018` and prints it.
|
s = input()
print("2017"+s[4:])
|
s829478567
|
Accepted
| 17
| 2,940
| 32
|
s = input()
print("2018"+s[4:])
|
s886687853
|
p03574
|
u655761160
| 2,000
| 262,144
|
Wrong Answer
| 31
| 3,188
| 630
|
You are given an H × W grid. The squares in the grid are described by H strings, S_1,...,S_H. The j-th character in the string S_i corresponds to the square at the i-th row from the top and j-th column from the left (1 \leq i \leq H,1 \leq j \leq W). `.` stands for an empty square, and `#` stands for a square containing a bomb. Dolphin is interested in how many bomb squares are horizontally, vertically or diagonally adjacent to each empty square. (Below, we will simply say "adjacent" for this meaning. For each square, there are at most eight adjacent squares.) He decides to replace each `.` in our H strings with a digit that represents the number of bomb squares adjacent to the corresponding empty square. Print the strings after the process.
|
H, W = map(int, input().split(' '))
masu = [input() for i in range(H)]
dx = [1, 1, 0, -1, -1, -1, 0, 1]
dy = [0, -1, -1, -1, 0, 1, 1, 1]
ans = []
for i in range(H):
a = []
for j in range(W):
if (masu[i][j] == '#'):
a.append('#')
continue
cnt = 0
for d in range(len(dx)):
x = i + dx[d]
y = j + dy[d]
if (x < 0 or H <= x):
continue
if (y < 0 or W <= y):
continue
if (masu[x][y] == '#'):
cnt += 1
a.append(str(cnt))
ans.append(a)
for b in ans:
print(b)
|
s759757899
|
Accepted
| 30
| 3,188
| 639
|
H, W = map(int, input().split(' '))
masu = [input() for i in range(H)]
dx = [1, 1, 0, -1, -1, -1, 0, 1]
dy = [0, -1, -1, -1, 0, 1, 1, 1]
ans = []
for i in range(H):
a = []
for j in range(W):
if (masu[i][j] == '#'):
a.append('#')
continue
cnt = 0
for d in range(len(dx)):
x = i + dx[d]
y = j + dy[d]
if (x < 0 or H <= x):
continue
if (y < 0 or W <= y):
continue
if (masu[x][y] == '#'):
cnt += 1
a.append(str(cnt))
ans.append(a)
for b in ans:
print("".join(b))
|
s506111437
|
p03434
|
u018976119
| 2,000
| 262,144
|
Wrong Answer
| 18
| 3,064
| 399
|
We have N cards. A number a_i is written on the i-th card. Alice and Bob will play a game using these cards. In this game, Alice and Bob alternately take one card. Alice goes first. The game ends when all the cards are taken by the two players, and the score of each player is the sum of the numbers written on the cards he/she has taken. When both players take the optimal strategy to maximize their scores, find Alice's score minus Bob's score.
|
N=int(input())
numbers=list(map(int,input().split()))
for i in range(1,N):
for k in range(i):
if numbers[k]<numbers[i]:
temp=numbers[k]
numbers[k]=numbers[i]
numbers[i]=temp
break
print(numbers)
Alice=0
Bob=0
for i in range(N//2+N%2):
Alice+=numbers[2*i]
for i in range(N//2):
Bob+=numbers[2*i+1]
print(Alice,Bob)
print(Alice-Bob)
|
s788709749
|
Accepted
| 17
| 3,060
| 232
|
N=int(input())
numbers=list(map(int,input().split()))
new_numbers=sorted(numbers,reverse=True)
Alice=0
Bob=0
for i in range(N//2+N%2):
Alice+=new_numbers[2*i]
for i in range(N//2):
Bob+=new_numbers[2*i+1]
print(Alice-Bob)
|
s069697344
|
p02255
|
u614197626
| 1,000
| 131,072
|
Wrong Answer
| 20
| 7,724
| 275
|
Write a program of the Insertion Sort algorithm which sorts a sequence A in ascending order. The algorithm should be based on the following pseudocode: for i = 1 to A.length-1 key = A[i] /* insert A[i] into the sorted sequence A[0,...,j-1] */ j = i - 1 while j >= 0 and A[j] > key A[j+1] = A[j] j-- A[j+1] = key Note that, indices for array elements are based on 0-origin. To illustrate the algorithms, your program should trace intermediate result for each step.
|
def insertionSort(A,N):
print(A)
for i in range(1,N):
v=A[i]
j=i-1
while j>=0 and A[j]>v:
A[j+1]=A[j]
j-=1
A[j+1]=v
print(A)
N=int(input())
sl=input()
lis=list(map(int,sl.split()))
insertionSort(lis,N)
|
s879445152
|
Accepted
| 30
| 7,724
| 325
|
def insertionSort(A,N):
for i in range(1,N):
v=A[i]
j=i-1
while j>=0 and A[j]>v:
A[j+1]=A[j]
j-=1
A[j+1]=v
print(str(A).replace(",",'').replace("[",'').replace("]",''))
N=int(input())
sl=input()
print(sl)
lis=list(map(int,sl.split()))
insertionSort(lis,N)
|
s107908770
|
p03658
|
u941884460
| 2,000
| 262,144
|
Wrong Answer
| 18
| 3,060
| 171
|
Snuke has N sticks. The length of the i-th stick is l_i. Snuke is making a snake toy by joining K of the sticks together. The length of the toy is represented by the sum of the individual sticks that compose it. Find the maximum possible length of the toy.
|
N,K = map(int,input().split())
num = [0]*N
tmp = input().split()
for i in range(N):
num[i] = int(tmp[i])
num.sort()
sum = 0
for j in range(K):
sum += num[j]
print(sum)
|
s629277212
|
Accepted
| 17
| 3,064
| 183
|
N,K = map(int,input().split())
num = [0]*N
tmp = input().split()
for i in range(N):
num[i] = int(tmp[i])
num.sort(reverse=True)
sum = 0
for j in range(K):
sum += num[j]
print(sum)
|
s127455135
|
p03415
|
u503228842
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 73
|
We have a 3×3 square grid, where each square contains a lowercase English letters. The letter in the square at the i-th row from the top and j-th column from the left is c_{ij}. Print the string of length 3 that can be obtained by concatenating the letters in the squares on the diagonal connecting the top-left and bottom-right corner of the grid, from the top-left to bottom-right.
|
s1 = input()
s2 = input()
s3 = input()
ans = s1[0]+s1[1]+s2[2]
print(ans)
|
s988892774
|
Accepted
| 17
| 2,940
| 73
|
s1 = input()
s2 = input()
s3 = input()
ans = s1[0]+s2[1]+s3[2]
print(ans)
|
s430465637
|
p03844
|
u757030836
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 30
|
Joisino wants to evaluate the formula "A op B". Here, A and B are integers, and the binary operator op is either `+` or `-`. Your task is to evaluate the formula instead of her.
|
print(input().replace(" ",""))
|
s627664446
|
Accepted
| 18
| 2,940
| 20
|
print(eval(input()))
|
s868570392
|
p02742
|
u098679988
| 2,000
| 1,048,576
|
Wrong Answer
| 18
| 2,940
| 145
|
We have a board with H horizontal rows and W vertical columns of squares. There is a bishop at the top-left square on this board. How many squares can this bishop reach by zero or more movements? Here the bishop can only move diagonally. More formally, the bishop can move from the square at the r_1-th row (from the top) and the c_1-th column (from the left) to the square at the r_2-th row and the c_2-th column if and only if exactly one of the following holds: * r_1 + c_1 = r_2 + c_2 * r_1 - c_1 = r_2 - c_2 For example, in the following figure, the bishop can move to any of the red squares in one move:
|
x = list( map(int, input().split()) )
h = x[0]
w = x[1]
menseki = h*w/2
if h*w % 2 == 0:
print(int(menseki+1))
else:
print(int(menseki))
|
s203608882
|
Accepted
| 18
| 3,060
| 205
|
import sys
x = list( map(int, input().split()) )
h = x[0]
w = x[1]
if h == 1 or w == 1:
print(1)
sys.exit()
menseki = h*w//2
if h*w % 2 == 0:
print(menseki)
else:
print(int(menseki)+1)
|
s713193269
|
p03494
|
u878384274
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 141
|
There are N positive integers written on a blackboard: A_1, ..., A_N. Snuke can perform the following operation when all integers on the blackboard are even: * Replace each integer X on the blackboard by X divided by 2. Find the maximum possible number of operations that Snuke can perform.
|
N=int(input())
A_list = [int(A_i) for A_i in input().split()]
b = min(A_list)
counter=0
while b%2 ==0:
b /= 2
counter+=1
print(counter)
|
s653091305
|
Accepted
| 19
| 3,064
| 200
|
def function(b):
counter=0
while b%2 ==0:
b /= 2
counter+=1
return counter
N=int(input())
A_list = [int(A_i) for A_i in input().split()]
B_list = min(map(function,A_list))
print(B_list)
|
s852273623
|
p03195
|
u026788530
| 2,000
| 1,048,576
|
Wrong Answer
| 220
| 3,060
| 131
|
There is an apple tree that bears apples of N colors. The N colors of these apples are numbered 1 to N, and there are a_i apples of Color i. You and Lunlun the dachshund alternately perform the following operation (starting from you): * Choose one or more apples from the tree and eat them. Here, the apples chosen at the same time must all have different colors. The one who eats the last apple from the tree will be declared winner. If both you and Lunlun play optimally, which will win?
|
N=int(input())
c= True
for i in range(N):
if int(input()) % 2 ==0:
c =not(c)
if(c):
print("first")
else:
print("second")
|
s019489174
|
Accepted
| 189
| 3,060
| 144
|
N= int(input())
c= True
for i in range(N):
if int(input()) % 2 == 1:
c = False
if c:
print("second")
else:
print("first")
|
s949642427
|
p03795
|
u581603131
| 2,000
| 262,144
|
Wrong Answer
| 17
| 3,064
| 65
|
Snuke has a favorite restaurant. The price of any meal served at the restaurant is 800 yen (the currency of Japan), and each time a customer orders 15 meals, the restaurant pays 200 yen back to the customer. So far, Snuke has ordered N meals at the restaurant. Let the amount of money Snuke has paid to the restaurant be x yen, and let the amount of money the restaurant has paid back to Snuke be y yen. Find x-y.
|
N = int(input())
import math
print(800*N - 200*(math.ceil(N/15)))
|
s229755287
|
Accepted
| 18
| 2,940
| 43
|
N = int(input())
print(800*N - 200*(N//15))
|
s112578483
|
p03351
|
u556225812
| 2,000
| 1,048,576
|
Wrong Answer
| 20
| 3,060
| 156
|
Three people, A, B and C, are trying to communicate using transceivers. They are standing along a number line, and the coordinates of A, B and C are a, b and c (in meters), respectively. Two people can directly communicate when the distance between them is at most d meters. Determine if A and C can communicate, either directly or indirectly. Here, A and C can indirectly communicate when A and B can directly communicate and also B and C can directly communicate.
|
a, b, c, d = map(int, input().split())
if abs(a-c) <= d:
print('Yes')
else:
if abs(a-b) <= d and abs(a-c) <= d:
print('Yes')
else:
print('No')
|
s133348338
|
Accepted
| 18
| 2,940
| 157
|
a, b, c, d = map(int, input().split())
if abs(a-c) <= d:
print('Yes')
else:
if abs(a-b) <= d and abs(b-c) <= d:
print('Yes')
else:
print('No')
|
s749249875
|
p02256
|
u428229577
| 1,000
| 131,072
|
Wrong Answer
| 30
| 7,664
| 138
|
Write a program which finds the greatest common divisor of two natural numbers _a_ and _b_
|
natural = list(map(int, input().split()))
natural.sort
x = natural[1]
y = natural[0]
while (y != 0):
x, y = y, x % y
print(x,y)
print(x)
|
s028364639
|
Accepted
| 20
| 7,628
| 126
|
natural = list(map(int, input().split()))
natural.sort
x = natural[1]
y = natural[0]
while (y != 0):
x, y = y, x % y
print(x)
|
s145373547
|
p03796
|
u655975843
| 2,000
| 262,144
|
Wrong Answer
| 34
| 2,940
| 103
|
Snuke loves working out. He is now exercising N times. Before he starts exercising, his _power_ is 1. After he exercises for the i-th time, his power gets multiplied by i. Find Snuke's power after he exercises N times. Since the answer can be extremely large, print the answer modulo 10^{9}+7.
|
n = int(input())
mod = 10 ** 9 + 7
ans = 0
for i in range(1, n + 1):
ans *= i
ans %= mod
print(ans)
|
s525725198
|
Accepted
| 41
| 2,940
| 103
|
n = int(input())
mod = 10 ** 9 + 7
ans = 1
for i in range(1, n + 1):
ans *= i
ans %= mod
print(ans)
|
s650888891
|
p03351
|
u603234915
| 2,000
| 1,048,576
|
Wrong Answer
| 174
| 13,480
| 220
|
Three people, A, B and C, are trying to communicate using transceivers. They are standing along a number line, and the coordinates of A, B and C are a, b and c (in meters), respectively. Two people can directly communicate when the distance between them is at most d meters. Determine if A and C can communicate, either directly or indirectly. Here, A and C can indirectly communicate when A and B can directly communicate and also B and C can directly communicate.
|
import numpy as np
a,b,c,d = (int(i) for i in input().split())
if np.abs(a - c) < d:
print('YES')
elif a < b < c and c-a < 2*d:
print('YES')
elif c < b < a and a-c < 2*d:
print('YES')
else :
print('NO')
|
s666369785
|
Accepted
| 150
| 12,500
| 225
|
import numpy as np
a,b,c,d = (int(i) for i in input().split())
if np.abs(a - c) <= d:
print('Yes')
elif a <= b <= c and c-a < 2*d:
print('Yes')
elif c <= b <= a and a-c < 2*d:
print('Yes')
else :
print('No')
|
s851655119
|
p03050
|
u663230781
| 2,000
| 1,048,576
|
Wrong Answer
| 2,104
| 2,940
| 182
|
Snuke received a positive integer N from Takahashi. A positive integer m is called a _favorite number_ when the following condition is satisfied: * The quotient and remainder of N divided by m are equal, that is, \lfloor \frac{N}{m} \rfloor = N \bmod m holds. Find all favorite numbers and print the sum of those.
|
n = int(input().rstrip())
total = 0
for number in range(2, n):
remain = n - number
x, y = divmod(remain, number)
if y == 0 and x > number:
total += x
print(total)
|
s391318159
|
Accepted
| 112
| 3,068
| 494
|
from math import sqrt
def main():
n = int(input().rstrip())
sqrt_n = int(sqrt(n))
total = 0
for number in range(1,sqrt_n + 1):
if n % number > 0:
continue
remain = n - number
x, y = divmod(remain, number)
#print(x, y, remain, number)
if y == 0 and x > number:
total += x
print(total)
if __name__ == "__main__":
main()
|
s765135399
|
p03471
|
u557282438
| 2,000
| 262,144
|
Wrong Answer
| 2,104
| 2,940
| 250
|
The commonly used bills in Japan are 10000-yen, 5000-yen and 1000-yen bills. Below, the word "bill" refers to only these. According to Aohashi, he received an otoshidama (New Year money gift) envelope from his grandfather that contained N bills for a total of Y yen, but he may be lying. Determine whether such a situation is possible, and if it is, find a possible set of bills contained in the envelope. Assume that his grandfather is rich enough, and the envelope was large enough.
|
n,y = map(int,input().split())
res = [-1,-1,-1]
for i in range(n):
for j in range(n-i):
for k in range(n-i-j):
if(10000*i + 5000*j + 1000*k == y):
res = [i,j,k]
break
print(res)
|
s972344502
|
Accepted
| 708
| 3,060
| 222
|
n,y = map(int,input().split())
res = [-1,-1,-1]
for i in range(n+1):
for j in range(n-i+1):
if(10000*i + 5000*j + 1000*(n-i-j) == y):
res = [i,j,n-i-j]
break
print(*res)
|
s901225476
|
p03829
|
u103902792
| 2,000
| 262,144
|
Wrong Answer
| 98
| 14,252
| 170
|
There are N towns on a line running east-west. The towns are numbered 1 through N, in order from west to east. Each point on the line has a one- dimensional coordinate, and a point that is farther east has a greater coordinate value. The coordinate of town i is X_i. You are now at town 1, and you want to visit all the other towns. You have two ways to travel: * Walk on the line. Your _fatigue level_ increases by A each time you travel a distance of 1, regardless of direction. * Teleport to any location of your choice. Your fatigue level increases by B, regardless of the distance covered. Find the minimum possible total increase of your fatigue level when you visit all the towns in these two ways.
|
n,a,b = map(int,input().split())
towns = list(map(int,input().split()))
fatigue = 0
for i in range(n-1):
d = towns[i+1] -towns[i]
fatigue = max(d*a,b)
print(fatigue)
|
s581321193
|
Accepted
| 100
| 14,252
| 173
|
n,a,b = map(int,input().split())
towns = list(map(int,input().split()))
fatigue = 0
for i in range(n-1):
d = towns[i+1] -towns[i]
fatigue += min(d*a,b)
print(fatigue)
|
s782582450
|
p02606
|
u211496288
| 2,000
| 1,048,576
|
Wrong Answer
| 24
| 9,012
| 122
|
How many multiples of d are there among the integers between L and R (inclusive)?
|
L, R, d = map(int, input().split())
count = 0
for i in range(L, R + 1):
if i // d == 0:
count += 1
print(count)
|
s270657933
|
Accepted
| 31
| 9,096
| 121
|
L, R, d = map(int, input().split())
count = 0
for i in range(L, R + 1):
if i % d == 0:
count += 1
print(count)
|
s731481848
|
p03152
|
u017810624
| 2,000
| 1,048,576
|
Wrong Answer
| 17
| 3,188
| 170
|
Consider writing each of the integers from 1 to N \times M in a grid with N rows and M columns, without duplicates. Takahashi thinks it is not fun enough, and he will write the numbers under the following conditions: * The largest among the values in the i-th row (1 \leq i \leq N) is A_i. * The largest among the values in the j-th column (1 \leq j \leq M) is B_j. For him, find the number of ways to write the numbers under these conditions, modulo 10^9 + 7.
|
n,m=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
if len(set(a))!=len(a) or len(set(b))!=len(b):
print(0)
else:
print(-1)
|
s270597541
|
Accepted
| 603
| 3,316
| 208
|
s,a,b=[set(map(int,input().split()))for j in[0]*3];c=1;N=M=0;x=max(a)
for k in range(x,0,-1):
A=k in a;B=k in b
if A and B:M+=1;N+=1
elif A:c*=M;N+=1
elif B:c*=N;M+=1
else:c*=M*N-x+k
c%=10**9+7
print(c)
|
s757149390
|
p03524
|
u706414019
| 2,000
| 262,144
|
Wrong Answer
| 35
| 9,392
| 129
|
Snuke has a string S consisting of three kinds of letters: `a`, `b` and `c`. He has a phobia for palindromes, and wants to permute the characters in S so that S will not contain a palindrome of length 2 or more as a substring. Determine whether this is possible.
|
import collections
A = input()
Ac = collections.Counter(A)
maxA = max(Ac.values())
print('Yes' if maxA<=(len(A)+2)/3 else 'No')
|
s128149562
|
Accepted
| 37
| 9,384
| 129
|
import collections
A = input()
Ac = collections.Counter(A)
maxA = max(Ac.values())
print('YES' if maxA<=(len(A)+2)/3 else 'NO')
|
s540092700
|
p02267
|
u822165491
| 1,000
| 131,072
|
Wrong Answer
| 20
| 5,596
| 178
|
You are given a sequence of _n_ integers S and a sequence of different _q_ integers T. Write a program which outputs C, the number of integers in T which are also in the set S.
|
def main():
n = int(input())
S = [int(i) for i in input().split()]
q = int(input())
T = [int(i) for i in input().split()]
return len(set(S) & set(T))
main()
|
s722518376
|
Accepted
| 20
| 6,504
| 178
|
def main():
n = int(input())
S = [int(i) for i in input().split()]
q = int(input())
T = [int(i) for i in input().split()]
print(len(set(S) & set(T)))
main()
|
s172720717
|
p03759
|
u089376182
| 2,000
| 262,144
|
Wrong Answer
| 17
| 3,064
| 72
|
Three poles stand evenly spaced along a line. Their heights are a, b and c meters, from left to right. We will call the arrangement of the poles _beautiful_ if the tops of the poles lie on the same line, that is, b-a = c-b. Determine whether the arrangement of the poles is beautiful.
|
a, b, c = map(int, input().split())
print('Yes' if b-a == c-b else 'No')
|
s339335469
|
Accepted
| 17
| 2,940
| 72
|
a, b, c = map(int, input().split())
print('YES' if b-a == c-b else 'NO')
|
s950735520
|
p03997
|
u546573715
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 69
|
You are given a trapezoid. The lengths of its upper base, lower base, and height are a, b, and h, respectively. An example of a trapezoid Find the area of this trapezoid.
|
a = int(input())
b = int(input())
h = int (input())
print((a+b)*h/2)
|
s121399181
|
Accepted
| 18
| 2,940
| 74
|
a = int(input())
b = int(input())
h = int (input())
print(int((a+b)*h/2))
|
s912526547
|
p03150
|
u993642190
| 2,000
| 1,048,576
|
Wrong Answer
| 18
| 3,064
| 180
|
A string is called a KEYENCE string when it can be changed to `keyence` by removing its contiguous substring (possibly empty) only once. Given a string S consisting of lowercase English letters, determine if S is a KEYENCE string.
|
def main() :
S = input()
remove_len = len(S) - 7
for i in range(len(S) - remove_len) :
s = S[i:i+7]
if (s == "keyence") :
print("YES")
return
print("NO")
main()
|
s578888770
|
Accepted
| 17
| 2,940
| 214
|
def main() :
S = input()
remove_len = len(S) - 7
for i in range(len(S) - remove_len) :
s = S[0:i] + S[i+remove_len:]
if (s == "keyence") :
print("YES")
return
print("NO")
main()
|
s984899537
|
p03693
|
u401487574
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 89
|
AtCoDeer has three cards, one red, one green and one blue. An integer between 1 and 9 (inclusive) is written on each card: r on the red card, g on the green card and b on the blue card. We will arrange the cards in the order red, green and blue from left to right, and read them as a three-digit integer. Is this integer a multiple of 4?
|
r,g,b = map(int,input().split())
if g*10+b %4==0:
print("YES")
else:
print("NO")
|
s878739242
|
Accepted
| 17
| 2,940
| 91
|
r,g,b = map(int,input().split())
if (g*10+b )%4==0:
print("YES")
else:
print("NO")
|
s629523209
|
p02612
|
u457901067
| 2,000
| 1,048,576
|
Wrong Answer
| 31
| 9,152
| 24
|
We will buy a product for N yen (the currency of Japan) at a shop. If we use only 1000-yen bills to pay the price, how much change will we receive? Assume we use the minimum number of bills required.
|
print(int(input())%1000)
|
s037243950
|
Accepted
| 29
| 8,892
| 47
|
N = int(input())
print((1000 - N%1000) % 1000)
|
s839464185
|
p03089
|
u934442292
| 2,000
| 1,048,576
|
Wrong Answer
| 2,104
| 3,064
| 586
|
Snuke has an empty sequence a. He will perform N operations on this sequence. In the i-th operation, he chooses an integer j satisfying 1 \leq j \leq i, and insert j at position j in a (the beginning is position 1). You are given a sequence b of length N. Determine if it is possible that a is equal to b after N operations. If it is, show one possible sequence of operations that achieves it.
|
import sys
input = sys.stdin.readline # NOQA
sys.setrecursionlimit(10 ** 7) # NOQA
def dfs(N, a, i, b):
if i == N + 1:
if a == b:
return a
else:
return None
i += 1
for j in range(1, i):
A = a[:]
A.insert(j-1, j)
res = dfs(N, A, i, b)
if res is not None:
return res
def main():
N = int(input())
b = list(map(int, input().split()))
res = dfs(N, [], 1, b)
if res is None:
print(-1)
else:
print(*res, sep="\n")
if __name__ == "__main__":
main()
|
s408810048
|
Accepted
| 29
| 9,160
| 530
|
import sys
input = sys.stdin.readline
def main():
N = int(input())
B = list(map(int, input().split()))
is_ok = True
for i, b in enumerate(B, 1):
if i < b:
is_ok = False
if not is_ok:
print(-1)
exit()
ans = []
for _ in range(N):
for i in reversed(range(len(B))):
if B[i] == i + 1:
break
ans.append(B[i])
del B[i]
ans = ans[::-1]
print("\n".join(map(str, ans)))
if __name__ == "__main__":
main()
|
s195670570
|
p03479
|
u047816928
| 2,000
| 262,144
|
Wrong Answer
| 18
| 2,940
| 77
|
As a token of his gratitude, Takahashi has decided to give his mother an integer sequence. The sequence A needs to satisfy the conditions below: * A consists of integers between X and Y (inclusive). * For each 1\leq i \leq |A|-1, A_{i+1} is a multiple of A_i and strictly greater than A_i. Find the maximum possible length of the sequence.
|
A, Y = map(int, input().split())
ans = 0
while A<=Y:
ans+=1
A*=2
print(A)
|
s300361820
|
Accepted
| 17
| 2,940
| 79
|
A, Y = map(int, input().split())
ans = 0
while A<=Y:
ans+=1
A*=2
print(ans)
|
s434728862
|
p02388
|
u623827446
| 1,000
| 131,072
|
Wrong Answer
| 30
| 7,392
| 20
|
Write a program which calculates the cube of a given integer x.
|
x=input()
print(x*3)
|
s292851149
|
Accepted
| 20
| 7,516
| 28
|
x = int(input())
print(x**3)
|
s574881251
|
p03737
|
u163892325
| 2,000
| 262,144
|
Wrong Answer
| 17
| 3,060
| 131
|
You are given three words s_1, s_2 and s_3, each composed of lowercase English letters, with spaces in between. Print the acronym formed from the uppercased initial letters of the words.
|
a = input()
b1 = list(a[0])
b2 = list(a[1])
b3 = list(a[2])
p1 = b1[0]
p2 = b2[0]
p3 = b3[0]
k =""
k += p1 +p2 +p3
print(k.upper())
|
s265297016
|
Accepted
| 18
| 3,060
| 139
|
a = input().split()
b1 = list(a[0])
b2 = list(a[1])
b3 = list(a[2])
p1 = b1[0]
p2 = b2[0]
p3 = b3[0]
k =""
k += p1 +p2 +p3
print(k.upper())
|
s219352406
|
p03162
|
u407784088
| 2,000
| 1,048,576
|
Wrong Answer
| 824
| 31,400
| 397
|
Taro's summer vacation starts tomorrow, and he has decided to make plans for it now. The vacation consists of N days. For each i (1 \leq i \leq N), Taro will choose one of the following activities and do it on the i-th day: * A: Swim in the sea. Gain a_i points of happiness. * B: Catch bugs in the mountains. Gain b_i points of happiness. * C: Do homework at home. Gain c_i points of happiness. As Taro gets bored easily, he cannot do the same activities for two or more consecutive days. Find the maximum possible total points of happiness that Taro gains.
|
import numpy as np
N = int(input())
a = np.zeros((N,3))
for i in range(N):
a[i][0],a[i][1],a[i][2] = map(int,input().split())
memo = np.zeros((N,3))
memo[0][0], memo[0][1], memo[0][2] = a[0][0],a[0][1],a[0][2]
day = 1
while (day < N):
memo[day] = [max(memo[day-1][(x+1)%3],memo[day-1][(x+2)%3]) + a[day][x] \
for x in [0,1,2]]
day += 1
print(max(memo[day - 1]))
|
s438500070
|
Accepted
| 780
| 31,156
| 402
|
import numpy as np
N = int(input())
a = np.zeros((N,3))
for i in range(N):
a[i][0],a[i][1],a[i][2] = map(int,input().split())
memo = np.zeros((N,3))
memo[0][0], memo[0][1], memo[0][2] = a[0][0],a[0][1],a[0][2]
day = 1
while (day < N):
memo[day] = [max(memo[day-1][(x+1)%3],memo[day-1][(x+2)%3]) + a[day][x] \
for x in [0,1,2]]
day += 1
print(int(max(memo[day - 1])))
|
s906713296
|
p02402
|
u253463900
| 1,000
| 131,072
|
Wrong Answer
| 30
| 7,560
| 75
|
Write a program which reads a sequence of $n$ integers $a_i (i = 1, 2, ... n)$, and prints the minimum value, maximum value and sum of the sequence.
|
input()
d = [int(x) for x in input().split()]
print(max(d), min(d), sum(d))
|
s978707564
|
Accepted
| 20
| 8,648
| 75
|
input()
d = [int(x) for x in input().split()]
print(min(d), max(d), sum(d))
|
s021069704
|
p03377
|
u760831084
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 77
|
There are a total of A + B cats and dogs. Among them, A are known to be cats, but the remaining B are not known to be either cats or dogs. Determine if it is possible that there are exactly X cats among these A + B animals.
|
a, b, x = map(int, input().split())
print('Yes' if a <= x <= a + b else 'No')
|
s928433828
|
Accepted
| 16
| 2,940
| 77
|
a, b, x = map(int, input().split())
print('YES' if a <= x <= a + b else 'NO')
|
s652431569
|
p03477
|
u761320129
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 131
|
A balance scale tips to the left if L>R, where L is the total weight of the masses on the left pan and R is the total weight of the masses on the right pan. Similarly, it balances if L=R, and tips to the right if L<R. Takahashi placed a mass of weight A and a mass of weight B on the left pan of a balance scale, and placed a mass of weight C and a mass of weight D on the right pan. Print `Left` if the balance scale tips to the left; print `Balanced` if it balances; print `Right` if it tips to the right.
|
A,B,C,D = map(int,input().split())
if A+B < C+D:
print('Left')
elif A+B == C+D:
print('Balanced')
else:
print('Right')
|
s955628086
|
Accepted
| 16
| 2,940
| 119
|
a,b,c,d = map(int,input().split())
if a+b>c+d:
print('Left')
elif a+b<c+d:
print('Right')
else:
print('Balanced')
|
s715949544
|
p02608
|
u950825280
| 2,000
| 1,048,576
|
Time Limit Exceeded
| 2,206
| 8,956
| 634
|
Let f(n) be the number of triples of integers (x,y,z) that satisfy both of the following conditions: * 1 \leq x,y,z * x^2 + y^2 + z^2 + xy + yz + zx = n Given an integer N, find each of f(1),f(2),f(3),\ldots,f(N).
|
N = int(input())
def f(a, b, c):
return a**2 + b**2 + c**2 + a*b + b*c + c*a
for i in range(1, N+1):
if i < 6:
print(0)
else:
x, y, z = 0, 0, 0
ans = 0
while True:
x += 1
y = 0
z = 0
if f(x,y,z) > i:
break
while True:
y += 1
z = 1
s = f(x,y,z)
if s > i:
break
while s <= i:
if s == i:
ans += 1
break
z += 1
print(ans)
|
s026115925
|
Accepted
| 845
| 9,112
| 301
|
N = int(input())
def f(a, b, c):
return a**2 + b**2 + c**2 + a*b + b*c + c*a
ans = [0] * N
for x in range(1, 101):
for y in range(1, 101):
for z in range(1, 101):
n = f(x,y,z)
if n <= N:
ans[n-1] += 1
for a in ans:
print(a)
|
s930995718
|
p03997
|
u799164835
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 75
|
You are given a trapezoid. The lengths of its upper base, lower base, and height are a, b, and h, respectively. An example of a trapezoid Find the area of this trapezoid.
|
a = int(input())
b = int(input())
h = int(input())
print(str((a + b)*h/2))
|
s393189159
|
Accepted
| 18
| 3,060
| 563
|
GBN_DEBUG = False
def dprn(s, i):
if GBN_DEBUG: print(", " + s + " = " + str(i), end = "")
def dprns(s):
if GBN_DEBUG: print(", " + s, end = "")
def dprni(i):
if GBN_DEBUG: print(i, end=" ")
def endl():
if GBN_DEBUG: print('')
def puts(s): print(s)
#S = input()
#N = int(input())
#S, T = input().split()
#a, b, h = map(int, input().split())
#W = [input() for _ in range(N)]
#A = list(map(int, input().split()))
#GBN_DEBUG = True
a = int(input())
b = int(input())
h = int(input())
print((a + b) * h // 2)
|
s856636034
|
p04043
|
u389188163
| 2,000
| 262,144
|
Wrong Answer
| 26
| 9,020
| 123
|
Iroha loves _Haiku_. Haiku is a short form of Japanese poetry. A Haiku consists of three phrases with 5, 7 and 5 syllables, in this order. To create a Haiku, Iroha has come up with three different phrases. These phrases have A, B and C syllables, respectively. Determine whether she can construct a Haiku by using each of the phrases once, in some order.
|
A, B, C = list(map(int, input().split()))
s = A, B, C
print('Yes') if s.count(5) == 2 and s.count(7) == 1 else print('No')
|
s110509079
|
Accepted
| 26
| 9,124
| 117
|
A, B, C = map(int, input().split())
s = A, B, C
print('YES') if s.count(5) == 2 and s.count(7) == 1 else print('NO')
|
s037987226
|
p03418
|
u952708174
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 605
|
Takahashi had a pair of two positive integers not exceeding N, (a,b), which he has forgotten. He remembers that the remainder of a divided by b was greater than or equal to K. Find the number of possible pairs that he may have had.
|
def d_remainder_reminder(N, K):
ans = 0
for b in range(K + 1, N + 1):
p = N // b
r = N % b
ans += p * max(0, b - K) + max(0, r + 1 - K)
if K == 0:
ans -= N
return ans
|
s669884052
|
Accepted
| 82
| 3,060
| 680
|
def d_remainder_reminder(N, K):
ans = 0
for b in range(K + 1, N + 1):
p = N // b
r = N % b
ans += p * max(0, b - K) + max(0, r + 1 - K)
if K == 0:
ans -= N
return ans
N,K = [int(i) for i in input().split()]
print(d_remainder_reminder(N, K))
|
s430141259
|
p02612
|
u938785734
| 2,000
| 1,048,576
|
Wrong Answer
| 31
| 9,140
| 28
|
We will buy a product for N yen (the currency of Japan) at a shop. If we use only 1000-yen bills to pay the price, how much change will we receive? Assume we use the minimum number of bills required.
|
n=int(input())
print(1000-n)
|
s204835127
|
Accepted
| 31
| 9,152
| 61
|
n=int(input())
sen=1000
while sen<n:
sen+=1000
print(sen-n)
|
s046576528
|
p03696
|
u977193988
| 2,000
| 262,144
|
Wrong Answer
| 18
| 3,060
| 512
|
You are given a string S of length N consisting of `(` and `)`. Your task is to insert some number of `(` and `)` into S to obtain a _correct bracket sequence_. Here, a correct bracket sequence is defined as follows: * `()` is a correct bracket sequence. * If X is a correct bracket sequence, the concatenation of `(`, X and `)` in this order is also a correct bracket sequence. * If X and Y are correct bracket sequences, the concatenation of X and Y in this order is also a correct bracket sequence. * Every correct bracket sequence can be derived from the rules above. Find the shortest correct bracket sequence that can be obtained. If there is more than one such sequence, find the lexicographically smallest one.
|
import sys
def input():
return sys.stdin.readline().strip()
sys.setrecursionlimit(10 ** 9)
def main():
N = int(input())
S = list(input())
answer = ""
cnt = 0
for s in S:
if s == "(":
cnt += 1
answer += "("
else:
if cnt > 0:
answer += ")"
cnt -= 1
else:
answer += "()"
if cnt > 0:
answer += ")" * cnt
print(answer)
if __name__ == "__main__":
main()
|
s087761500
|
Accepted
| 18
| 3,064
| 734
|
import sys
def input():
return sys.stdin.readline().strip()
sys.setrecursionlimit(10 ** 9)
def main():
N = int(input())
S = list(input())
answer = ""
right = 0
left = 0
for s in S:
if s == "(":
if right > 0:
answer = "(" * right + answer
answer += ")" * right
right = 0
left += 1
answer += "("
else:
if left > 0:
answer += ")"
left -= 1
else:
right += 1
if left > 0:
answer += ")" * left
if right > 0:
answer = "(" * right + answer + ")" * right
print(answer)
if __name__ == "__main__":
main()
|
s355569135
|
p02850
|
u979684411
| 2,000
| 1,048,576
|
Wrong Answer
| 2,105
| 42,460
| 771
|
Given is a tree G with N vertices. The vertices are numbered 1 through N, and the i-th edge connects Vertex a_i and Vertex b_i. Consider painting the edges in G with some number of colors. We want to paint them so that, for each vertex, the colors of the edges incident to that vertex are all different. Among the colorings satisfying the condition above, construct one that uses the minimum number of colors.
|
N = int(input())
palette = [1]
colors = [None] * N
edges = [None] * N
ends = {}
for i in range(1,N):
edges[i] = [int(n) for n in input().split()]
for i in range(1,N):
a, b = edges[i]
if a not in ends:
ends[a] = [i]
else:
ends[a].append(i)
if b not in ends:
ends[b] = [i]
else:
ends[b].append(i)
for i in range(1,N):
p = palette[:]
for j in ends[i]:
if colors[j]:
p = [color for color in p if color != colors[j]]
else:
if len(p) > 0:
colors[j] = p[0]
del p[0]
else:
color = len(palette) + 1
palette.append(color)
colors[j] = color
for i in range(1,N):
print(colors[i])
|
s954188595
|
Accepted
| 857
| 99,764
| 1,298
|
import sys
sys.setrecursionlimit(100000)
N = int(input())
palette = 1
colors = {}
ends = {}
edges = {}
for edge in range(1,N):
ends[edge] = [int(n) for n in input().split()]
a, b = ends[edge]
if a not in edges:
edges[a] = [edge]
else:
edges[a].append(edge)
if b not in edges:
edges[b] = [edge]
else:
edges[b].append(edge)
def color_edges(parent, root):
ng = {}
global palette
if parent > 0:
ng[colors[parent]] = True
for edge in edges[root]:
if edge in colors:
color = colors[edge]
elif palette - len(ng) > 0:
color = 1
while color in ng:
color += 1
colors[edge] = color
else:
palette += 1
color = palette
colors[edge] = color
ng[color] = True
for edge in edges[root]:
if edge == parent:
continue
a, b = ends[edge]
if a == root:
color_edges(edge, b)
else:
color_edges(edge, a)
max_edges = 1
root = 1
for node in range(1,N+1):
if len(edges[node]) > max_edges:
max_edges = len(edges[node])
root = node
color_edges(0, root)
print(palette)
for edge in range(1,N):
print(colors[edge])
|
s189279999
|
p03729
|
u363610900
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 139
|
You are given three strings A, B and C. Check whether they form a _word chain_. More formally, determine whether both of the following are true: * The last character in A and the initial character in B are the same. * The last character in B and the initial character in C are the same. If both are true, print `YES`. Otherwise, print `NO`.
|
def func():
A, B, C = input().split()
result = 'Yes' if A[-1] == B[0] and B[-1] == C[0] else 'No'
return result
print(func())
|
s179898178
|
Accepted
| 18
| 2,940
| 83
|
A, B, C = input().split()
print('YES' if A[-1] == B[0] and B[-1] == C[0] else 'NO')
|
s434583771
|
p03814
|
u344959959
| 2,000
| 262,144
|
Wrong Answer
| 39
| 9,132
| 202
|
Snuke has decided to construct a string that starts with `A` and ends with `Z`, by taking out a substring of a string s (that is, a consecutive part of s). Find the greatest length of the string Snuke can construct. Here, the test set guarantees that there always exists a substring of s that starts with `A` and ends with `Z`.
|
a = input()
for i in range(len(a)):
if a[i] == "A":
b = i
print(b)
break
for j in range(len(a)):
if a[j] == "Z":
c = j
print(c)
break
print(c-b+1)
|
s086510311
|
Accepted
| 46
| 9,176
| 155
|
a = input()
for i in range(len(a)):
if a[i] == "A":
b = i
break
for j in range(len(a)):
if a[j] == "Z":
c = j
print(c-b+1)
|
s234474083
|
p03379
|
u947823593
| 2,000
| 262,144
|
Wrong Answer
| 215
| 25,556
| 334
|
When l is an odd number, the median of l numbers a_1, a_2, ..., a_l is the (\frac{l+1}{2})-th largest value among a_1, a_2, ..., a_l. You are given N numbers X_1, X_2, ..., X_N, where N is an even number. For each i = 1, 2, ..., N, let the median of X_1, X_2, ..., X_N excluding X_i, that is, the median of X_1, X_2, ..., X_{i-1}, X_{i+1}, ..., X_N be B_i. Find B_i for each i = 1, 2, ..., N.
|
def solve(N, A):
c = int(N / 2)
left = A[c - 1]
right = A[c]
for x in range(c - 1):
print(left)
print(right)
print(left)
for x in range(c + 1, N):
print(right)
if __name__ == "__main__":
N = int(input())
A = list(map(lambda x: int(x), input().split()))
solve(N, A)
|
s492003249
|
Accepted
| 387
| 26,772
| 431
|
def solve(N, A):
c = int(N / 2)
left = sorted(A)[c - 1]
right = sorted(A)[c]
if left == right:
for x in range(N):
print(left)
return;
for x in range(N):
if A[x] <= left:
print(right)
if A[x] >= right:
print(left)
if __name__ == "__main__":
N = int(input())
A = list(map(lambda x: int(x), input().split()))
solve(N, A)
|
s353007844
|
p04045
|
u887207211
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 162
|
Iroha is very particular about numbers. There are K digits that she dislikes: D_1, D_2, ..., D_K. She is shopping, and now paying at the cashier. Her total is N yen (the currency of Japan), thus she has to hand at least N yen to the cashier (and possibly receive the change). However, as mentioned before, she is very particular about numbers. When she hands money to the cashier, the decimal notation of the amount must not contain any digits that she dislikes. Under this condition, she will hand the minimum amount of money. Find the amount of money that she will hand to the cashier.
|
N, K = map(int,input().split())
D = list(map(int,input().split()))
while True:
for n in str(N):
if(n in D):
break
else:
break
N += 1
print(N)
|
s578816511
|
Accepted
| 51
| 2,940
| 147
|
N, K = map(int,input().split())
D = input().split()
while True:
for n in str(N):
if(n in D):
break
else:
break
N += 1
print(N)
|
s936970447
|
p03611
|
u220345792
| 2,000
| 262,144
|
Wrong Answer
| 2,104
| 13,964
| 212
|
You are given an integer sequence of length N, a_1,a_2,...,a_N. For each 1≤i≤N, you have three choices: add 1 to a_i, subtract 1 from a_i or do nothing. After these operations, you select an integer X and count the number of i such that a_i=X. Maximize this count by making optimal choices.
|
N = int(input())
A = list(map(int, input().split()))
all_data = list(set(A))
num = 0
for i in all_data:
tmp = all_data.count(i) + all_data.count(i+1) + all_data.count(i-1)
num = max(num, tmp)
print(num)
|
s297214217
|
Accepted
| 79
| 13,964
| 155
|
N = int(input())
A = list(map(int, input().split()))
ans = [0]*(100000+2)
for i in A:
ans[i-1] += 1
ans[i] += 1
ans[i+1] += 1
print(max(ans))
|
s969723206
|
p03637
|
u898058223
| 2,000
| 262,144
|
Wrong Answer
| 78
| 14,228
| 297
|
We have a sequence of length N, a = (a_1, a_2, ..., a_N). Each a_i is a positive integer. Snuke's objective is to permute the element in a so that the following condition is satisfied: * For each 1 ≤ i ≤ N - 1, the product of a_i and a_{i + 1} is a multiple of 4. Determine whether Snuke can achieve his objective.
|
n=int(input())
a=list(map(int,input().split()))
cnt_odd=0
cnt_even=0
cnt_4=0
for i in range(n):
if a[i]%2!=0:
cnt_odd+=1
else:
cnt_even+=1
if a[i]%4==0:
cnt_4+=1
if n%2!=1 and cnt_odd-1<=cnt_4:
print("Yes")
elif n%2==0 and cnt_odd<=cnt_4:
print("Yes")
else:
print("No")
|
s834287677
|
Accepted
| 76
| 14,252
| 337
|
n=int(input())
a=list(map(int,input().split()))
cnt_odd=0
cnt_even=0
cnt_4=0
for i in range(n):
if a[i]%2!=0:
cnt_odd+=1
else:
cnt_even+=1
if a[i]%4==0:
cnt_4+=1
if cnt_even-cnt_4==0:
if cnt_4+1>=cnt_odd:
print("Yes")
else:
print("No")
else:
if cnt_4>=cnt_odd:
print("Yes")
else:
print("No")
|
s808357698
|
p03447
|
u521866787
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 61
|
You went shopping to buy cakes and donuts with X yen (the currency of Japan). First, you bought one cake for A yen at a cake shop. Then, you bought as many donuts as possible for B yen each, at a donut shop. How much do you have left after shopping?
|
x,a,b = (int(input(i)) for i in range(3))
print((x-a) % b )
|
s694387044
|
Accepted
| 17
| 2,940
| 60
|
x,a,b = (int(input()) for i in range(3))
print((x-a) % b )
|
s146383350
|
p03568
|
u409064224
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 200
|
We will say that two integer sequences of length N, x_1, x_2, ..., x_N and y_1, y_2, ..., y_N, are _similar_ when |x_i - y_i| \leq 1 holds for all i (1 \leq i \leq N). In particular, any integer sequence is similar to itself. You are given an integer N and an integer sequence of length N, A_1, A_2, ..., A_N. How many integer sequences b_1, b_2, ..., b_N are there such that b_1, b_2, ..., b_N is similar to A and the product of all elements, b_1 b_2 ... b_N, is even?
|
n = int(input())
a = list(map(int,input().split()))
print(a)
o = 1
for i in range(len(a)):
if a[i]%2 == 1:
#odd
o *= 1
else:
#even
o *= 2
print(3**len(a)-o)
|
s455522978
|
Accepted
| 17
| 2,940
| 191
|
n = int(input())
a = list(map(int,input().split()))
o = 1
for i in range(len(a)):
if a[i]%2 == 1:
#odd
o *= 1
else:
#even
o *= 2
print(3**len(a)-o)
|
s478056846
|
p02831
|
u106181248
| 2,000
| 1,048,576
|
Wrong Answer
| 38
| 5,304
| 75
|
Takahashi is organizing a party. At the party, each guest will receive one or more snack pieces. Takahashi predicts that the number of guests at this party will be A or B. Find the minimum number of pieces that can be evenly distributed to the guests in both of the cases predicted. We assume that a piece cannot be divided and distributed to multiple guests.
|
from fractions import gcd
a,b = map(int,input().split())
print(gcd(a, b))
|
s485312557
|
Accepted
| 17
| 2,940
| 160
|
def gcd(a, b):
while b:
a, b = b, a % b
return a
def lcm(a, b):
return a * b // gcd (a, b)
a,b = map(int,input().split())
print(lcm(a, b))
|
s209803297
|
p03574
|
u268318377
| 2,000
| 262,144
|
Wrong Answer
| 29
| 3,188
| 358
|
You are given an H × W grid. The squares in the grid are described by H strings, S_1,...,S_H. The j-th character in the string S_i corresponds to the square at the i-th row from the top and j-th column from the left (1 \leq i \leq H,1 \leq j \leq W). `.` stands for an empty square, and `#` stands for a square containing a bomb. Dolphin is interested in how many bomb squares are horizontally, vertically or diagonally adjacent to each empty square. (Below, we will simply say "adjacent" for this meaning. For each square, there are at most eight adjacent squares.) He decides to replace each `.` in our H strings with a digit that represents the number of bomb squares adjacent to the corresponding empty square. Print the strings after the process.
|
H,W = map(int, input().split())
S = []
for _ in range(H):
S.append([s for s in input()])
for h in range(H):
for w in range(W):
if S[h][w] == ".":
a = 0
for x in [-1, 0, 1]:
for y in [-1, 0, 1]:
if 0 <= h+x < H and 0 <= w+y < W:
if S[h+x][w+y] == "#":
a += 1
S[h][w] = str(a)
print(S)
|
s658853057
|
Accepted
| 29
| 3,188
| 389
|
H,W = map(int, input().split())
S = []
for _ in range(H):
S.append([s for s in input()])
for h in range(H):
for w in range(W):
if S[h][w] == ".":
a = 0
for x in [-1, 0, 1]:
for y in [-1, 0, 1]:
if 0 <= h+x < H and 0 <= w+y < W:
if S[h+x][w+y] == "#":
a += 1
S[h][w] = str(a)
for _ in range(H):
print("".join(S[_]))
|
s626619088
|
p03477
|
u536717874
| 2,000
| 262,144
|
Wrong Answer
| 17
| 3,060
| 278
|
A balance scale tips to the left if L>R, where L is the total weight of the masses on the left pan and R is the total weight of the masses on the right pan. Similarly, it balances if L=R, and tips to the right if L<R. Takahashi placed a mass of weight A and a mass of weight B on the left pan of a balance scale, and placed a mass of weight C and a mass of weight D on the right pan. Print `Left` if the balance scale tips to the left; print `Balanced` if it balances; print `Right` if it tips to the right.
|
# coding: utf-8
import sys
def main(argv=sys.argv):
a, b, c, d = map(int, input().split(' '))
if a + b > c + d:
print('left')
elif a + b < c + d:
print('Right')
else:
print('Balanced')
return 0
if __name__ == '__main__':
sys.exit(main())
|
s471865720
|
Accepted
| 18
| 3,060
| 278
|
# coding: utf-8
import sys
def main(argv=sys.argv):
a, b, c, d = map(int, input().split(' '))
if a + b > c + d:
print('Left')
elif a + b < c + d:
print('Right')
else:
print('Balanced')
return 0
if __name__ == '__main__':
sys.exit(main())
|
s493371011
|
p03943
|
u016393440
| 2,000
| 262,144
|
Wrong Answer
| 19
| 3,060
| 125
|
Two students of AtCoder Kindergarten are fighting over candy packs. There are three candy packs, each of which contains a, b, and c candies, respectively. Teacher Evi is trying to distribute the packs between the two students so that each student gets the same number of candies. Determine whether it is possible. Note that Evi cannot take candies out of the packs, and the whole contents of each pack must be given to one of the students.
|
a = [int(i) for i in input().split()]
a.sort()
if int(a[0]) + int(a[1]) == int(a[2]):
print('YES')
else:
print('NO')
|
s753618084
|
Accepted
| 18
| 2,940
| 125
|
a = [int(i) for i in input().split()]
a.sort()
if int(a[0]) + int(a[1]) == int(a[2]):
print('Yes')
else:
print('No')
|
s376405799
|
p02286
|
u167493070
| 2,000
| 262,144
|
Wrong Answer
| 20
| 5,624
| 2,462
|
A binary search tree can be unbalanced depending on features of data. For example, if we insert $n$ elements into a binary search tree in ascending order, the tree become a list, leading to long search times. One of strategies is to randomly shuffle the elements to be inserted. However, we should consider to maintain the balanced binary tree where different operations can be performed one by one depending on requirement. We can maintain the balanced binary search tree by assigning a priority randomly selected to each node and by ordering nodes based on the following properties. Here, we assume that all priorities are distinct and also that all keys are distinct. * **binary-search-tree property.** If $v$ is a **left child** of $u$, then $v.key < u.key$ and if $v$ is a **right child** of $u$, then $u.key < v.key$ * **heap property.** If $v$ is a **child** of $u$, then $v.priority < u.priority$ This combination of properties is why the tree is called Treap (tree + heap). An example of Treap is shown in the following figure. **Insert** To insert a new element into a Treap, first of all, insert a node which a randomly selected priority value is assigned in the same way for ordinal binary search tree. For example, the following figure shows the Treap after a node with key = 6 and priority = 90 is inserted. It is clear that this Treap violates the heap property, so we need to modify the structure of the tree by **rotate** operations. The rotate operation is to change parent-child relation while maintaing the binary-search-tree property. The rotate operations can be implemented as follows. rightRotate(Node t) Node s = t.left t.left = s.right s.right = t return s // the new root of subtree | leftRotate(Node t) Node s = t.right t.right = s.left s.left = t return s // the new root of subtree ---|--- The following figure shows processes of the rotate operations after the insert operation to maintain the properties. The insert operation with rotate operations can be implemented as follows. insert(Node t, int key, int priority) // search the corresponding place recursively if t == NIL return Node(key, priority) // create a new node when you reach a leaf if key == t.key return t // ignore duplicated keys if key < t.key // move to the left child t.left = insert(t.left, key, priority) // update the pointer to the left child if t.priority < t.left.priority // rotate right if the left child has higher priority t = rightRotate(t) else // move to the right child t.right = insert(t.right, key, priority) // update the pointer to the right child if t.priority < t.right.priority // rotate left if the right child has higher priority t = leftRotate(t) return t **Delete** To delete a node from the Treap, first of all, the target node should be moved until it becomes a leaf by rotate operations. Then, you can remove the node (the leaf). These processes can be implemented as follows. delete(Node t, int key) // seach the target recursively if t == NIL return NIL if key < t.key // search the target recursively t.left = delete(t.left, key) else if key > t.key t.right = delete(t.right, key) else return _delete(t, key) return t _delete(Node t, int key) // if t is the target node if t.left == NIL && t.right == NIL // if t is a leaf return NIL else if t.left == NIL // if t has only the right child, then perform left rotate t = leftRotate(t) else if t.right == NIL // if t has only the left child, then perform right rotate t = rightRotate(t) else // if t has both the left and right child if t.left.priority > t.right.priority // pull up the child with higher priority t = rightRotate(t) else t = leftRotate(t) return delete(t, key) Write a program which performs the following operations to a Treap $T$ based on the above described algorithm. * insert ($k$, $p$): Insert a node containing $k$ as key and $p$ as priority to $T$. * find ($k$): Report whether $T$ has a node containing $k$. * delete ($k$): Delete a node containing $k$. * print(): Print the keys of the binary search tree by inorder tree walk and preorder tree walk respectively.
|
class node:
def __init__(self,key,pri,left=None,right=None):
self.left = left
self.right = right
self.key = key
self.pri = pri
def insert(n,key,pri):
if(n == None):
return node(key,pri)
if(key == n.key):
return n
if(key < n.key):
n.left = insert(n.left, key, pri)
if(n.pri < n.left.pri):
n = rightRotate(n)
else:
n.right = insert(n.right, key, pri)
if(n.pri < n.right.pri):
n = leftRotate(n)
return n
def rightRotate(n):
swapL,swapK,swapP = n.left.left,n.left.key,n.left.pri
n.left = None
n = node(swapK,swapP,swapL,n)
return n
def leftRotate(n):
swapR,swapK,swapP = n.right.right,n.right.key,n.right.pri
n.right = None
n = node(swapK,swapP,n,swapR)
return n
def find(n,key):
if(n == None):
return None
elif(n.key == key):
return n
elif(n.key > key):
return find(n.left,key)
else:
return find(n.right,key)
def delete(n, key):
if(n == None):
return None
if(key < n.key):
n.left = delete(n.left, key)
elif(key > n.key):
n.right = delete(n.right, key)
else:
return _delete(n, key)
return n
def _delete(n, key):
if(n.left == None and n.right == None):
return None
elif(n.left == None):
n = leftRotate(n)
elif(n.right == None):
n = rightRotate(n)
else:
if(n.left.pri > n.right.pri):
n = rightRotate(n)
else:
n = leftRotate(n)
return delete(n, key)
def inorder(n):
if(n==None):
return
if(n.left != None):
inorder(n.left)
print(" "+str(n.key), end='')
if(n.right != None):
inorder(n.right)
def preorder(n):
if(n==None):
return
print(" "+str(n.key), end='')
if(n.left != None):
preorder(n.left)
if(n.right != None):
preorder(n.right)
op_num=(int)(input())
root = None
for i in range(op_num):
items = input().split()
if(items[0] == "insert"):
root = insert(root,(int)(items[1]),(int)(items[2]))
elif(items[0] == "delete"):
root = delete(root,(int)(items[1]))
elif(items[0] == "find"):
res = find(root,(int)(items[1]))
if(res == None):
print("no")
else:
print("yes")
else:
inorder(root)
print("")
preorder(root)
print("")
|
s067197239
|
Accepted
| 5,830
| 52,028
| 2,529
|
class node:
def __init__(self,key,pri,left=None,right=None):
self.left = left
self.right = right
self.key = key
self.pri = pri
def insert(n,key,pri):
if(n == None):
return node(key,pri)
if(key == n.key):
return n
if(key < n.key):
n.left = insert(n.left, key, pri)
if(n.pri < n.left.pri):
n = rightRotate(n)
else:
n.right = insert(n.right, key, pri)
if(n.pri < n.right.pri):
n = leftRotate(n)
return n
def rightRotate(n):
child = n.left
swapL,swapR,swapK,swapP = child.left,child.right,child.key,child.pri
n.left = swapR
n = node(swapK,swapP,swapL,n)
return n
def leftRotate(n):
child = n.right
swapL,swapR,swapK,swapP = child.left,child.right,child.key,child.pri
n.right = swapL
n = node(swapK,swapP,n,swapR)
return n
def find(n,key):
if(n == None):
return None
elif(n.key == key):
return n
elif(n.key > key):
return find(n.left,key)
else:
return find(n.right,key)
def delete(n, key):
if(n == None):
return None
if(key < n.key):
n.left = delete(n.left, key)
elif(key > n.key):
n.right = delete(n.right, key)
else:
return _delete(n, key)
return n
def _delete(n, key):
if(n.left == None and n.right == None):
return None
elif(n.left == None):
n = leftRotate(n)
elif(n.right == None):
n = rightRotate(n)
else:
if(n.left.pri > n.right.pri):
n = rightRotate(n)
else:
n = leftRotate(n)
return delete(n, key)
def inorder(n):
if(n==None):
return
if(n.left != None):
inorder(n.left)
print(" "+str(n.key), end='')
if(n.right != None):
inorder(n.right)
def preorder(n):
if(n==None):
return
print(" "+str(n.key), end='')
if(n.left != None):
preorder(n.left)
if(n.right != None):
preorder(n.right)
op_num=(int)(input())
root = None
for i in range(op_num):
items = input().split()
if(items[0] == "insert"):
root = insert(root,(int)(items[1]),(int)(items[2]))
elif(items[0] == "delete"):
root = delete(root,(int)(items[1]))
elif(items[0] == "find"):
res = find(root,(int)(items[1]))
if(res == None):
print("no")
else:
print("yes")
else:
inorder(root)
print("")
preorder(root)
print("")
|
s995913201
|
p03827
|
u469953228
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 139
|
You have an integer variable x. Initially, x=0. Some person gave you a string S of length N, and using the string you performed the following operation N times. In the i-th operation, you incremented the value of x by 1 if S_i=`I`, and decremented the value of x by 1 if S_i=`D`. Find the maximum value taken by x during the operations (including before the first operation, and after the last operation).
|
n=int(input())
s=input()
x=0
maximum=0
for i in range(n):
if s[i]=="I":
x+=1
else:
x-=0
maximum=max(x,maximum)
print(maximum)
|
s534634447
|
Accepted
| 17
| 2,940
| 139
|
n=int(input())
s=input()
x=0
maximum=0
for i in range(n):
if s[i]=="I":
x+=1
else:
x-=1
maximum=max(x,maximum)
print(maximum)
|
s115943767
|
p03543
|
u980492406
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 113
|
We call a 4-digit integer with three or more consecutive same digits, such as 1118, **good**. You are given a 4-digit integer N. Answer the question: Is N **good**?
|
N = input()
for i in range(0,10) :
if N.count('i') >= 3 :
print('Yes')
else :
print('No')
|
s016167006
|
Accepted
| 17
| 2,940
| 99
|
n = list(input())
if n[0]==n[1]==n[2] or n[1]==n[2]==n[3] :
print('Yes')
else :
print('No')
|
s456288158
|
p03943
|
u243159381
| 2,000
| 262,144
|
Wrong Answer
| 18
| 2,940
| 110
|
Two students of AtCoder Kindergarten are fighting over candy packs. There are three candy packs, each of which contains a, b, and c candies, respectively. Teacher Evi is trying to distribute the packs between the two students so that each student gets the same number of candies. Determine whether it is possible. Note that Evi cannot take candies out of the packs, and the whole contents of each pack must be given to one of the students.
|
a,b,c=(int(x) for x in input().split())
if a+b==c or b+c==a or c+a==b:
print('YES')
else:
print('NO')
|
s547761398
|
Accepted
| 18
| 2,940
| 110
|
a,b,c=(int(x) for x in input().split())
if a+b==c or b+c==a or c+a==b:
print('Yes')
else:
print('No')
|
s926994366
|
p03360
|
u023229441
| 2,000
| 262,144
|
Wrong Answer
| 27
| 9,084
| 84
|
There are three positive integers A, B and C written on a blackboard. E869120 performs the following operation K times: * Choose one integer written on the blackboard and let the chosen integer be n. Replace the chosen integer with 2n. What is the largest possible sum of the integers written on the blackboard after K operations?
|
a,b,c=map(int,input().split())
n=int(input())
a,b,c= sorted([a,b,c])
print(a+b+c*n)
|
s987007968
|
Accepted
| 26
| 9,148
| 88
|
a,b,c=map(int,input().split())
n=int(input())
a,b,c= sorted([a,b,c])
print(a+b+c*2**n)
|
s554622369
|
p02842
|
u008357982
| 2,000
| 1,048,576
|
Wrong Answer
| 17
| 2,940
| 90
|
Takahashi bought a piece of apple pie at ABC Confiserie. According to his memory, he paid N yen (the currency of Japan) for it. The consumption tax rate for foods in this shop is 8 percent. That is, to buy an apple pie priced at X yen before tax, you have to pay X \times 1.08 yen (rounded down to the nearest integer). Takahashi forgot the price of his apple pie before tax, X, and wants to know it again. Write a program that takes N as input and finds X. We assume X is an integer. If there are multiple possible values for X, find any one of them. Also, Takahashi's memory of N, the amount he paid, may be incorrect. If no value could be X, report that fact.
|
n = int(input())
x = -(-n // 1.08)
if int(x * 1.08) == n:
print(1)
else:
print(0)
|
s672223542
|
Accepted
| 17
| 2,940
| 98
|
n = int(input())
x = -(-n // 1.08)
if int(x * 1.08) == n:
print(int(x))
else:
print(':(')
|
s821241393
|
p03693
|
u855057563
| 2,000
| 262,144
|
Wrong Answer
| 27
| 9,136
| 81
|
AtCoDeer has three cards, one red, one green and one blue. An integer between 1 and 9 (inclusive) is written on each card: r on the red card, g on the green card and b on the blue card. We will arrange the cards in the order red, green and blue from left to right, and read them as a three-digit integer. Is this integer a multiple of 4?
|
r,g,b=input().split()
n=int(r+g+b)
if n%4==0:
print("Yes")
else:
print("No")
|
s704823335
|
Accepted
| 25
| 9,008
| 82
|
r,g,b=input().split()
n=int(r+g+b)
if n%4==0:
print("YES")
else:
print("NO")
|
s768495354
|
p03759
|
u629350026
| 2,000
| 262,144
|
Wrong Answer
| 18
| 2,940
| 82
|
Three poles stand evenly spaced along a line. Their heights are a, b and c meters, from left to right. We will call the arrangement of the poles _beautiful_ if the tops of the poles lie on the same line, that is, b-a = c-b. Determine whether the arrangement of the poles is beautiful.
|
a,b,c=map(int,input().split())
if (b-a)==(c-b):
print("Yes")
else:
print("No")
|
s947173897
|
Accepted
| 17
| 2,940
| 82
|
a,b,c=map(int,input().split())
if (b-a)==(c-b):
print("YES")
else:
print("NO")
|
s567661446
|
p02402
|
u613534067
| 1,000
| 131,072
|
Wrong Answer
| 20
| 5,576
| 74
|
Write a program which reads a sequence of $n$ integers $a_i (i = 1, 2, ... n)$, and prints the minimum value, maximum value and sum of the sequence.
|
input()
a = list(map(int, input().split()))
print(max(a), min(a), sum(a))
|
s904170755
|
Accepted
| 20
| 6,544
| 74
|
input()
a = list(map(int, input().split()))
print(min(a), max(a), sum(a))
|
s934026344
|
p03352
|
u201802797
| 2,000
| 1,048,576
|
Wrong Answer
| 18
| 3,068
| 197
|
You are given a positive integer X. Find the largest _perfect power_ that is at most X. Here, a perfect power is an integer that can be represented as b^p, where b is an integer not less than 1 and p is an integer not less than 2.
|
# solution
import io
nim = int(input())
mike = 1
for i in range(2,(nim+1)//2):
kite = 0
counter = 0
while kite <= nim:
m = max(mike,kite)
kite = i**counter
counter+=1
print(mike)
|
s979374789
|
Accepted
| 17
| 2,940
| 151
|
# solution
data=int(input())
array=[]
for i in range(1,34):
for j in range(2,11):
if (i**j)<=data:
array.append(i**j)
print(max(array))
|
s398686144
|
p03636
|
u236460988
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 50
|
The word `internationalization` is sometimes abbreviated to `i18n`. This comes from the fact that there are 18 letters between the first `i` and the last `n`. You are given a string s of length at least 3 consisting of lowercase English letters. Abbreviate s in the same way.
|
s = input()
print( s[0] + str(len(s)-1) + s[-1] )
|
s712780156
|
Accepted
| 17
| 2,940
| 50
|
s = input()
print( s[0] + str(len(s)-2) + s[-1] )
|
s564558994
|
p02842
|
u635540732
| 2,000
| 1,048,576
|
Wrong Answer
| 17
| 3,060
| 100
|
Takahashi bought a piece of apple pie at ABC Confiserie. According to his memory, he paid N yen (the currency of Japan) for it. The consumption tax rate for foods in this shop is 8 percent. That is, to buy an apple pie priced at X yen before tax, you have to pay X \times 1.08 yen (rounded down to the nearest integer). Takahashi forgot the price of his apple pie before tax, X, and wants to know it again. Write a program that takes N as input and finds X. We assume X is an integer. If there are multiple possible values for X, find any one of them. Also, Takahashi's memory of N, the amount he paid, may be incorrect. If no value could be X, report that fact.
|
n=int(input())
x=n//1.08
if x%1==0:
print(x)
elif (x+1)*1.08-n<1:
print(x+1)
else:
print(':(')
|
s376841072
|
Accepted
| 17
| 3,060
| 118
|
n=int(input())
x=n/1.08
if x%1==0:
print(int(x))
elif int((int(x)+1)*1.08)==n:
print(int(x)+1)
else:
print(':(')
|
s390259299
|
p03048
|
u277312083
| 2,000
| 1,048,576
|
Time Limit Exceeded
| 2,126
| 9,120
| 195
|
Snuke has come to a store that sells boxes containing balls. The store sells the following three kinds of boxes: * Red boxes, each containing R red balls * Green boxes, each containing G green balls * Blue boxes, each containing B blue balls Snuke wants to get a total of exactly N balls by buying r red boxes, g green boxes and b blue boxes. How many triples of non-negative integers (r,g,b) achieve this?
|
R, G, B, N = map(int, input().split())
ans = 0
for r in range(3001):
for g in range(3001):
v = R * r + G * g
if N >= v and (N - v) % B == 0:
ans += 1
print(ans)
|
s739152856
|
Accepted
| 1,995
| 9,116
| 270
|
R, G, B, N = map(int, input().split())
ans = 0
for r in range(min(3000, 3000 // R) + 1):
if R * r <= N:
for g in range(min(3000, 3000 // G) + 1):
v = R * r + G * g
if N >= v and (N - v) % B == 0:
ans += 1
print(ans)
|
s236296686
|
p01132
|
u506554532
| 8,000
| 131,072
|
Wrong Answer
| 4,300
| 5,624
| 832
|
Mr. Bill は店で買い物をしている。 彼の財布にはいくらかの硬貨(10 円玉、50 円玉、100 円玉、500 円玉)が入っているが、彼は今この小銭をできるだけ消費しようとしている。 つまり、適切な枚数の硬貨によって品物の代金を払うことで、釣り銭を受け取った後における硬貨の合計枚数を最小にしようとしている。 幸いなことに、この店の店員はとても律儀かつ親切であるため、釣り銭は常に最適な方法で渡される。 したがって、例えば 1 枚の 500 円玉の代わりに 5 枚の 100 円玉が渡されるようなことはない。 また、例えば 10 円玉を 5 枚出して、50 円玉を釣り銭として受け取ることもできる。 ただし、出した硬貨と同じ種類の硬貨が釣り銭として戻ってくるような払いかたをしてはいけない。 例えば、10 円玉を支払いの際に出したにも関わらず、別の 10 円玉が釣り銭として戻されるようでは、完全に意味のないやりとりが発生してしまうからである。 ところが Mr. Bill は計算が苦手なため、実際に何枚の硬貨を使用すればよいかを彼自身で求めることができなかった。 そこで、彼はあなたに助けを求めてきた。 あなたの仕事は、彼の財布の中にある硬貨の枚数と支払い代金をもとに、使用すべき硬貨の種類と枚数を求めるプログラムを書くことである。なお、店員はお釣りに紙幣を使用することはない。
|
def calc(c1,c2,c3,c4):
return c1*10 + c2*50 + c3*100 + c4*500
def coindiff(p,c1,c2,c3,c4):
n = c1+c2+c3+c4
over = calc(c1,c2,c3,c4) - p
n -= (over%50) // 10
n -= (over%100) // 50
n -= (over%500) // 100
n -= over // 500
return n
while True:
N = int(input())
if N == 0: break
c1,c2,c3,c4 = map(int,input().split())
maxdiff = -9999999
ans = None
for n1 in range(c1+1):
for n2 in range(c2+1):
for n3 in range(c3+1):
n4 = (N - n1*10 + n2*50 + n3*100) // 500
if n4 < 0: continue
d = coindiff(N,n1,n2,n3,n4)
if d > maxdiff:
maxdiff = d
ans = {10:n1,50:n2,100:n3,500:n4}
for k,v in sorted(ans.items()):
print('{0} {1}'.format(k, v))
print('')
|
s601285565
|
Accepted
| 100
| 5,620
| 498
|
first = True
while True:
P = int(input())
if P== 0: break
if first:
first = False
else:
print('')
c1,c2,c3,c4 = map(int,input().split())
v = c1*10 + c2*50 + c3*100 + c4*500
n = c1 + c2 + c3 + c4
ans = {}
rem = v - P
ans[10] = c1 - (rem//10) % 5
ans[50] = c2 - (rem//50) % 2
ans[100] = c3 - (rem//100) % 5
ans[500] = c4 - rem//500
for k,v in sorted(ans.items()):
if v <= 0: continue
print('{0} {1}'.format(k,v))
|
s659268644
|
p02795
|
u269724549
| 2,000
| 1,048,576
|
Wrong Answer
| 18
| 2,940
| 74
|
We have a grid with H rows and W columns, where all the squares are initially white. You will perform some number of painting operations on the grid. In one operation, you can do one of the following two actions: * Choose one row, then paint all the squares in that row black. * Choose one column, then paint all the squares in that column black. At least how many operations do you need in order to have N or more black squares in the grid? It is guaranteed that, under the conditions in Constraints, having N or more black squares is always possible by performing some number of operations.
|
h=int(input())
n=int(input())
w=int(input())
print(w+max(h,n)-1//max(h,n))
|
s790894341
|
Accepted
| 17
| 2,940
| 74
|
h=int(input())
n=int(input())
w=int(input())
v=max(h,n)
print((w+v-1)//v)
|
s558843367
|
p03695
|
u107077660
| 2,000
| 262,144
|
Wrong Answer
| 21
| 3,316
| 179
|
In AtCoder, a person who has participated in a contest receives a _color_ , which corresponds to the person's rating as follows: * Rating 1-399 : gray * Rating 400-799 : brown * Rating 800-1199 : green * Rating 1200-1599 : cyan * Rating 1600-1999 : blue * Rating 2000-2399 : yellow * Rating 2400-2799 : orange * Rating 2800-3199 : red Other than the above, a person whose rating is 3200 or higher can freely pick his/her color, which can be one of the eight colors above or not. Currently, there are N users who have participated in a contest in AtCoder, and the i-th user has a rating of a_i. Find the minimum and maximum possible numbers of different colors of the users.
|
from collections import Counter
N = input()
c = Counter([int(i)//400 for i in input().split()])
print(c)
ans = 0
for i in range(8):
ans += bool(c[i])
print(max(ans,1),ans+c[8])
|
s493157591
|
Accepted
| 20
| 3,316
| 171
|
from collections import Counter
input()
c = Counter([min(int(i)//400,8) for i in input().split()])
ans = 0
for i in range(8):
ans += bool(c[i])
print(max(ans,1),ans+c[8])
|
s804374420
|
p03640
|
u489124637
| 2,000
| 262,144
|
Wrong Answer
| 28
| 4,340
| 617
|
We have a grid with H rows and W columns of squares. Snuke is painting these squares in colors 1, 2, ..., N. Here, the following conditions should be satisfied: * For each i (1 ≤ i ≤ N), there are exactly a_i squares painted in Color i. Here, a_1 + a_2 + ... + a_N = H W. * For each i (1 ≤ i ≤ N), the squares painted in Color i are _4-connected_. That is, every square painted in Color i can be reached from every square painted in Color i by repeatedly traveling to a horizontally or vertically adjacent square painted in Color i. Find a way to paint the squares so that the conditions are satisfied. It can be shown that a solution always exists.
|
from collections import deque
import itertools
H , W = map(int,input().split())
N = int(input())
a = list(map(int,input().split()))
acu = [0] + list(itertools.accumulate(a))
ans = [[0] * W for _ in range(H)]
cnt = 1
jdg = 1
for h in range(H):
if h % 2 == 1:
for w in range(W):
ans[h][w] = jdg
if cnt >= acu[jdg]:
jdg += 1
cnt += 1
if h % 2 == 0:
for w in reversed(range(W)):
ans[h][w] = jdg
if cnt >= acu[jdg]:
jdg += 1
cnt += 1
print(ans)
|
s201653966
|
Accepted
| 30
| 4,596
| 644
|
from collections import deque
import itertools
H , W = map(int,input().split())
N = int(input())
a = list(map(int,input().split()))
acu = [0] + list(itertools.accumulate(a))
ans = [[0] * W for _ in range(H)]
cnt = 1
jdg = 1
for h in range(H):
if h % 2 == 1:
for w in range(W):
ans[h][w] = jdg
if cnt >= acu[jdg]:
jdg += 1
cnt += 1
if h % 2 == 0:
for w in reversed(range(W)):
ans[h][w] = jdg
if cnt >= acu[jdg]:
jdg += 1
cnt += 1
for i in range(H):
print(*ans[i])
|
s233258086
|
p03597
|
u121732701
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 45
|
We have an N \times N square grid. We will paint each square in the grid either black or white. If we paint exactly A squares white, how many squares will be painted black?
|
N = int(input())
A = int(input())
print(N-A)
|
s546359007
|
Accepted
| 18
| 2,940
| 47
|
N = int(input())
A = int(input())
print(N*N-A)
|
s642040577
|
p03480
|
u227082700
| 2,000
| 262,144
|
Wrong Answer
| 68
| 3,316
| 111
|
You are given a string S consisting of `0` and `1`. Find the maximum integer K not greater than |S| such that we can turn all the characters of S into `0` by repeating the following operation some number of times. * Choose a contiguous segment [l,r] in S whose length is at least K (that is, r-l+1\geq K must be satisfied). For each integer i such that l\leq i\leq r, do the following: if S_i is `0`, replace it with `1`; if S_i is `1`, replace it with `0`.
|
s=input()
ans=len(s)
for i in range(len(s)-1):
if s[i]!=s[i+1]:
ans=min(ans,min(i+1,len(s)-i))
print(ans)
|
s219494818
|
Accepted
| 72
| 3,188
| 113
|
s=input()
ans=len(s)
for i in range(len(s)-1):
if s[i]!=s[i+1]:
ans=min(ans,max(i+1,len(s)-i-1))
print(ans)
|
s322236537
|
p03556
|
u887207211
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 46
|
Find the largest square number not exceeding N. Here, a _square number_ is an integer that can be represented as the square of an integer.
|
N = int(input())
print((int(N**(0.5))-1)**2)
|
s493012329
|
Accepted
| 17
| 3,060
| 38
|
N = int(input())
print(int(N**0.5)**2)
|
s454916717
|
p03369
|
u901687869
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 88
|
In "Takahashi-ya", a ramen restaurant, a bowl of ramen costs 700 yen (the currency of Japan), plus 100 yen for each kind of topping (boiled egg, sliced pork, green onions). A customer ordered a bowl of ramen and told which toppings to put on his ramen to a clerk. The clerk took a memo of the order as a string S. S is three characters long, and if the first character in S is `o`, it means the ramen should be topped with boiled egg; if that character is `x`, it means the ramen should not be topped with boiled egg. Similarly, the second and third characters in S mean the presence or absence of sliced pork and green onions on top of the ramen. Write a program that, when S is given, prints the price of the corresponding bowl of ramen.
|
money = 700
tp = input()
for s in tp:
if(s == "○"):
money += 100
print(money)
|
s277399511
|
Accepted
| 17
| 2,940
| 86
|
money = 700
tp = input()
for s in tp:
if(s == "o"):
money += 100
print(money)
|
s148627676
|
p03470
|
u747427153
| 2,000
| 262,144
|
Wrong Answer
| 27
| 9,188
| 162
|
An _X -layered kagami mochi_ (X ≥ 1) is a pile of X round mochi (rice cake) stacked vertically where each mochi (except the bottom one) has a smaller diameter than that of the mochi directly below it. For example, if you stack three mochi with diameters of 10, 8 and 6 centimeters from bottom to top in this order, you have a 3-layered kagami mochi; if you put just one mochi, you have a 1-layered kagami mochi. Lunlun the dachshund has N round mochi, and the diameter of the i-th mochi is d_i centimeters. When we make a kagami mochi using some or all of them, at most how many layers can our kagami mochi have?
|
n = int(input())
l = []
for i in range(n):
s0 = int(input())
l.append(s0)
l.sort()
ans = 1
for i in range(1,n-1):
if l[i] != l[i-1]:
ans += 1
print(ans)
|
s038772989
|
Accepted
| 25
| 9,176
| 160
|
n = int(input())
l = []
for i in range(n):
s0 = int(input())
l.append(s0)
l.sort()
ans = 1
for i in range(1,n):
if l[i] > l[i-1]:
ans += 1
print(ans)
|
s247885261
|
p03719
|
u342869120
| 2,000
| 262,144
|
Wrong Answer
| 19
| 2,940
| 97
|
You are given three integers A, B and C. Determine whether C is not less than A and not greater than B.
|
a, b, c = map(int, input().split())
if b <= a and a <= c:
print("Yes")
else:
print("No")
|
s612259878
|
Accepted
| 17
| 2,940
| 97
|
a, b, c = map(int, input().split())
if a <= c and c <= b:
print("Yes")
else:
print("No")
|
s360320511
|
p03379
|
u814986259
| 2,000
| 262,144
|
Wrong Answer
| 591
| 40,632
| 205
|
When l is an odd number, the median of l numbers a_1, a_2, ..., a_l is the (\frac{l+1}{2})-th largest value among a_1, a_2, ..., a_l. You are given N numbers X_1, X_2, ..., X_N, where N is an even number. For each i = 1, 2, ..., N, let the median of X_1, X_2, ..., X_N excluding X_i, that is, the median of X_1, X_2, ..., X_{i-1}, X_{i+1}, ..., X_N be B_i. Find B_i for each i = 1, 2, ..., N.
|
N=int(input())
a=list(map(int,input().split()))
b=[[a[i],i] for i in range(N)]
b.sort()
ans=[b[N//2][0],b[(N//2) -1][0]]
for i in range(N):
if a[i] >= ans[1]:
print(ans[0])
else:
print(ans[1])
|
s715055195
|
Accepted
| 321
| 26,772
| 172
|
N=int(input())
a=list(map(int,input().split()))
b=sorted(a)
ans=[b[N//2],b[(N//2) -1]]
for i in range(N):
if a[i] >= ans[0]:
print(ans[1])
else:
print(ans[0])
|
s585642446
|
p02418
|
u009288816
| 1,000
| 131,072
|
Wrong Answer
| 20
| 5,560
| 422
|
Write a program which finds a pattern $p$ in a ring shaped text $s$.
|
import sys
def rotate(x,n):
return x[n:]+x[:n]
def tostring(x):
res = ""
for i in range(0,len(x)):
res += x[i]
return res
def isavail(x,y):
for i in range(0,len(x)):
l = list(x)
l = x[:len(x)-1]
temp = tostring(rotate(l,i))
if temp.find(y) != -1:
return "Yes"
return "No"
l = []
for i in sys.stdin:
l.append(i)
print(isavail(l[0],l[1]))
|
s794009455
|
Accepted
| 20
| 5,564
| 168
|
def ring(s, p):
t = list(s)
for i in range(len(s)):
if ''.join(s[i:] + s[:i]).find(p) > -1:
return 'Yes'
return 'No'
s = input()
p = input()
print(ring(s, p))
|
s175527928
|
p03456
|
u975997984
| 2,000
| 262,144
|
Wrong Answer
| 31
| 9,400
| 103
|
AtCoDeer the deer has found two positive integers, a and b. Determine whether the concatenation of a and b in this order is a square number.
|
n = int(''.join(input().split()))
if isinstance(n ** 0.5, int):
print('Yes')
else:
print('No')
|
s886612165
|
Accepted
| 29
| 9,340
| 101
|
n = int(''.join(input().split()))
if int(n ** 0.5) ** 2 == n:
print('Yes')
else:
print('No')
|
s726830653
|
p03999
|
u543373102
| 2,000
| 262,144
|
Wrong Answer
| 24
| 9,148
| 106
|
You are given a string S consisting of digits between `1` and `9`, inclusive. You can insert the letter `+` into some of the positions (possibly none) between two letters in this string. Here, `+` must not occur consecutively after insertion. All strings that can be obtained in this way can be evaluated as formulas. Evaluate all possible formulas, and print the sum of the results.
|
S = input()
sn = len(S)
ans = 0
for i in range(1, sn+1-1):
ans += int(S[i]) + int(S[i:])
print(ans)
|
s809663569
|
Accepted
| 33
| 9,088
| 239
|
S = input()
n = len(S)-1
ans = 0
for i in range(1 << n):
p = 0
for j in range(n):
if i >> j & 1 == 0:
continue
else:
ans += int(S[p:j+1])
p = j+1
ans += int(S[p:])
print(ans)
|
s413628804
|
p03474
|
u590647174
| 2,000
| 262,144
|
Wrong Answer
| 18
| 3,064
| 352
|
The postal code in Atcoder Kingdom is A+B+1 characters long, its (A+1)-th character is a hyphen `-`, and the other characters are digits from `0` through `9`. You are given a string S. Determine whether it follows the postal code format in Atcoder Kingdom.
|
def judge(S,A,B):
a = list(S)
front = a[:A]
back = a[A+1:]
for i in range(A):
if not type(front[i])==int:
print("No")
return
for j in range(B):
if not type(back[j])==int:
print("No")
return
if not a[A]=="-":
print("No")
return
print("Yes")
A,B = map(int,input().split())
S = input()
judge(S,A,B)
|
s958823737
|
Accepted
| 17
| 3,064
| 425
|
def judge(S,A,B):
a = list(S)
front = a[0:A]
back = a[A+1:A+B+1]
lst = ["0","1","2","3","4","5","6","7","8","9"]
for i in range(A):
if front[i] not in lst:
print("No")
return
for j in range(B):
if back[j] not in lst:
print("No")
return
if a[A]!="-":
print("No")
return
print("Yes")
A,B = map(int,input().split())
S = input()
judge(S,A,B)
|
s116646699
|
p03352
|
u918601425
| 2,000
| 1,048,576
|
Wrong Answer
| 17
| 3,064
| 265
|
You are given a positive integer X. Find the largest _perfect power_ that is at most X. Here, a perfect power is an integer that can be represented as b^p, where b is an integer not less than 1 and p is an integer not less than 2.
|
ls=[1,2,4,8,16,32,64,128,256,512,3,9,27,81,243,729,
25,125,625,36,216,49,343,100,1000,
121,144,169,196,225,289,324,361,400,
441,484,529,576,625,676,781,841,900,961,1001]
n=int(input())
for i in range(len(ls)):
if ls[i]>n:
print(ls[i-1])
break
|
s825481332
|
Accepted
| 17
| 3,064
| 276
|
ls=[1,2,4,8,16,32,64,128,256,512,3,9,27,81,243,729,
25,125,625,36,216,49,343,100,1000,
121,144,169,196,225,289,324,361,400,
441,484,529,576,625,676,781,841,900,961,1001]
ls.sort()
n=int(input())
for i in range(len(ls)):
if ls[i]>n:
print(ls[i-1])
break
|
s306742473
|
p03759
|
u339923489
| 2,000
| 262,144
|
Wrong Answer
| 18
| 2,940
| 136
|
Three poles stand evenly spaced along a line. Their heights are a, b and c meters, from left to right. We will call the arrangement of the poles _beautiful_ if the tops of the poles lie on the same line, that is, b-a = c-b. Determine whether the arrangement of the poles is beautiful.
|
a, b, c =input("数字を入れよう").split(" ")
a=int(a)
b=int(b)
c=int(c)
if b - a == c - b:
print("YES")
else:
print("NO")
|
s824739566
|
Accepted
| 20
| 3,316
| 96
|
a, b, c =map(int, input().split(" "))
if b - a == c - b:
print("YES")
else:
print("NO")
|
s182016677
|
p02393
|
u661041240
| 1,000
| 131,072
|
Wrong Answer
| 20
| 5,588
| 62
|
Write a program which reads three integers, and prints them in ascending order.
|
a, b, c = map(int, input().split())
print(sorted([a, b, c]))
|
s591159140
|
Accepted
| 20
| 5,596
| 89
|
l = list(map(int, input().split()))
l = sorted(l)
print('%d %d %d' % (l[0], l[1], l[2]))
|
s115031216
|
p03478
|
u194894739
| 2,000
| 262,144
|
Wrong Answer
| 28
| 2,940
| 193
|
Find the sum of the integers between 1 and N (inclusive), whose sum of digits written in base 10 is between A and B (inclusive).
|
n, a, b = map(int,input().split())
ans = 0
for i in range(1, n + 1):
sum = 0
while i != 0:
sum += i % 10
i = i // 10
if a <= sum <= b:
ans += sum
print(ans)
|
s805255424
|
Accepted
| 29
| 2,940
| 201
|
n, a, b = map(int,input().split())
ans = 0
for i in range(1, n + 1):
sum = 0
j = i
while j != 0:
sum += j % 10
j = j // 10
if a <= sum <= b:
ans += i
print(ans)
|
s440300895
|
p03860
|
u550535134
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 41
|
Snuke is going to open a contest named "AtCoder s Contest". Here, s is a string of length 1 or greater, where the first character is an uppercase English letter, and the second and subsequent characters are lowercase English letters. Snuke has decided to abbreviate the name of the contest as "AxC". Here, x is the uppercase English letter at the beginning of s. Given the name of the contest, print the abbreviation of the name.
|
A, s, C = input().split()
print(A+s[0]+C)
|
s989656242
|
Accepted
| 17
| 2,940
| 47
|
A, s, C = input().split()
print(A[0]+s[0]+C[0])
|
s257279934
|
p03469
|
u541610817
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 38
|
On some day in January 2018, Takaki is writing a document. The document has a column where the current date is written in `yyyy/mm/dd` format. For example, January 23, 2018 should be written as `2018/01/23`. After finishing the document, she noticed that she had mistakenly wrote `2017` at the beginning of the date column. Write a program that, when the string that Takaki wrote in the date column, S, is given as input, modifies the first four characters in S to `2018` and prints it.
|
str = input()
str[3] == '7'
print(str)
|
s160880702
|
Accepted
| 18
| 2,940
| 126
|
def solve():
_, m, d = input().split('/')
return '2018/' + m + '/' + d
if __name__ == '__main__':
print(solve())
|
s219306074
|
p03377
|
u111202730
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 86
|
There are a total of A + B cats and dogs. Among them, A are known to be cats, but the remaining B are not known to be either cats or dogs. Determine if it is possible that there are exactly X cats among these A + B animals.
|
A, B, X = map(int, input().split())
if X <= B:
print('Yes')
else:
print('No')
|
s204475783
|
Accepted
| 17
| 2,940
| 94
|
A, B, X = map(int, input().split())
if A <= X <= A + B:
print('YES')
else:
print('NO')
|
s146025637
|
p03556
|
u382639013
| 2,000
| 262,144
|
Wrong Answer
| 30
| 9,408
| 42
|
Find the largest square number not exceeding N. Here, a _square number_ is an integer that can be represented as the square of an integer.
|
N = int(input())
print(int(10**(0.5)**2))
|
s701631940
|
Accepted
| 31
| 9,348
| 41
|
N = int(input())
print(int(N**(0.5))**2)
|
s490760161
|
p02747
|
u498847144
| 2,000
| 1,048,576
|
Wrong Answer
| 17
| 3,064
| 317
|
A Hitachi string is a concatenation of one or more copies of the string `hi`. For example, `hi` and `hihi` are Hitachi strings, while `ha` and `hii` are not. Given a string S, determine whether S is a Hitachi string.
|
large_s = input()
con = 0
str_check = ""
for i in range(len(large_s)):
z = large_s.find('hi', con, len(large_s))
if (0 <= z):
print(z)
str_check += str(z)
con += 2
if (str_check=='0' or str_check=='02' or str_check=='024' or str_check=='0246' or str_check=='02468'):
print("YES")
|
s723582266
|
Accepted
| 18
| 2,940
| 127
|
z = input()
if z=='hi' or z=='hihi' or z=='hihihi' or z=='hihihihi' or z=='hihihihihi':
print("Yes")
else:
print("No")
|
s398319446
|
p03587
|
u898651494
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 60
|
Snuke prepared 6 problems for a upcoming programming contest. For each of those problems, Rng judged whether it can be used in the contest or not. You are given a string S of length 6. If the i-th character of s is `1`, it means that the i-th problem prepared by Snuke is accepted to be used; `0` means that the problem is not accepted. How many problems prepared by Snuke are accepted to be used in the contest?
|
s=input()
ans=0
for i in s:
if i==1:
ans+=1
print(ans)
|
s247672863
|
Accepted
| 19
| 2,940
| 76
|
s=input()
ans=0
for i in range (6):
if int(s[i])==1:
ans+=1
print(ans)
|
s417791219
|
p02612
|
u281745878
| 2,000
| 1,048,576
|
Wrong Answer
| 23
| 9,148
| 68
|
We will buy a product for N yen (the currency of Japan) at a shop. If we use only 1000-yen bills to pay the price, how much change will we receive? Assume we use the minimum number of bills required.
|
N = int(input())
if N <1000:
print(N)
else:
print(N % 1000)
|
s961581932
|
Accepted
| 28
| 9,160
| 153
|
N = int(input())
if N <1000:
print(1000 - N)
elif N % 1000 == 0:
print(0)
else:
tmp = N // 1000
tmp = 1000 * (tmp +1)
print(tmp - N)
|
s228204171
|
p03555
|
u557171945
| 2,000
| 262,144
|
Wrong Answer
| 18
| 2,940
| 139
|
You are given a grid with 2 rows and 3 columns of squares. The color of the square at the i-th row and j-th column is represented by the character C_{ij}. Write a program that prints `YES` if this grid remains the same when rotated 180 degrees, and prints `NO` otherwise.
|
x = [input() for i in range(2)]
if ((x[0][0]==x[1][2])and(x[0][2]==x[1][0])) and x[0][1]==x[1][1]:
print('Yes')
else:
print('No')
|
s833579149
|
Accepted
| 18
| 2,940
| 139
|
x = [input() for i in range(2)]
if ((x[0][0]==x[1][2])and(x[0][2]==x[1][0])) and x[0][1]==x[1][1]:
print('YES')
else:
print('NO')
|
s697496861
|
p03610
|
u703442202
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 91
|
You are given a string s consisting of lowercase English letters. Extract all the characters in the odd-indexed positions and print the string obtained by concatenating them. Here, the leftmost character is assigned the index 1.
|
s = "abcde"
s = list(s)
s_cut = s[0::2]
ans = ""
for i in s_cut:
ans += i
print(ans)
|
s448530751
|
Accepted
| 27
| 4,268
| 90
|
s = input()
s = list(s)
s_cut = s[0::2]
ans = ""
for i in s_cut:
ans += i
print(ans)
|
s655101793
|
p02608
|
u830036378
| 2,000
| 1,048,576
|
Wrong Answer
| 1,229
| 118,632
| 482
|
Let f(n) be the number of triples of integers (x,y,z) that satisfy both of the following conditions: * 1 \leq x,y,z * x^2 + y^2 + z^2 + xy + yz + zx = n Given an integer N, find each of f(1),f(2),f(3),\ldots,f(N).
|
import itertools
import math
import collections
def main():
n = int(input())
s = int(math.sqrt(n))
a = list(itertools.product(range(1,s),repeat=3))
ans = []
for i in range(len(a)):
t = a[i][0] ** 2 + a[i][1] ** 2 + a[i][2] ** 2 + a[i][0] * a[i][1] + a[i][1] * a[i][2] + a[i][2] * a[i][0]
ans.append(t)
# print(ans)
c = collections.Counter(ans)
for i in range(n):
print(c[i])
main()
|
s471068378
|
Accepted
| 1,171
| 118,384
| 486
|
import itertools
import math
import collections
def main():
n = int(input())
s = int(math.sqrt(n))
a = list(itertools.product(range(1,s),repeat=3))
ans = []
for i in range(len(a)):
t = a[i][0] ** 2 + a[i][1] ** 2 + a[i][2] ** 2 + a[i][0] * a[i][1] + a[i][1] * a[i][2] + a[i][2] * a[i][0]
ans.append(t)
# print(ans)
c = collections.Counter(ans)
for i in range(1,n+1):
print(c[i])
main()
|
s762138370
|
p03361
|
u185294445
| 2,000
| 262,144
|
Wrong Answer
| 19
| 3,192
| 1,985
|
We have a canvas divided into a grid with H rows and W columns. The square at the i-th row from the top and the j-th column from the left is represented as (i, j). Initially, all the squares are white. square1001 wants to draw a picture with black paint. His specific objective is to make Square (i, j) black when s_{i, j}= `#`, and to make Square (i, j) white when s_{i, j}= `.`. However, since he is not a good painter, he can only choose two squares that are horizontally or vertically adjacent and paint those squares black, for some number of times (possibly zero). He may choose squares that are already painted black, in which case the color of those squares remain black. Determine if square1001 can achieve his objective.
|
n = input().split()
n = [int(n[0]), int(n[1])]
H = n[0]
W=n[1]
s = [list(map(str, input().split())) for i in range(H)]
print(s[0][0][1])
c = True
for i in range(H):
for j in range(W):
if(s[i][0][j] == '#'):
if(i == 0):
if(j == 0):
if(s[i + 1][0][j] == '.' and s[i][0][j + 1] == '.'):
c = False
break
elif(j == W - 1):
if(s[i+1][0][j ] == '.' and s[i][0][j-1] == '.'):
c = False
break
else:
if(s[i + 1][0][j] == '.' and s[i][0][j + 1] == '.' and s[i][0][j-1] == '.'):
c = False
break
elif(i == H - 1):
if(j == 0):
if(s[i - 1][0][j] == '.' and s[i][0][j +1] == '.'):
c = False
break
elif(j == W - 1):
if(s[i-1][0][j] == '.' and s[i][0][j-1] == '.'):
c = False
break
else:
if(s[i - 1][0][j] == '.' and s[i][0][j + 1] == '.' and s[i][0][j-1] == '.'):
c = False
break
else:
if(j == 0):
if(s[i - 1][0][j] == '.' and s[i][0][j +1] == '.' and s[i + 1][0][j] == '.'):
c = False
break
elif(j == W - 1):
if(s[i-1][0][j] == '.' and s[i][0][j-1] == '.' and s[i + 1][0][j] == '.'):
c = False
break
else:
if(s[i - 1][0][j] == '.' and s[i][0][j + 1] == '.' and s[i][0][j-1] == '.' and s[i + 1][0][j] == '.'):
c = False
break
if(c):
print("Yes")
else:
print("No")
|
s837124790
|
Accepted
| 19
| 3,192
| 1,968
|
n = input().split()
n = [int(n[0]), int(n[1])]
H = n[0]
W=n[1]
s = [list(map(str, input().split())) for i in range(H)]
c = True
for i in range(H):
for j in range(W):
if(s[i][0][j] == '#'):
if(i == 0):
if(j == 0):
if(s[i + 1][0][j] == '.' and s[i][0][j + 1] == '.'):
c = False
break
elif(j == W - 1):
if(s[i+1][0][j ] == '.' and s[i][0][j-1] == '.'):
c = False
break
else:
if(s[i + 1][0][j] == '.' and s[i][0][j + 1] == '.' and s[i][0][j-1] == '.'):
c = False
break
elif(i == H - 1):
if(j == 0):
if(s[i - 1][0][j] == '.' and s[i][0][j +1] == '.'):
c = False
break
elif(j == W - 1):
if(s[i-1][0][j] == '.' and s[i][0][j-1] == '.'):
c = False
break
else:
if(s[i - 1][0][j] == '.' and s[i][0][j + 1] == '.' and s[i][0][j-1] == '.'):
c = False
break
else:
if(j == 0):
if(s[i - 1][0][j] == '.' and s[i][0][j +1] == '.' and s[i + 1][0][j] == '.'):
c = False
break
elif(j == W - 1):
if(s[i-1][0][j] == '.' and s[i][0][j-1] == '.' and s[i + 1][0][j] == '.'):
c = False
break
else:
if(s[i - 1][0][j] == '.' and s[i][0][j + 1] == '.' and s[i][0][j-1] == '.' and s[i + 1][0][j] == '.'):
c = False
break
if(c):
print("Yes")
else:
print("No")
|
s370898615
|
p03486
|
u361826811
| 2,000
| 262,144
|
Wrong Answer
| 17
| 3,060
| 260
|
You are given strings s and t, consisting of lowercase English letters. You will create a string s' by freely rearranging the characters in s. You will also create a string t' by freely rearranging the characters in t. Determine whether it is possible to satisfy s' < t' for the lexicographic order.
|
import sys
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 7)
a = readline().rstrip()
b = readline().rstrip()
sorted(a)
sorted(b)[::-1]
print("Yes" if a < b else "No")
|
s224255111
|
Accepted
| 18
| 3,064
| 357
|
import sys
# import itertools
# import numpy as np
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)
s, t = read().decode('utf8').split()
S=''.join(sorted(s))
T=''.join(sorted(t))
print('Yes' if S < T[::-1] else 'No')
|
s599117276
|
p03450
|
u099566485
| 2,000
| 262,144
|
Wrong Answer
| 18
| 3,064
| 2,126
|
There are N people standing on the x-axis. Let the coordinate of Person i be x_i. For every i, x_i is an integer between 0 and 10^9 (inclusive). It is possible that more than one person is standing at the same coordinate. You will given M pieces of information regarding the positions of these people. The i-th piece of information has the form (L_i, R_i, D_i). This means that Person R_i is to the right of Person L_i by D_i units of distance, that is, x_{R_i} - x_{L_i} = D_i holds. It turns out that some of these M pieces of information may be incorrect. Determine if there exists a set of values (x_1, x_2, ..., x_N) that is consistent with the given pieces of information.
|
#ABC087-D
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(input())
def S(): return list(input())
class WeightedUnionFind:
def __init__(self, size):
"""
:param collections.Iterable nodes:
"""
self._parents = [i for i in range(size)]
self._ranks = [0 for _ in range(size)]
self._sizes = [1 for _ in range(size)]
self._weights = [0 for _ in range(size)]
def unite(self, x, y, w):
rx = self.find(x)
ry = self.find(y)
if rx == ry:
return
if self._ranks[rx] > self._ranks[ry]:
self._parents[ry] = rx
self._sizes[rx] += self._sizes[ry]
self._weights[ry] = w + self._weights[x] - self._weights[y]
else:
self._parents[rx] = ry
self._sizes[ry] += self._sizes[rx]
self._weights[rx] = -w + self._weights[y] - self._weights[x]
if self._ranks[rx] == self._ranks[ry]:
self._ranks[ry] += 1
def find(self, x):
if self._parents[x] == x:
return x
root = self.find(self._parents[x])
self._weights[x] += self._weights[self._parents[x]]
self._parents[x] = root
return root
def size(self, x):
return self._sizes[self.find(x)]
def weight(self, x):
"""
:param x:
:return:
"""
self.find(x)
return self._weights[x]
|
s370462027
|
Accepted
| 1,729
| 10,812
| 2,738
|
#ABC087-D
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(input())
def S(): return list(input())
class WeightedUnionFind:
def __init__(self, size):
"""
:param collections.Iterable nodes:
"""
self._parents = [i for i in range(size)]
self._ranks = [0 for _ in range(size)]
self._sizes = [1 for _ in range(size)]
self._weights = [0 for _ in range(size)]
def unite(self, x, y, w):
rx = self.find(x)
ry = self.find(y)
if rx == ry:
return
if self._ranks[rx] > self._ranks[ry]:
self._parents[ry] = rx
self._sizes[rx] += self._sizes[ry]
self._weights[ry] = w + self._weights[x] - self._weights[y]
else:
self._parents[rx] = ry
self._sizes[ry] += self._sizes[rx]
self._weights[rx] = -w + self._weights[y] - self._weights[x]
if self._ranks[rx] == self._ranks[ry]:
self._ranks[ry] += 1
def find(self, x):
if self._parents[x] == x:
return x
root = self.find(self._parents[x])
self._weights[x] += self._weights[self._parents[x]]
self._parents[x] = root
return root
def size(self, x):
return self._sizes[self.find(x)]
def weight(self, x):
"""
:param x:
:return:
"""
self.find(x)
return self._weights[x]
def diff(self, x, y):
if self.find(x) == self.find(y):
return self._weights[y] - self._weights[x]
return float('inf')
def is_same(self,x,y):
if self.find(x) == self.find(y):
return True
else:
return False
n,m=IL()
UF=WeightedUnionFind(n)
for i in range(m):
l,r,d=IL()
if UF.is_same(l-1,r-1) and UF.diff(l-1,r-1)!=d:
print("No")
break
UF.unite(l-1,r-1,d)
else:
print("Yes")
|
s697605711
|
p02612
|
u546165262
| 2,000
| 1,048,576
|
Wrong Answer
| 25
| 9,132
| 66
|
We will buy a product for N yen (the currency of Japan) at a shop. If we use only 1000-yen bills to pay the price, how much change will we receive? Assume we use the minimum number of bills required.
|
n = int(input())
def change(n):
res = n % 1000
return res
|
s981439305
|
Accepted
| 34
| 9,168
| 180
|
N = int(input())
temp = N%1000
if(N > 1000 and temp != 0):
res = 1000 - temp
print(res)
elif (N>1000 and temp == 0):
print(temp)
else:
res = 1000 - N
print(res)
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.