output_description
stringlengths 15
956
| submission_id
stringlengths 10
10
| status
stringclasses 3
values | problem_id
stringlengths 6
6
| input_description
stringlengths 9
2.55k
| attempt
stringlengths 1
13.7k
| problem_description
stringlengths 7
5.24k
| samples
stringlengths 2
2.72k
|
---|---|---|---|---|---|---|---|
If Takahashi can buy the toy, print `Yes`; if he cannot, print `No`.
* * *
|
s461604370
|
Runtime Error
|
p03407
|
Input is given from Standard Input in the following format:
A B C
|
a, b, c = map(int, input().split())
if a + b > c:
Print("Yes")
Else:
Print("No")
|
Statement
An elementary school student Takahashi has come to a variety store.
He has two coins, A-yen and B-yen coins (yen is the currency of Japan), and
wants to buy a toy that costs C yen. Can he buy it?
Note that he lives in Takahashi Kingdom, and may have coins that do not exist
in Japan.
|
[{"input": "50 100 120", "output": "Yes\n \n\nHe has 50 + 100 = 150 yen, so he can buy the 120-yen toy.\n\n* * *"}, {"input": "500 100 1000", "output": "No\n \n\nHe has 500 + 100 = 600 yen, but he cannot buy the 1000-yen toy.\n\n* * *"}, {"input": "19 123 143", "output": "No\n \n\nThere are 19-yen and 123-yen coins in Takahashi Kingdom, which are rather hard\nto use.\n\n* * *"}, {"input": "19 123 142", "output": "Yes"}]
|
If Takahashi can buy the toy, print `Yes`; if he cannot, print `No`.
* * *
|
s111156076
|
Runtime Error
|
p03407
|
Input is given from Standard Input in the following format:
A B C
|
a,b,c=list(map(lambda x:int(x), input().split()))
print("Yes") if a+b>=c else print("No")
|
Statement
An elementary school student Takahashi has come to a variety store.
He has two coins, A-yen and B-yen coins (yen is the currency of Japan), and
wants to buy a toy that costs C yen. Can he buy it?
Note that he lives in Takahashi Kingdom, and may have coins that do not exist
in Japan.
|
[{"input": "50 100 120", "output": "Yes\n \n\nHe has 50 + 100 = 150 yen, so he can buy the 120-yen toy.\n\n* * *"}, {"input": "500 100 1000", "output": "No\n \n\nHe has 500 + 100 = 600 yen, but he cannot buy the 1000-yen toy.\n\n* * *"}, {"input": "19 123 143", "output": "No\n \n\nThere are 19-yen and 123-yen coins in Takahashi Kingdom, which are rather hard\nto use.\n\n* * *"}, {"input": "19 123 142", "output": "Yes"}]
|
If Takahashi can buy the toy, print `Yes`; if he cannot, print `No`.
* * *
|
s708770297
|
Wrong Answer
|
p03407
|
Input is given from Standard Input in the following format:
A B C
|
print(["No", "Yes"][(lambda x: x[0] + x[1] > x[2])(list(map(int, input().split())))])
|
Statement
An elementary school student Takahashi has come to a variety store.
He has two coins, A-yen and B-yen coins (yen is the currency of Japan), and
wants to buy a toy that costs C yen. Can he buy it?
Note that he lives in Takahashi Kingdom, and may have coins that do not exist
in Japan.
|
[{"input": "50 100 120", "output": "Yes\n \n\nHe has 50 + 100 = 150 yen, so he can buy the 120-yen toy.\n\n* * *"}, {"input": "500 100 1000", "output": "No\n \n\nHe has 500 + 100 = 600 yen, but he cannot buy the 1000-yen toy.\n\n* * *"}, {"input": "19 123 143", "output": "No\n \n\nThere are 19-yen and 123-yen coins in Takahashi Kingdom, which are rather hard\nto use.\n\n* * *"}, {"input": "19 123 142", "output": "Yes"}]
|
If Takahashi can buy the toy, print `Yes`; if he cannot, print `No`.
* * *
|
s373396587
|
Runtime Error
|
p03407
|
Input is given from Standard Input in the following format:
A B C
|
a, b, c = map(int, input().split())
if a+b >= c
print("Yes")
else:
print("No")
|
Statement
An elementary school student Takahashi has come to a variety store.
He has two coins, A-yen and B-yen coins (yen is the currency of Japan), and
wants to buy a toy that costs C yen. Can he buy it?
Note that he lives in Takahashi Kingdom, and may have coins that do not exist
in Japan.
|
[{"input": "50 100 120", "output": "Yes\n \n\nHe has 50 + 100 = 150 yen, so he can buy the 120-yen toy.\n\n* * *"}, {"input": "500 100 1000", "output": "No\n \n\nHe has 500 + 100 = 600 yen, but he cannot buy the 1000-yen toy.\n\n* * *"}, {"input": "19 123 143", "output": "No\n \n\nThere are 19-yen and 123-yen coins in Takahashi Kingdom, which are rather hard\nto use.\n\n* * *"}, {"input": "19 123 142", "output": "Yes"}]
|
If Takahashi can buy the toy, print `Yes`; if he cannot, print `No`.
* * *
|
s208603221
|
Runtime Error
|
p03407
|
Input is given from Standard Input in the following format:
A B C
|
n = [ input() for _ in range( int( input() ) )]
m = [ input() for = in range( int( input() ) )]
l = list( set(n) )
print( max(0, max( n.count(l[i]) - m.count(l[i]) for i in range( len(l) ) ) ) )
|
Statement
An elementary school student Takahashi has come to a variety store.
He has two coins, A-yen and B-yen coins (yen is the currency of Japan), and
wants to buy a toy that costs C yen. Can he buy it?
Note that he lives in Takahashi Kingdom, and may have coins that do not exist
in Japan.
|
[{"input": "50 100 120", "output": "Yes\n \n\nHe has 50 + 100 = 150 yen, so he can buy the 120-yen toy.\n\n* * *"}, {"input": "500 100 1000", "output": "No\n \n\nHe has 500 + 100 = 600 yen, but he cannot buy the 1000-yen toy.\n\n* * *"}, {"input": "19 123 143", "output": "No\n \n\nThere are 19-yen and 123-yen coins in Takahashi Kingdom, which are rather hard\nto use.\n\n* * *"}, {"input": "19 123 142", "output": "Yes"}]
|
If Takahashi can buy the toy, print `Yes`; if he cannot, print `No`.
* * *
|
s768941510
|
Runtime Error
|
p03407
|
Input is given from Standard Input in the following format:
A B C
|
a, b, c = (int(i) for i in input().split())
if a + b >= c:
print("Yes")
else:
print("No")5
|
Statement
An elementary school student Takahashi has come to a variety store.
He has two coins, A-yen and B-yen coins (yen is the currency of Japan), and
wants to buy a toy that costs C yen. Can he buy it?
Note that he lives in Takahashi Kingdom, and may have coins that do not exist
in Japan.
|
[{"input": "50 100 120", "output": "Yes\n \n\nHe has 50 + 100 = 150 yen, so he can buy the 120-yen toy.\n\n* * *"}, {"input": "500 100 1000", "output": "No\n \n\nHe has 500 + 100 = 600 yen, but he cannot buy the 1000-yen toy.\n\n* * *"}, {"input": "19 123 143", "output": "No\n \n\nThere are 19-yen and 123-yen coins in Takahashi Kingdom, which are rather hard\nto use.\n\n* * *"}, {"input": "19 123 142", "output": "Yes"}]
|
If Takahashi can buy the toy, print `Yes`; if he cannot, print `No`.
* * *
|
s399856889
|
Runtime Error
|
p03407
|
Input is given from Standard Input in the following format:
A B C
|
a = list(int,input().split())
if a[0] + a[1] >= a[2]:
print("Yes")
else:
print("No")
|
Statement
An elementary school student Takahashi has come to a variety store.
He has two coins, A-yen and B-yen coins (yen is the currency of Japan), and
wants to buy a toy that costs C yen. Can he buy it?
Note that he lives in Takahashi Kingdom, and may have coins that do not exist
in Japan.
|
[{"input": "50 100 120", "output": "Yes\n \n\nHe has 50 + 100 = 150 yen, so he can buy the 120-yen toy.\n\n* * *"}, {"input": "500 100 1000", "output": "No\n \n\nHe has 500 + 100 = 600 yen, but he cannot buy the 1000-yen toy.\n\n* * *"}, {"input": "19 123 143", "output": "No\n \n\nThere are 19-yen and 123-yen coins in Takahashi Kingdom, which are rather hard\nto use.\n\n* * *"}, {"input": "19 123 142", "output": "Yes"}]
|
If Takahashi can buy the toy, print `Yes`; if he cannot, print `No`.
* * *
|
s210724345
|
Runtime Error
|
p03407
|
Input is given from Standard Input in the following format:
A B C
|
A, B, C= list(map(int, input().split()))
if (C<=A+B):
print('Yes')
else:
print('No')
|
Statement
An elementary school student Takahashi has come to a variety store.
He has two coins, A-yen and B-yen coins (yen is the currency of Japan), and
wants to buy a toy that costs C yen. Can he buy it?
Note that he lives in Takahashi Kingdom, and may have coins that do not exist
in Japan.
|
[{"input": "50 100 120", "output": "Yes\n \n\nHe has 50 + 100 = 150 yen, so he can buy the 120-yen toy.\n\n* * *"}, {"input": "500 100 1000", "output": "No\n \n\nHe has 500 + 100 = 600 yen, but he cannot buy the 1000-yen toy.\n\n* * *"}, {"input": "19 123 143", "output": "No\n \n\nThere are 19-yen and 123-yen coins in Takahashi Kingdom, which are rather hard\nto use.\n\n* * *"}, {"input": "19 123 142", "output": "Yes"}]
|
If Takahashi can buy the toy, print `Yes`; if he cannot, print `No`.
* * *
|
s521319614
|
Runtime Error
|
p03407
|
Input is given from Standard Input in the following format:
A B C
|
n = int(input())
sn = [input() for _ in range(n)]
m = int(input())
sm = [input() for _ in range(m)]
l = list(set(sn))
print(max(0, max([sn.count(l[i]) - sm.count(l[i]) for i in range(len(l))])))
|
Statement
An elementary school student Takahashi has come to a variety store.
He has two coins, A-yen and B-yen coins (yen is the currency of Japan), and
wants to buy a toy that costs C yen. Can he buy it?
Note that he lives in Takahashi Kingdom, and may have coins that do not exist
in Japan.
|
[{"input": "50 100 120", "output": "Yes\n \n\nHe has 50 + 100 = 150 yen, so he can buy the 120-yen toy.\n\n* * *"}, {"input": "500 100 1000", "output": "No\n \n\nHe has 500 + 100 = 600 yen, but he cannot buy the 1000-yen toy.\n\n* * *"}, {"input": "19 123 143", "output": "No\n \n\nThere are 19-yen and 123-yen coins in Takahashi Kingdom, which are rather hard\nto use.\n\n* * *"}, {"input": "19 123 142", "output": "Yes"}]
|
If Takahashi can buy the toy, print `Yes`; if he cannot, print `No`.
* * *
|
s721467571
|
Runtime Error
|
p03407
|
Input is given from Standard Input in the following format:
A B C
|
A,B,C = map(int,input().split())
money = A+B
if C>money:
print('No')
else:
print('Yes)
|
Statement
An elementary school student Takahashi has come to a variety store.
He has two coins, A-yen and B-yen coins (yen is the currency of Japan), and
wants to buy a toy that costs C yen. Can he buy it?
Note that he lives in Takahashi Kingdom, and may have coins that do not exist
in Japan.
|
[{"input": "50 100 120", "output": "Yes\n \n\nHe has 50 + 100 = 150 yen, so he can buy the 120-yen toy.\n\n* * *"}, {"input": "500 100 1000", "output": "No\n \n\nHe has 500 + 100 = 600 yen, but he cannot buy the 1000-yen toy.\n\n* * *"}, {"input": "19 123 143", "output": "No\n \n\nThere are 19-yen and 123-yen coins in Takahashi Kingdom, which are rather hard\nto use.\n\n* * *"}, {"input": "19 123 142", "output": "Yes"}]
|
If Takahashi can buy the toy, print `Yes`; if he cannot, print `No`.
* * *
|
s798050171
|
Runtime Error
|
p03407
|
Input is given from Standard Input in the following format:
A B C
|
n = int(input())
sl = list(input() for _ in range(n))
m = int(input())
tl = list(input() for _ in range(m))
sls = set(sl)
ma = 0
for s in sls:
ma = max(ma, sl.count(s) - tl.count(s))
print(ma)
|
Statement
An elementary school student Takahashi has come to a variety store.
He has two coins, A-yen and B-yen coins (yen is the currency of Japan), and
wants to buy a toy that costs C yen. Can he buy it?
Note that he lives in Takahashi Kingdom, and may have coins that do not exist
in Japan.
|
[{"input": "50 100 120", "output": "Yes\n \n\nHe has 50 + 100 = 150 yen, so he can buy the 120-yen toy.\n\n* * *"}, {"input": "500 100 1000", "output": "No\n \n\nHe has 500 + 100 = 600 yen, but he cannot buy the 1000-yen toy.\n\n* * *"}, {"input": "19 123 143", "output": "No\n \n\nThere are 19-yen and 123-yen coins in Takahashi Kingdom, which are rather hard\nto use.\n\n* * *"}, {"input": "19 123 142", "output": "Yes"}]
|
If Takahashi can buy the toy, print `Yes`; if he cannot, print `No`.
* * *
|
s610699988
|
Runtime Error
|
p03407
|
Input is given from Standard Input in the following format:
A B C
|
a = list(map(int,input().split()))
if a[0] + a[1] >= a[2]:
print("Yes")
else:
print("No")
|
Statement
An elementary school student Takahashi has come to a variety store.
He has two coins, A-yen and B-yen coins (yen is the currency of Japan), and
wants to buy a toy that costs C yen. Can he buy it?
Note that he lives in Takahashi Kingdom, and may have coins that do not exist
in Japan.
|
[{"input": "50 100 120", "output": "Yes\n \n\nHe has 50 + 100 = 150 yen, so he can buy the 120-yen toy.\n\n* * *"}, {"input": "500 100 1000", "output": "No\n \n\nHe has 500 + 100 = 600 yen, but he cannot buy the 1000-yen toy.\n\n* * *"}, {"input": "19 123 143", "output": "No\n \n\nThere are 19-yen and 123-yen coins in Takahashi Kingdom, which are rather hard\nto use.\n\n* * *"}, {"input": "19 123 142", "output": "Yes"}]
|
If Takahashi can buy the toy, print `Yes`; if he cannot, print `No`.
* * *
|
s473371209
|
Runtime Error
|
p03407
|
Input is given from Standard Input in the following format:
A B C
|
A, B, C = map(int, input().split())
if (A+B)>=C:
print('Yes')
else:
print('No')
|
Statement
An elementary school student Takahashi has come to a variety store.
He has two coins, A-yen and B-yen coins (yen is the currency of Japan), and
wants to buy a toy that costs C yen. Can he buy it?
Note that he lives in Takahashi Kingdom, and may have coins that do not exist
in Japan.
|
[{"input": "50 100 120", "output": "Yes\n \n\nHe has 50 + 100 = 150 yen, so he can buy the 120-yen toy.\n\n* * *"}, {"input": "500 100 1000", "output": "No\n \n\nHe has 500 + 100 = 600 yen, but he cannot buy the 1000-yen toy.\n\n* * *"}, {"input": "19 123 143", "output": "No\n \n\nThere are 19-yen and 123-yen coins in Takahashi Kingdom, which are rather hard\nto use.\n\n* * *"}, {"input": "19 123 142", "output": "Yes"}]
|
If Takahashi can buy the toy, print `Yes`; if he cannot, print `No`.
* * *
|
s127556753
|
Runtime Error
|
p03407
|
Input is given from Standard Input in the following format:
A B C
|
A,B,C=map(int,input().split())
if A+B=>C:
print('Yes')
else:
print('No')
|
Statement
An elementary school student Takahashi has come to a variety store.
He has two coins, A-yen and B-yen coins (yen is the currency of Japan), and
wants to buy a toy that costs C yen. Can he buy it?
Note that he lives in Takahashi Kingdom, and may have coins that do not exist
in Japan.
|
[{"input": "50 100 120", "output": "Yes\n \n\nHe has 50 + 100 = 150 yen, so he can buy the 120-yen toy.\n\n* * *"}, {"input": "500 100 1000", "output": "No\n \n\nHe has 500 + 100 = 600 yen, but he cannot buy the 1000-yen toy.\n\n* * *"}, {"input": "19 123 143", "output": "No\n \n\nThere are 19-yen and 123-yen coins in Takahashi Kingdom, which are rather hard\nto use.\n\n* * *"}, {"input": "19 123 142", "output": "Yes"}]
|
If Takahashi can buy the toy, print `Yes`; if he cannot, print `No`.
* * *
|
s173832115
|
Runtime Error
|
p03407
|
Input is given from Standard Input in the following format:
A B C
|
a, b, c = map(int, input().split())
if a+b =< c:
print("Yes")
else:
print("No")
|
Statement
An elementary school student Takahashi has come to a variety store.
He has two coins, A-yen and B-yen coins (yen is the currency of Japan), and
wants to buy a toy that costs C yen. Can he buy it?
Note that he lives in Takahashi Kingdom, and may have coins that do not exist
in Japan.
|
[{"input": "50 100 120", "output": "Yes\n \n\nHe has 50 + 100 = 150 yen, so he can buy the 120-yen toy.\n\n* * *"}, {"input": "500 100 1000", "output": "No\n \n\nHe has 500 + 100 = 600 yen, but he cannot buy the 1000-yen toy.\n\n* * *"}, {"input": "19 123 143", "output": "No\n \n\nThere are 19-yen and 123-yen coins in Takahashi Kingdom, which are rather hard\nto use.\n\n* * *"}, {"input": "19 123 142", "output": "Yes"}]
|
If Takahashi can buy the toy, print `Yes`; if he cannot, print `No`.
* * *
|
s651477728
|
Runtime Error
|
p03407
|
Input is given from Standard Input in the following format:
A B C
|
A,B,C = (int,input().split())
if A + B => C :
print("Yes")
else :
print("NO)
|
Statement
An elementary school student Takahashi has come to a variety store.
He has two coins, A-yen and B-yen coins (yen is the currency of Japan), and
wants to buy a toy that costs C yen. Can he buy it?
Note that he lives in Takahashi Kingdom, and may have coins that do not exist
in Japan.
|
[{"input": "50 100 120", "output": "Yes\n \n\nHe has 50 + 100 = 150 yen, so he can buy the 120-yen toy.\n\n* * *"}, {"input": "500 100 1000", "output": "No\n \n\nHe has 500 + 100 = 600 yen, but he cannot buy the 1000-yen toy.\n\n* * *"}, {"input": "19 123 143", "output": "No\n \n\nThere are 19-yen and 123-yen coins in Takahashi Kingdom, which are rather hard\nto use.\n\n* * *"}, {"input": "19 123 142", "output": "Yes"}]
|
If Takahashi can buy the toy, print `Yes`; if he cannot, print `No`.
* * *
|
s015080298
|
Runtime Error
|
p03407
|
Input is given from Standard Input in the following format:
A B C
|
A,B,C = (int,input().split())
if A + B => C :
print("Yes")
else :
print("No")
|
Statement
An elementary school student Takahashi has come to a variety store.
He has two coins, A-yen and B-yen coins (yen is the currency of Japan), and
wants to buy a toy that costs C yen. Can he buy it?
Note that he lives in Takahashi Kingdom, and may have coins that do not exist
in Japan.
|
[{"input": "50 100 120", "output": "Yes\n \n\nHe has 50 + 100 = 150 yen, so he can buy the 120-yen toy.\n\n* * *"}, {"input": "500 100 1000", "output": "No\n \n\nHe has 500 + 100 = 600 yen, but he cannot buy the 1000-yen toy.\n\n* * *"}, {"input": "19 123 143", "output": "No\n \n\nThere are 19-yen and 123-yen coins in Takahashi Kingdom, which are rather hard\nto use.\n\n* * *"}, {"input": "19 123 142", "output": "Yes"}]
|
If Takahashi can buy the toy, print `Yes`; if he cannot, print `No`.
* * *
|
s714378740
|
Wrong Answer
|
p03407
|
Input is given from Standard Input in the following format:
A B C
|
print("hello,world")
|
Statement
An elementary school student Takahashi has come to a variety store.
He has two coins, A-yen and B-yen coins (yen is the currency of Japan), and
wants to buy a toy that costs C yen. Can he buy it?
Note that he lives in Takahashi Kingdom, and may have coins that do not exist
in Japan.
|
[{"input": "50 100 120", "output": "Yes\n \n\nHe has 50 + 100 = 150 yen, so he can buy the 120-yen toy.\n\n* * *"}, {"input": "500 100 1000", "output": "No\n \n\nHe has 500 + 100 = 600 yen, but he cannot buy the 1000-yen toy.\n\n* * *"}, {"input": "19 123 143", "output": "No\n \n\nThere are 19-yen and 123-yen coins in Takahashi Kingdom, which are rather hard\nto use.\n\n* * *"}, {"input": "19 123 142", "output": "Yes"}]
|
If Takahashi can buy the toy, print `Yes`; if he cannot, print `No`.
* * *
|
s293249134
|
Runtime Error
|
p03407
|
Input is given from Standard Input in the following format:
A B C
|
a, b, c = map(int,input().split())
if (a + b) >= C:
print("Yes")
else:
print("No")
|
Statement
An elementary school student Takahashi has come to a variety store.
He has two coins, A-yen and B-yen coins (yen is the currency of Japan), and
wants to buy a toy that costs C yen. Can he buy it?
Note that he lives in Takahashi Kingdom, and may have coins that do not exist
in Japan.
|
[{"input": "50 100 120", "output": "Yes\n \n\nHe has 50 + 100 = 150 yen, so he can buy the 120-yen toy.\n\n* * *"}, {"input": "500 100 1000", "output": "No\n \n\nHe has 500 + 100 = 600 yen, but he cannot buy the 1000-yen toy.\n\n* * *"}, {"input": "19 123 143", "output": "No\n \n\nThere are 19-yen and 123-yen coins in Takahashi Kingdom, which are rather hard\nto use.\n\n* * *"}, {"input": "19 123 142", "output": "Yes"}]
|
If Takahashi can buy the toy, print `Yes`; if he cannot, print `No`.
* * *
|
s472467275
|
Runtime Error
|
p03407
|
Input is given from Standard Input in the following format:
A B C
|
a, b, c = map(int,input().split())
if (a + b) <= C:
print("Yes")
else:
print("No")
|
Statement
An elementary school student Takahashi has come to a variety store.
He has two coins, A-yen and B-yen coins (yen is the currency of Japan), and
wants to buy a toy that costs C yen. Can he buy it?
Note that he lives in Takahashi Kingdom, and may have coins that do not exist
in Japan.
|
[{"input": "50 100 120", "output": "Yes\n \n\nHe has 50 + 100 = 150 yen, so he can buy the 120-yen toy.\n\n* * *"}, {"input": "500 100 1000", "output": "No\n \n\nHe has 500 + 100 = 600 yen, but he cannot buy the 1000-yen toy.\n\n* * *"}, {"input": "19 123 143", "output": "No\n \n\nThere are 19-yen and 123-yen coins in Takahashi Kingdom, which are rather hard\nto use.\n\n* * *"}, {"input": "19 123 142", "output": "Yes"}]
|
If Takahashi can buy the toy, print `Yes`; if he cannot, print `No`.
* * *
|
s886317304
|
Accepted
|
p03407
|
Input is given from Standard Input in the following format:
A B C
|
# -*- coding: utf-8 -*-
import sys
import itertools # これは色々使える組み込み関数みたいなやつ
import math # 数学的計算はこれでいける。普通に0.5乗しても計算可能
# w=input()
i = 0
j = 0
s = 0
eq = ""
A, B, C = map(int, input().split())
# A,B,Cを分けて入力しかも一行で
# N=int(input())
# Nori=N
# D, N=input().split()
# S=input()
D = 0
D = A + B
if D >= C:
print("Yes")
sys.exit()
print("No")
def change(i):
return int(i)
# S_list=list(S)
numberlist = []
numberlist = list(map(change, numberlist))
keisanlist = sorted(numberlist, reverse=True)
# M=int(input())
# drink_list = [list(map(int, input().split(" ")))for i in range(M)]
# print(T_list[1])
# D=int(D)
# N=int(N)
# 不本意だが内包表記で二次元の空のリストを作成する
# dp=[['' for i in range(2)] for j in range(N)]
# absTH=[''for i in range(N)]
# K=int(K)
# S_list=[]
# sentence_list=[]
# total=0
# mojiretu=""
# センテンスを暗記するのではなく、まずinput()を書いて、膨らます感じで記述する。すると#思考の流れ通りに書ける。素晴らしい!
# for i in range(K):
# ID_list.append(i+1)
# print(ID_list)
# for i in range(H)
# この下の行が二次元リストの読み込
# intを消して記号を読み込めるようにしたしかしこれでは文字列から読み込んでいるのと同じ
# weight_value_list = [list(input())for i in range(N)]#一文字づつばらして入れてしまう
# s = [input() for i in range(N)]
# 複数行に複数の入力値を取得し、出力する
# sentence_list = (list(input())for i in range(N))
# for i in range(H):
# ppixel_list=list(input())
# print(pixel_list)
# high_pixel_list =[['' for i in range(W)]for j in range(2*H)]
# print(high_pixel_list)
# print(pixel_list[0][1])#行 列の順番にかっこが並んでいる
# print(a_list)
first_term = 0
second_term = 0
# 整数二次元配列を読み込む時のやり方
# a_b_c_list = [list(map(int, input().split(" ")))for i in range(N)]
# センテンスを暗記するのではなく、まずinput()を書いて、膨らます感じで記述する。すると#思考の流れ通りに書ける。素晴らしい!
# x, y = [0]*N, [0]*N#N個の空のリストを作成
# l = list(range(N))#範囲がNのリストを作成する
# for i in range(N):
# x[i], y[i] = map(int, input().split())
# 分けて入力する形式を設定することで可読性が高く仕上がっている
# 素晴らしいことだ
distance = 0
# comb = list(itertools.permutations(l))
# prmutation:英語の意味としては順列である
"""p[, r]で
長さrのタプル列、重複なしのあらゆる並びを表す
今回はリストlの重複なしの並び替え順序を新たなリストに収納している
並び方を計算しリストに収納しているイメージ
l[0,1,2]
l[0,2,1]これにもリスト番号が0,1,2と割り振られている
これが全通り入っている
これ作った人はすごい
自分も早く理解したい
"""
# for i in range(0, len(comb)):#i番目のパターンの時を考える。
# for j in range(0, N-1):#lのリスト番号を読み込み
# distance += math.sqrt((x[comb[i][j]]-x[comb[i][j+1]])**2 + (y[comb[i][j]]-y[comb[i][j+1]])**2)
"""
各経路の距離を足していき全距離分を経路数
で割れば平均距離が出るので各経路ごとの距離は
不必要と判断されている。
"""
# print(distance/len(comb))
# dp[i+1][j]=max(dp[i][j]+a_b_c_list[i],dp[i][j],dp[i][j])
# リストを一周するようにすればいいのか
|
Statement
An elementary school student Takahashi has come to a variety store.
He has two coins, A-yen and B-yen coins (yen is the currency of Japan), and
wants to buy a toy that costs C yen. Can he buy it?
Note that he lives in Takahashi Kingdom, and may have coins that do not exist
in Japan.
|
[{"input": "50 100 120", "output": "Yes\n \n\nHe has 50 + 100 = 150 yen, so he can buy the 120-yen toy.\n\n* * *"}, {"input": "500 100 1000", "output": "No\n \n\nHe has 500 + 100 = 600 yen, but he cannot buy the 1000-yen toy.\n\n* * *"}, {"input": "19 123 143", "output": "No\n \n\nThere are 19-yen and 123-yen coins in Takahashi Kingdom, which are rather hard\nto use.\n\n* * *"}, {"input": "19 123 142", "output": "Yes"}]
|
If Takahashi can buy the toy, print `Yes`; if he cannot, print `No`.
* * *
|
s769195732
|
Runtime Error
|
p03407
|
Input is given from Standard Input in the following format:
A B C
|
A, B, C = map(int,input().split())
if A + B => C :
print("Yes")
else :
print("No")
|
Statement
An elementary school student Takahashi has come to a variety store.
He has two coins, A-yen and B-yen coins (yen is the currency of Japan), and
wants to buy a toy that costs C yen. Can he buy it?
Note that he lives in Takahashi Kingdom, and may have coins that do not exist
in Japan.
|
[{"input": "50 100 120", "output": "Yes\n \n\nHe has 50 + 100 = 150 yen, so he can buy the 120-yen toy.\n\n* * *"}, {"input": "500 100 1000", "output": "No\n \n\nHe has 500 + 100 = 600 yen, but he cannot buy the 1000-yen toy.\n\n* * *"}, {"input": "19 123 143", "output": "No\n \n\nThere are 19-yen and 123-yen coins in Takahashi Kingdom, which are rather hard\nto use.\n\n* * *"}, {"input": "19 123 142", "output": "Yes"}]
|
If Takahashi can buy the toy, print `Yes`; if he cannot, print `No`.
* * *
|
s693557854
|
Runtime Error
|
p03407
|
Input is given from Standard Input in the following format:
A B C
|
a, b, c = [map(int, input().split())]
print("Yes" if a >= c or b >= c or a + b >= c else "No")
|
Statement
An elementary school student Takahashi has come to a variety store.
He has two coins, A-yen and B-yen coins (yen is the currency of Japan), and
wants to buy a toy that costs C yen. Can he buy it?
Note that he lives in Takahashi Kingdom, and may have coins that do not exist
in Japan.
|
[{"input": "50 100 120", "output": "Yes\n \n\nHe has 50 + 100 = 150 yen, so he can buy the 120-yen toy.\n\n* * *"}, {"input": "500 100 1000", "output": "No\n \n\nHe has 500 + 100 = 600 yen, but he cannot buy the 1000-yen toy.\n\n* * *"}, {"input": "19 123 143", "output": "No\n \n\nThere are 19-yen and 123-yen coins in Takahashi Kingdom, which are rather hard\nto use.\n\n* * *"}, {"input": "19 123 142", "output": "Yes"}]
|
If Takahashi can buy the toy, print `Yes`; if he cannot, print `No`.
* * *
|
s535877939
|
Runtime Error
|
p03407
|
Input is given from Standard Input in the following format:
A B C
|
a=int(input())
b=int(input())
c=int(input())
if(a+b>c) print("Yes")
else print("No")
|
Statement
An elementary school student Takahashi has come to a variety store.
He has two coins, A-yen and B-yen coins (yen is the currency of Japan), and
wants to buy a toy that costs C yen. Can he buy it?
Note that he lives in Takahashi Kingdom, and may have coins that do not exist
in Japan.
|
[{"input": "50 100 120", "output": "Yes\n \n\nHe has 50 + 100 = 150 yen, so he can buy the 120-yen toy.\n\n* * *"}, {"input": "500 100 1000", "output": "No\n \n\nHe has 500 + 100 = 600 yen, but he cannot buy the 1000-yen toy.\n\n* * *"}, {"input": "19 123 143", "output": "No\n \n\nThere are 19-yen and 123-yen coins in Takahashi Kingdom, which are rather hard\nto use.\n\n* * *"}, {"input": "19 123 142", "output": "Yes"}]
|
If Takahashi can buy the toy, print `Yes`; if he cannot, print `No`.
* * *
|
s364762576
|
Runtime Error
|
p03407
|
Input is given from Standard Input in the following format:
A B C
|
a,b,c = map(int,input().split())
if a+b <= c:
print("Yes)
else:
print("No")
|
Statement
An elementary school student Takahashi has come to a variety store.
He has two coins, A-yen and B-yen coins (yen is the currency of Japan), and
wants to buy a toy that costs C yen. Can he buy it?
Note that he lives in Takahashi Kingdom, and may have coins that do not exist
in Japan.
|
[{"input": "50 100 120", "output": "Yes\n \n\nHe has 50 + 100 = 150 yen, so he can buy the 120-yen toy.\n\n* * *"}, {"input": "500 100 1000", "output": "No\n \n\nHe has 500 + 100 = 600 yen, but he cannot buy the 1000-yen toy.\n\n* * *"}, {"input": "19 123 143", "output": "No\n \n\nThere are 19-yen and 123-yen coins in Takahashi Kingdom, which are rather hard\nto use.\n\n* * *"}, {"input": "19 123 142", "output": "Yes"}]
|
If Takahashi can buy the toy, print `Yes`; if he cannot, print `No`.
* * *
|
s909619065
|
Runtime Error
|
p03407
|
Input is given from Standard Input in the following format:
A B C
|
A,B,C = map(int, input().split())
if A+B >= C:
print('Yes')
else:
print('No)
|
Statement
An elementary school student Takahashi has come to a variety store.
He has two coins, A-yen and B-yen coins (yen is the currency of Japan), and
wants to buy a toy that costs C yen. Can he buy it?
Note that he lives in Takahashi Kingdom, and may have coins that do not exist
in Japan.
|
[{"input": "50 100 120", "output": "Yes\n \n\nHe has 50 + 100 = 150 yen, so he can buy the 120-yen toy.\n\n* * *"}, {"input": "500 100 1000", "output": "No\n \n\nHe has 500 + 100 = 600 yen, but he cannot buy the 1000-yen toy.\n\n* * *"}, {"input": "19 123 143", "output": "No\n \n\nThere are 19-yen and 123-yen coins in Takahashi Kingdom, which are rather hard\nto use.\n\n* * *"}, {"input": "19 123 142", "output": "Yes"}]
|
If "it" can catch the other child, print `YES`; otherwise, print `NO`.
* * *
|
s704303296
|
Wrong Answer
|
p02646
|
Input is given from Standard Input in the following format:
A V
B W
T
|
rd = lambda: map(int, input().split())
a, v = rd()
b, w = rd()
if b < a:
a, b, v, w = -a, -b, -v, -w
print("YES" if int(input()) * (v - w) >= b - a else "NO")
|
Statement
Two children are playing tag on a number line. (In the game of tag, the child
called "it" tries to catch the other child.) The child who is "it" is now at
coordinate A, and he can travel the distance of V per second. The other child
is now at coordinate B, and she can travel the distance of W per second.
He can catch her when his coordinate is the same as hers. Determine whether he
can catch her within T seconds (including exactly T seconds later). We assume
that both children move optimally.
|
[{"input": "1 2\n 3 1\n 3", "output": "YES\n \n\n* * *"}, {"input": "1 2\n 3 2\n 3", "output": "NO\n \n\n* * *"}, {"input": "1 2\n 3 3\n 3", "output": "NO"}]
|
If "it" can catch the other child, print `YES`; otherwise, print `NO`.
* * *
|
s908758639
|
Wrong Answer
|
p02646
|
Input is given from Standard Input in the following format:
A V
B W
T
|
print("YES")
|
Statement
Two children are playing tag on a number line. (In the game of tag, the child
called "it" tries to catch the other child.) The child who is "it" is now at
coordinate A, and he can travel the distance of V per second. The other child
is now at coordinate B, and she can travel the distance of W per second.
He can catch her when his coordinate is the same as hers. Determine whether he
can catch her within T seconds (including exactly T seconds later). We assume
that both children move optimally.
|
[{"input": "1 2\n 3 1\n 3", "output": "YES\n \n\n* * *"}, {"input": "1 2\n 3 2\n 3", "output": "NO\n \n\n* * *"}, {"input": "1 2\n 3 3\n 3", "output": "NO"}]
|
If "it" can catch the other child, print `YES`; otherwise, print `NO`.
* * *
|
s303358743
|
Wrong Answer
|
p02646
|
Input is given from Standard Input in the following format:
A V
B W
T
|
a, v = map(int, input().split(" "))
b, w = map(int, input().split(" "))
t = int(input())
r = "NO"
if b - a <= abs(w * t - v * t):
r = "YES"
print(r)
|
Statement
Two children are playing tag on a number line. (In the game of tag, the child
called "it" tries to catch the other child.) The child who is "it" is now at
coordinate A, and he can travel the distance of V per second. The other child
is now at coordinate B, and she can travel the distance of W per second.
He can catch her when his coordinate is the same as hers. Determine whether he
can catch her within T seconds (including exactly T seconds later). We assume
that both children move optimally.
|
[{"input": "1 2\n 3 1\n 3", "output": "YES\n \n\n* * *"}, {"input": "1 2\n 3 2\n 3", "output": "NO\n \n\n* * *"}, {"input": "1 2\n 3 3\n 3", "output": "NO"}]
|
Print the integer written into the block of step 1.
* * *
|
s809860632
|
Wrong Answer
|
p03954
|
The input is given from Standard Input in the following format:
N
a_1 a_2 ... a_{2N-1}
|
# editorial
# ある数以下、以上が連続していればそれが保持
n = int(input())
(*a,) = map(int, input().split())
mx = 2 * n + 1
mn = 0
while mx - mn > 1:
mid = (mx + mn) // 2
for i in range(n - 1):
if (a[n + i - 1] >= mid & a[n + i] >= mid) | (
a[n - i - 1] >= mid & a[n - 2 - i] >= mid
):
mn = mid
break
if (a[n + i - 1] < mid & a[n + i] < mid) | (
a[n - i - 1] < mid & a[n - 2 - i] < mid
):
mx = mid
break
mx = mid
print(mn)
|
Statement
We have a pyramid with N steps, built with blocks. The steps are numbered 1
through N from top to bottom. For each 1≤i≤N, step i consists of 2i-1 blocks
aligned horizontally. The pyramid is built so that the blocks at the centers
of the steps are aligned vertically.

A pyramid with N=4 steps
Snuke wrote a permutation of (1, 2, ..., 2N-1) into the blocks of step N.
Then, he wrote integers into all remaining blocks, under the following rule:
* The integer written into a block b must be equal to the median of the three integers written into the three blocks directly under b, or to the lower left or lower right of b.

Writing integers into the blocks
Afterwards, he erased all integers written into the blocks. Now, he only
remembers that the permutation written into the blocks of step N was (a_1,
a_2, ..., a_{2N-1}).
Find the integer written into the block of step 1.
|
[{"input": "4\n 1 6 3 7 4 5 2", "output": "4\n \n\nThis case corresponds to the figure in the problem statement.\n\n* * *"}, {"input": "2\n 1 2 3", "output": "2"}]
|
Print the integer written into the block of step 1.
* * *
|
s392404904
|
Wrong Answer
|
p03954
|
The input is given from Standard Input in the following format:
N
a_1 a_2 ... a_{2N-1}
|
N = int(input())
a = list(map(int, input().split()))
def cond(n):
L = (0, -1)
for i in range(1, N):
if a[i] >= n and a[i - 1] >= n:
L = (i, 1)
elif a[i] < n and a[i - 1] < n:
L = (i, 0)
R = (2 * N - 1, -1)
for i in range(2 * N - 3, N - 2, -1):
if a[i] >= n and a[i + 1] >= n:
R = (i, 1)
elif a[i] < n and a[i + 1] < n:
R = (i, 0)
if L[1] == -1 and R[1] == -1:
return a[0] >= n
elif L[1] == -1:
return R[1] == 1
elif R[1] == -1:
return L[1] == 1
else:
if L[1] == 0:
return N - 1 - L[0] > R[0] - (N - 1)
else:
return N - 1 - L[0] < R[0] - (N - 1)
start = 1
end = 2 * N - 1
while end - start > 1:
test = (end + start) // 2
if cond(test):
start = test
else:
end = test
if cond(end):
print(end)
else:
print(start)
|
Statement
We have a pyramid with N steps, built with blocks. The steps are numbered 1
through N from top to bottom. For each 1≤i≤N, step i consists of 2i-1 blocks
aligned horizontally. The pyramid is built so that the blocks at the centers
of the steps are aligned vertically.

A pyramid with N=4 steps
Snuke wrote a permutation of (1, 2, ..., 2N-1) into the blocks of step N.
Then, he wrote integers into all remaining blocks, under the following rule:
* The integer written into a block b must be equal to the median of the three integers written into the three blocks directly under b, or to the lower left or lower right of b.

Writing integers into the blocks
Afterwards, he erased all integers written into the blocks. Now, he only
remembers that the permutation written into the blocks of step N was (a_1,
a_2, ..., a_{2N-1}).
Find the integer written into the block of step 1.
|
[{"input": "4\n 1 6 3 7 4 5 2", "output": "4\n \n\nThis case corresponds to the figure in the problem statement.\n\n* * *"}, {"input": "2\n 1 2 3", "output": "2"}]
|
Print the integer written into the block of step 1.
* * *
|
s766331923
|
Wrong Answer
|
p03954
|
The input is given from Standard Input in the following format:
N
a_1 a_2 ... a_{2N-1}
|
n = int(input())
print(n)
|
Statement
We have a pyramid with N steps, built with blocks. The steps are numbered 1
through N from top to bottom. For each 1≤i≤N, step i consists of 2i-1 blocks
aligned horizontally. The pyramid is built so that the blocks at the centers
of the steps are aligned vertically.

A pyramid with N=4 steps
Snuke wrote a permutation of (1, 2, ..., 2N-1) into the blocks of step N.
Then, he wrote integers into all remaining blocks, under the following rule:
* The integer written into a block b must be equal to the median of the three integers written into the three blocks directly under b, or to the lower left or lower right of b.

Writing integers into the blocks
Afterwards, he erased all integers written into the blocks. Now, he only
remembers that the permutation written into the blocks of step N was (a_1,
a_2, ..., a_{2N-1}).
Find the integer written into the block of step 1.
|
[{"input": "4\n 1 6 3 7 4 5 2", "output": "4\n \n\nThis case corresponds to the figure in the problem statement.\n\n* * *"}, {"input": "2\n 1 2 3", "output": "2"}]
|
Print the integer written into the block of step 1.
* * *
|
s553288610
|
Wrong Answer
|
p03954
|
The input is given from Standard Input in the following format:
N
a_1 a_2 ... a_{2N-1}
|
def examA():
N = I()
S = SI()
T = SI()
ans = 2 * N
for l in range(N - 1, -1, -1):
flag = True
for i in range(l + 1):
if S[N - 1 - i] != T[l - i]:
flag = False
break
if flag:
ans -= l + 1
break
print(ans)
return
def examB():
N, x = LI()
d = defaultdict(bool)
if x == 1 or x == 2 * N - 1:
print("No")
return
print("Yes")
ans = [0] * (2 * N - 1)
ans[N - 1] = x
d[x] = True
ans[N] = x + 1
ans[N - 2] = x - 1
d[x + 1] = True
d[x - 1] = True
# print(d); print(ans)
cur = 1
for j in range(N - 2):
while d[cur]:
cur += 1
ans[j] = cur
cur += 1
for j in range(N + 1, 2 * N - 1):
while d[cur]:
cur += 1
ans[j] = cur
cur += 1
for v in ans:
print(v)
return
def examD():
N = I()
A = LI()
next = [0] * (2 * N - 3)
for i in range(1, 2 * N - 2):
cur = [A[i - 1], A[i], A[i + 1]]
cur.sort()
next[i - 1] = cur[1]
ans = next[2 * N - 4]
print(ans)
return
import sys, copy, bisect, itertools, heapq, math
from heapq import heappop, heappush, heapify
from collections import Counter, defaultdict, deque
def I():
return int(sys.stdin.readline())
def LI():
return list(map(int, sys.stdin.readline().split()))
def LSI():
return list(map(str, sys.stdin.readline().split()))
def LS():
return sys.stdin.readline().split()
def SI():
return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float("inf")
if __name__ == "__main__":
examD()
|
Statement
We have a pyramid with N steps, built with blocks. The steps are numbered 1
through N from top to bottom. For each 1≤i≤N, step i consists of 2i-1 blocks
aligned horizontally. The pyramid is built so that the blocks at the centers
of the steps are aligned vertically.

A pyramid with N=4 steps
Snuke wrote a permutation of (1, 2, ..., 2N-1) into the blocks of step N.
Then, he wrote integers into all remaining blocks, under the following rule:
* The integer written into a block b must be equal to the median of the three integers written into the three blocks directly under b, or to the lower left or lower right of b.

Writing integers into the blocks
Afterwards, he erased all integers written into the blocks. Now, he only
remembers that the permutation written into the blocks of step N was (a_1,
a_2, ..., a_{2N-1}).
Find the integer written into the block of step 1.
|
[{"input": "4\n 1 6 3 7 4 5 2", "output": "4\n \n\nThis case corresponds to the figure in the problem statement.\n\n* * *"}, {"input": "2\n 1 2 3", "output": "2"}]
|
Print the integer written into the block of step 1.
* * *
|
s269056603
|
Runtime Error
|
p03954
|
The input is given from Standard Input in the following format:
N
a_1 a_2 ... a_{2N-1}
|
import math
from functools import reduce
from collections import deque
import sys
sys.setrecursionlimit(10**7)
from statistics import median
def s(generator, splitter, mapper):
return [mapper(s) for s in generator().split(splitter)]
# スペース区切りの入力を読み込んで数値リストにして返します。
def get_nums_l():
return [int(s) for s in input().split(" ")]
# 改行区切りの入力をn行読み込んで数値リストにして返します。
def get_nums_n(n):
return [int(input()) for _ in range(n)]
n = int(input())
nums = get_nums_l()
while len(nums) > 1:
print(nums)
new_nums = []
for i in range(1, len(nums) - 1):
new_nums.append(median(nums[i - 1 : i + 2]))
nums = new_nums
print(nums[0])
|
Statement
We have a pyramid with N steps, built with blocks. The steps are numbered 1
through N from top to bottom. For each 1≤i≤N, step i consists of 2i-1 blocks
aligned horizontally. The pyramid is built so that the blocks at the centers
of the steps are aligned vertically.

A pyramid with N=4 steps
Snuke wrote a permutation of (1, 2, ..., 2N-1) into the blocks of step N.
Then, he wrote integers into all remaining blocks, under the following rule:
* The integer written into a block b must be equal to the median of the three integers written into the three blocks directly under b, or to the lower left or lower right of b.

Writing integers into the blocks
Afterwards, he erased all integers written into the blocks. Now, he only
remembers that the permutation written into the blocks of step N was (a_1,
a_2, ..., a_{2N-1}).
Find the integer written into the block of step 1.
|
[{"input": "4\n 1 6 3 7 4 5 2", "output": "4\n \n\nThis case corresponds to the figure in the problem statement.\n\n* * *"}, {"input": "2\n 1 2 3", "output": "2"}]
|
Print the integer written into the block of step 1.
* * *
|
s781529079
|
Wrong Answer
|
p03954
|
The input is given from Standard Input in the following format:
N
a_1 a_2 ... a_{2N-1}
|
n = int(input())
A = list(map(int, input().split()))
l = 1
r = 2 * n
while l < r - 1:
mid = (l + r) // 2
B = []
C = []
for i in range(0, 2 * n - 1):
B.append(A[i] >= mid)
C.append(0)
for i in range(1, 2 * n - 1):
if B[i - 1] == B[i]:
C[i] = 1
for i in range(0, 2 * n - 2):
if B[i + 1] == B[i]:
C[i] = 1
mi = 2 * n
ans = False
for i in range(0, 2 * n - 1):
if C[i] == 1:
if abs(i - n + 1) < mi:
mi = abs(i - n + 1)
ans = B[i]
if ans == True:
l = mid
else:
r = mid
print(l)
|
Statement
We have a pyramid with N steps, built with blocks. The steps are numbered 1
through N from top to bottom. For each 1≤i≤N, step i consists of 2i-1 blocks
aligned horizontally. The pyramid is built so that the blocks at the centers
of the steps are aligned vertically.

A pyramid with N=4 steps
Snuke wrote a permutation of (1, 2, ..., 2N-1) into the blocks of step N.
Then, he wrote integers into all remaining blocks, under the following rule:
* The integer written into a block b must be equal to the median of the three integers written into the three blocks directly under b, or to the lower left or lower right of b.

Writing integers into the blocks
Afterwards, he erased all integers written into the blocks. Now, he only
remembers that the permutation written into the blocks of step N was (a_1,
a_2, ..., a_{2N-1}).
Find the integer written into the block of step 1.
|
[{"input": "4\n 1 6 3 7 4 5 2", "output": "4\n \n\nThis case corresponds to the figure in the problem statement.\n\n* * *"}, {"input": "2\n 1 2 3", "output": "2"}]
|
Print the integer written into the block of step 1.
* * *
|
s743931970
|
Wrong Answer
|
p03954
|
The input is given from Standard Input in the following format:
N
a_1 a_2 ... a_{2N-1}
|
N = int(input())
A = list(map(int, input().split()))
z = (2 * N - 1) // 2 - 1
left = sorted(A[:-2])[z]
center = sorted(A[1:-1])[z]
right = sorted(A[2:])[z]
ans = sorted([left, center, right])[1]
print(ans)
|
Statement
We have a pyramid with N steps, built with blocks. The steps are numbered 1
through N from top to bottom. For each 1≤i≤N, step i consists of 2i-1 blocks
aligned horizontally. The pyramid is built so that the blocks at the centers
of the steps are aligned vertically.

A pyramid with N=4 steps
Snuke wrote a permutation of (1, 2, ..., 2N-1) into the blocks of step N.
Then, he wrote integers into all remaining blocks, under the following rule:
* The integer written into a block b must be equal to the median of the three integers written into the three blocks directly under b, or to the lower left or lower right of b.

Writing integers into the blocks
Afterwards, he erased all integers written into the blocks. Now, he only
remembers that the permutation written into the blocks of step N was (a_1,
a_2, ..., a_{2N-1}).
Find the integer written into the block of step 1.
|
[{"input": "4\n 1 6 3 7 4 5 2", "output": "4\n \n\nThis case corresponds to the figure in the problem statement.\n\n* * *"}, {"input": "2\n 1 2 3", "output": "2"}]
|
Print Q lines. In the i-th line print the value of S after the i-th query,
modulo 998,244,353.
* * *
|
s563599913
|
Wrong Answer
|
p02538
|
Input is given from Standard Input in the following format:
N Q
L_1 R_1 D_1
:
L_Q R_Q D_Q
|
# class化。
import sys
input = sys.stdin.buffer.readline
mod = 998244353
max_n = 2 * pow(10, 5) + 10
pow_list = [1] * max_n
cum_pow = [0] * max_n
cum_pow[0] = 1
for i in range(1, max_n):
pow_list[i] = pow_list[i - 1] * 10
pow_list[i] %= mod
cum_pow[i] += cum_pow[i - 1] + pow_list[i]
cum_pow[i] %= mod
cum_pow = [0] + cum_pow
class LazySegmentTree:
# funcはseg同士、calcはpoint計算
def __init__(self, n, ele, lazy_ele, mod=mod):
self.n = n
self.ele = ele
self.lazy_ele = lazy_ele
self.num = 2 ** ((self.n - 1).bit_length())
self.SEG = [self.ele] * (2 * self.num)
self.LAZY = [self.lazy_ele] * (2 * self.num)
self.node = [1] * (2 * self.num)
for i in reversed(range(1, self.num)):
self.node[i] = self.node[2 * i] + self.node[2 * i + 1]
# SEG同士の計算
def func(self, a, b, b_idx):
# print(a, b, a_idx, b_idx)
node_num = self.node[b_idx]
return (a * pow_list[node_num] + b) % mod
# LAZYをSEGに作用
def calc(self, idx):
if self.LAZY[idx] == -1:
return self.SEG[idx]
node_num = self.node[idx]
res = (self.LAZY[idx] * cum_pow[node_num]) % mod
return res
# LAZY同士の作用の蓄積
def lazy_func(self, a, b):
return b
# 配列で初期化
def initialize(self, A):
for i, val in enumerate(A):
i += self.num
self.SEG[i] = val
for i in reversed(range(1, self.num)):
self.SEG[i] = self.func(self.SEG[2 * i], self.SEG[2 * i + 1], 2 * i)
# LAZYの値を1つ下に伝播して初期化
def propagate_point(self, idx):
self.SEG[idx] = self.calc(idx)
# print(idx)
if self.LAZY[idx] >= 0:
self.LAZY[2 * idx] = self.lazy_func(self.LAZY[2 * idx], self.LAZY[idx])
self.LAZY[2 * idx + 1] = self.lazy_func(
self.LAZY[2 * idx + 1], self.LAZY[idx]
)
self.LAZY[idx] = lazy_ele
# idx=1からidxの直上まで、伝播を行う
def propagate_above(self, idx):
height = idx.bit_length() - 1
# print(idx, height)
for h in reversed(range(1, height + 1)):
self.propagate_point(idx >> h)
# そのidxの直上の値を計算
def recalc_above(self, idx):
# print("ra", idx)
while idx > 1:
idx //= 2
self.SEG[idx] = self.func(
self.calc(2 * idx),
self.calc(2 * idx + 1),
2 * idx,
)
# 1点更新
def update_point(self, idx):
idx += self.num
while idx > 0:
idx //= 2
self.SEG[idx] = self.func(
self.calc(self.SEG[2 * idx]),
self.calc(self.SEG[2 * idx + 1]),
2 * idx,
)
# 範囲更新
def update_range(self, left, right, mono):
left += self.num
right += self.num
left_temp = left // (left & -left)
right_temp = right // (right & -right) - 1
self.propagate_above(left_temp)
self.propagate_above(right_temp)
while left < right:
if left & 1:
self.LAZY[left] = self.lazy_func(self.LAZY[left], mono)
left += 1
if right & 1:
right -= 1
self.LAZY[right] = self.lazy_func(self.LAZY[right], mono)
left //= 2
right //= 2
self.recalc_above(left_temp)
self.recalc_above(right_temp)
# 範囲取得
def get_range(self, left, right):
left += self.num
right += self.num
self.propagate_above(left // (left & -left))
self.propagate_above(right // (right & -right) - 1)
res_left = self.ele
res_right = self.ele
while left < right:
if left & 1:
res_left = self.func(res_left, self.calc(left), left)
left += 1
if right & 1:
right -= 1
res_right = self.func(self.calc(right), res_right, right)
left //= 2
right //= 2
return self.func(res_right, res_left, self.n // 2) % mod
# def get_point(self, idx):
# a,b=self.LAZY[idx]>>32, self.LAZY[idx]&(1<<32-1)
# return a*self.SEG[idx]+b*self.node[idx]
ele = 0
lazy_ele = -1
n, q = map(int, input().split())
A = [1 for _ in range(n)]
LST = LazySegmentTree(n, ele, lazy_ele)
LST.initialize(A)
for _ in range(q):
l, r, d = map(int, input().split())
l -= 1
LST.update_range(l, r, d)
print(LST.get_range(0, n) % mod)
|
Statement
You have a string S of length N. Initially, all characters in S are `1`s.
You will perform queries Q times. In the i-th query, you are given two
integers L_i, R_i and a character D_i (which is a digit). Then, you must
replace all characters from the L_i-th to the R_i-th (inclusive) with D_i.
After each query, read the string S as a decimal integer, and print its value
modulo 998,244,353.
|
[{"input": "8 5\n 3 6 2\n 1 4 7\n 3 8 3\n 2 2 2\n 4 5 1", "output": "11222211\n 77772211\n 77333333\n 72333333\n 72311333\n \n\n* * *"}, {"input": "200000 1\n 123 456 7", "output": "641437905\n \n\nDon't forget to take the modulo."}]
|
Print Q lines. In the i-th line print the value of S after the i-th query,
modulo 998,244,353.
* * *
|
s180658205
|
Accepted
|
p02538
|
Input is given from Standard Input in the following format:
N Q
L_1 R_1 D_1
:
L_Q R_Q D_Q
|
mod = 998244353
eps = 10**-9
def main():
import sys
input = sys.stdin.buffer.readline
beki10 = [0] * ((1 << 19) + 1)
beki10[0] = 1
for i in range(20):
beki10[1 << i] = pow(10, (1 << i), mod)
def op(a, b, seg_len):
return (a * beki10[seg_len] + b) % mod
e = 0
inv9 = pow(9, mod - 2, mod)
def mapping(a, x, seg_len):
return ((x * inv9) % mod * (beki10[seg_len] - 1)) % mod
def composition(x, y):
return y
id = -1
class LazySegTree:
# Range update query
def __init__(
self,
A,
op=op,
e=e,
mapping=mapping,
composition=composition,
id=id,
initialize=True,
):
self.N = len(A)
self.LV = (self.N - 1).bit_length()
self.N0 = 1 << self.LV
self.op = op
self.e = e
self.mapping = mapping
self.composition = composition
self.id = id
if initialize:
self.data = [self.e] * self.N0 + A + [self.e] * (self.N0 - self.N)
seg_len = 1
beki = self.N0 // 2
for i in range(self.N0 - 1, 0, -1):
self.data[i] = op(self.data[i * 2], self.data[i * 2 + 1], seg_len)
if i == beki:
seg_len <<= 1
beki >>= 1
else:
self.data = [self.e] * (self.N0 * 2)
self.lazy = [id] * (self.N0 * 2)
def _ascend(self, i, seg_len):
for _ in range(i.bit_length() - 1):
i >>= 1
self.data[i] = self.op(self.data[i * 2], self.data[i * 2 + 1], seg_len)
seg_len <<= 1
def _descend(self, idx):
lv = idx.bit_length()
seg_len = 1 << self.LV
for j in range(lv - 1, 0, -1):
seg_len >>= 1
i = idx >> j
x = self.lazy[i]
if x == self.id:
continue
self.lazy[i * 2] = self.composition(self.lazy[i * 2], x)
self.lazy[i * 2 + 1] = self.composition(self.lazy[i * 2 + 1], x)
self.lazy[i] = self.id
self.data[i * 2] = self.mapping(self.data[i * 2], x, seg_len)
self.data[i * 2 + 1] = self.mapping(self.data[i * 2 + 1], x, seg_len)
# open interval [l, r)
def apply(self, l, r, x):
l += self.N0 - 1
r += self.N0 - 1
self._descend(l // (l & -l))
self._descend(r // (r & -r) - 1)
l_ori = l
r_ori = r
seg_len = 1
while l < r:
if l & 1:
self.data[l] = self.mapping(self.data[l], x, seg_len)
self.lazy[l] = self.composition(self.lazy[l], x)
l += 1
if r & 1:
r -= 1
self.data[r] = self.mapping(self.data[r], x, seg_len)
self.lazy[r] = self.composition(self.lazy[r], x)
l >>= 1
r >>= 1
seg_len <<= 1
self._ascend(l_ori // (l_ori & -l_ori), l_ori & -l_ori)
self._ascend(r_ori // (r_ori & -r_ori) - 1, r_ori & -r_ori)
# open interval [l, r)
def query(self, l, r):
l += self.N0 - 1
r += self.N0 - 1
self._descend(l // (l & -l))
self._descend(r // (r & -r) - 1)
ret_l = self.e
ret_r = self.e
seg_len = 1
while l < r:
if l & 1:
ret_l = self.op(ret_l, self.data[l], seg_len)
l += 1
if r & 1:
ret_r = self.op(self.data[r - 1], ret_r, seg_len)
r -= 1
l >>= 1
r >>= 1
seg_len <<= 1
return self.op(ret_l, ret_r, 1)
N, Q = map(int, input().split())
N0 = 1 << (N - 1).bit_length()
ST = LazySegTree([0] * (N0 - N) + [1] * N)
inv10 = pow(10, mod - 2, mod)
ans = [0] * Q
for q in range(Q):
l, r, d = map(int, input().split())
ST.apply(N0 - N + l, N0 - N + r + 1, d)
ans[q] = (ST.query(N0 - N + 1, N0 + 1) * inv10) % mod
print(*ans, sep="\n")
if __name__ == "__main__":
main()
|
Statement
You have a string S of length N. Initially, all characters in S are `1`s.
You will perform queries Q times. In the i-th query, you are given two
integers L_i, R_i and a character D_i (which is a digit). Then, you must
replace all characters from the L_i-th to the R_i-th (inclusive) with D_i.
After each query, read the string S as a decimal integer, and print its value
modulo 998,244,353.
|
[{"input": "8 5\n 3 6 2\n 1 4 7\n 3 8 3\n 2 2 2\n 4 5 1", "output": "11222211\n 77772211\n 77333333\n 72333333\n 72311333\n \n\n* * *"}, {"input": "200000 1\n 123 456 7", "output": "641437905\n \n\nDon't forget to take the modulo."}]
|
Print Q lines. In the i-th line print the value of S after the i-th query,
modulo 998,244,353.
* * *
|
s041322137
|
Wrong Answer
|
p02538
|
Input is given from Standard Input in the following format:
N Q
L_1 R_1 D_1
:
L_Q R_Q D_Q
|
# N: 処理する区間の長さ
mod = 998244353
N, q = map(int, input().split())
lrd = [list(map(int, input().split())) for _ in range(q)]
INF = float("inf") # 2**31-1
LV = (N - 1).bit_length()
N0 = 2**LV
data = [0] * (2 * N0)
lazy = [0] * (2 * N0)
# 伝搬対象の区間を求める
def gindex(l, r):
L = (l + N0) >> 1
R = (r + N0) >> 1
lc = 0 if l & 1 else (L & -L).bit_length()
rc = 0 if r & 1 else (R & -R).bit_length()
for i in range(LV):
if rc <= i:
yield R
if L < R and lc <= i:
yield L
L >>= 1
R >>= 1
# 遅延伝搬処理
def propagates(*ids):
for i in reversed(ids):
v = lazy[i - 1]
if v is None:
continue
lazy[2 * i - 1] = data[2 * i - 1] = lazy[2 * i] = data[2 * i] = v
lazy[i - 1] = None
# 区間[l, r)をxで更新
def update(l, r, x):
(*ids,) = gindex(l, r)
propagates(*ids)
L = N0 + l
R = N0 + r
while L < R:
if R & 1:
R -= 1
lazy[R - 1] = data[R - 1] = x * pow(10, N - R % N, mod)
if L & 1:
lazy[L - 1] = data[L - 1] = x * pow(10, N - L % N, mod)
L += 1
L >>= 1
R >>= 1
for i in ids:
data[i - 1] = data[2 * i - 1] + data[2 * i]
# 区間[l, r)内の最小値を求める
def query(l, r):
propagates(*gindex(l, r))
L = N0 + l
R = N0 + r
s = 0
while L < R:
if R & 1:
R -= 1
s = s + data[R - 1]
if L & 1:
s = s + data[L - 1]
L += 1
L >>= 1
R >>= 1
return s
s = 0
ss = []
tmp = 1
for i in range(N):
ss.append(tmp)
s += tmp
s %= mod
tmp *= 10
tmp %= mod
ss.reverse()
update(0, N, 1)
# print(query(0,N))
for l, r, d in lrd:
update(l - 1, r, d)
print(query(0, N))
|
Statement
You have a string S of length N. Initially, all characters in S are `1`s.
You will perform queries Q times. In the i-th query, you are given two
integers L_i, R_i and a character D_i (which is a digit). Then, you must
replace all characters from the L_i-th to the R_i-th (inclusive) with D_i.
After each query, read the string S as a decimal integer, and print its value
modulo 998,244,353.
|
[{"input": "8 5\n 3 6 2\n 1 4 7\n 3 8 3\n 2 2 2\n 4 5 1", "output": "11222211\n 77772211\n 77333333\n 72333333\n 72311333\n \n\n* * *"}, {"input": "200000 1\n 123 456 7", "output": "641437905\n \n\nDon't forget to take the modulo."}]
|
Print Q lines. In the i-th line print the value of S after the i-th query,
modulo 998,244,353.
* * *
|
s004309411
|
Wrong Answer
|
p02538
|
Input is given from Standard Input in the following format:
N Q
L_1 R_1 D_1
:
L_Q R_Q D_Q
|
d = input().split()
N = int(d[0])
Q = int(d[1])
S = "1" * N
for i in range(Q):
n = input().split()
L = int(n[0])
R = int(n[1])
D = n[2]
S = S[: L - 1] + D * (R - L + 1) + S[R - 1 :]
S = int(S)
print(S % 998244353)
|
Statement
You have a string S of length N. Initially, all characters in S are `1`s.
You will perform queries Q times. In the i-th query, you are given two
integers L_i, R_i and a character D_i (which is a digit). Then, you must
replace all characters from the L_i-th to the R_i-th (inclusive) with D_i.
After each query, read the string S as a decimal integer, and print its value
modulo 998,244,353.
|
[{"input": "8 5\n 3 6 2\n 1 4 7\n 3 8 3\n 2 2 2\n 4 5 1", "output": "11222211\n 77772211\n 77333333\n 72333333\n 72311333\n \n\n* * *"}, {"input": "200000 1\n 123 456 7", "output": "641437905\n \n\nDon't forget to take the modulo."}]
|
Print Q lines. In the i-th line print the value of S after the i-th query,
modulo 998,244,353.
* * *
|
s768865781
|
Accepted
|
p02538
|
Input is given from Standard Input in the following format:
N Q
L_1 R_1 D_1
:
L_Q R_Q D_Q
|
import sys
input = sys.stdin.readline
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def main():
class LazySegmentTree:
__slots__ = ["n", "data", "lazy", "me", "oe", "fmm", "fmo", "foo"]
def __init__(self, monoid_data, monoid_identity, operator_identity, func_monoid_monoid, func_monoid_operator, func_operator_operator):
self.me = monoid_identity
self.oe = operator_identity
self.fmm = func_monoid_monoid
self.fmo = func_monoid_operator
self.foo = func_operator_operator
self.n = len(monoid_data)
self.data = monoid_data * 2
for i in range(self.n-1, 0, -1):
self.data[i] = self.fmm(self.data[2*i], self.data[2*i+1])
self.lazy = [self.oe] * (self.n * 2)
def replace(self, index, value):
index += self.n
# propagation
for shift in range(index.bit_length()-1, 0, -1):
i = index >> shift
self.lazy[2*i] = self.foo(self.lazy[2*i], self.lazy[i])
self.lazy[2*i+1] = self.foo(self.lazy[2*i+1], self.lazy[i])
self.data[i] = self.fmo(self.data[i], self.lazy[i])
self.lazy[i] = self.oe
# update
self.data[index] = value
self.lazy[index] = self.oe
# recalculation
i = index
while i > 1:
i //= 2
self.data[i] = self.fmm( self.fmo(self.data[2*i], self.lazy[2*i]), self.fmo(self.data[2*i+1], self.lazy[2*i+1]) )
self.lazy[i] = self.oe
def effect(self, l, r, operator):
l += self.n
r += self.n
# preparing indices
indices = []
l0 = (l // (l & -l)) // 2
r0 = (r // (r & -r) - 1) // 2
while r0 > l0:
indices.append(r0)
r0 //= 2
while l0 > r0:
indices.append(l0)
l0 //= 2
while l0 and l0 != r0:
indices.append(r0)
r0 //= 2
if l0 == r0:
break
indices.append(l0)
l0 //= 2
while r0:
indices.append(r0)
r0 //= 2
# propagation
for i in reversed(indices):
self.lazy[2*i] = self.foo(self.lazy[2*i], self.lazy[i])
self.lazy[2*i+1] = self.foo(self.lazy[2*i+1], self.lazy[i])
self.data[i] = self.fmo(self.data[i], self.lazy[i])
self.lazy[i] = self.oe
# effect
while l < r:
if l % 2:
self.lazy[l] = self.foo(self.lazy[l], operator)
l += 1
if r % 2:
r -= 1
self.lazy[r] = self.foo(self.lazy[r], operator)
l //= 2
r //= 2
# recalculation
for i in indices:
self.data[i] = self.fmm( self.fmo(self.data[2*i], self.lazy[2*i]), self.fmo(self.data[2*i+1], self.lazy[2*i+1]) )
self.lazy[i] = self.oe
def folded(self, l, r):
l += self.n
r += self.n
# preparing indices
indices = []
l0 = (l // (l & -l)) // 2
r0 = (r // (r & -r) - 1) // 2
while r0 > l0:
indices.append(r0)
r0 //= 2
while l0 > r0:
indices.append(l0)
l0 //= 2
while l0 and l0 != r0:
indices.append(r0)
r0 //= 2
if l0 == r0:
break
indices.append(l0)
l0 //= 2
while r0:
indices.append(r0)
r0 //= 2
# propagation
for i in reversed(indices):
self.lazy[2*i] = self.foo(self.lazy[2*i], self.lazy[i])
self.lazy[2*i+1] = self.foo(self.lazy[2*i+1], self.lazy[i])
self.data[i] = self.fmo(self.data[i], self.lazy[i])
self.lazy[i] = self.oe
# fold
left_folded = self.me
right_folded = self.me
while l < r:
if l % 2:
left_folded = self.fmm(left_folded, self.fmo(self.data[l], self.lazy[l]))
l += 1
if r % 2:
r -= 1
right_folded = self.fmm(self.fmo(self.data[r], self.lazy[r]), right_folded)
l //= 2
r //= 2
return self.fmm(left_folded, right_folded)
mod=998244353
N,Q=MI()
POW=[1]
for _ in range(N+5):
a=POW[-1]
a*=10
a%=mod
POW.append(a)
inv9=pow(9,mod-2,mod)#9でわる
MM=32
mask=(1<<MM)-1
# (数,今見てる数の桁数)を1つにまとめる
def enc(a,d):
return (a<<MM) + d
def dec(v):
a=v>>MM
d=v&mask
return a,d
mide=enc(1,1)
monoid_data=[mide]*N
monoid_ide=0#0を足したいからこれで
ope_ide=0
def fmm(m1,m2):
# print(m1,m2)
a1,d1=dec(m1)
a2,d2=dec(m2)
# print(a1,d1,a2,d2)
temp=a1*POW[d2]+a2
return enc(temp%mod,d1+d2)#桁数は足せば良い
def fmo(m1,o1):
if o1:
# o1がd1桁だけ続くものを返したい
a1,d1=dec(m1)
temp=(o1*(POW[d1]-1)*inv9)#1がd1桁
return enc(temp%mod,d1)
else:
return m1
def foo(o1,o2):
if o2:
return o2
else:
return o1
Lseg=LazySegmentTree(monoid_data,monoid_ide,ope_ide,fmm,fmo,foo)
for _ in range(Q):
# print("---")
l,r,d=MI()
l-=1
r-=1
Lseg.effect(l,r+1,d)
ans=Lseg.folded(0,N)
a,d=dec(ans)
print(a)
main()
|
Statement
You have a string S of length N. Initially, all characters in S are `1`s.
You will perform queries Q times. In the i-th query, you are given two
integers L_i, R_i and a character D_i (which is a digit). Then, you must
replace all characters from the L_i-th to the R_i-th (inclusive) with D_i.
After each query, read the string S as a decimal integer, and print its value
modulo 998,244,353.
|
[{"input": "8 5\n 3 6 2\n 1 4 7\n 3 8 3\n 2 2 2\n 4 5 1", "output": "11222211\n 77772211\n 77333333\n 72333333\n 72311333\n \n\n* * *"}, {"input": "200000 1\n 123 456 7", "output": "641437905\n \n\nDon't forget to take the modulo."}]
|
Print Q lines. In the i-th line print the value of S after the i-th query,
modulo 998,244,353.
* * *
|
s346947975
|
Accepted
|
p02538
|
Input is given from Standard Input in the following format:
N Q
L_1 R_1 D_1
:
L_Q R_Q D_Q
|
def _ceil_pow2(n: int) -> int:
x = 0
while (1 << x) < n:
x += 1
return x
def _bsf(n: int) -> int:
x = 0
while n % 2 == 0:
x += 1
n //= 2
return x
class LazySegTree:
def __init__(self, op, e, mapping, composition, id_, v):
self._op = op
self._e = e
self._mapping = mapping
self._composition = composition
self._id = id_
if isinstance(v, int):
v = [e] * v
self._n = len(v)
self._log = _ceil_pow2(self._n)
self._size = 1 << self._log
self._d = [e] * (2 * self._size)
self._lz = [self._id] * self._size
for i in range(self._n):
self._d[self._size + i] = v[i]
for i in range(self._size - 1, 0, -1):
self._update(i)
def set(self, p: int, x) -> None:
assert 0 <= p < self._n
p += self._size
for i in range(self._log, 0, -1):
self._push(p >> i)
self._d[p] = x
for i in range(1, self._log + 1):
self._update(p >> i)
def get(self, p: int):
assert 0 <= p < self._n
p += self._size
for i in range(self._log, 0, -1):
self._push(p >> i)
return self._d[p]
def prod(self, left: int, right: int):
assert 0 <= left <= right <= self._n
if left == right:
return self._e
left += self._size
right += self._size
for i in range(self._log, 0, -1):
if ((left >> i) << i) != left:
self._push(left >> i)
if ((right >> i) << i) != right:
self._push(right >> i)
sml = self._e
smr = self._e
while left < right:
if left & 1:
sml = self._op(sml, self._d[left])
left += 1
if right & 1:
right -= 1
smr = self._op(self._d[right], smr)
left >>= 1
right >>= 1
return self._op(sml, smr)
def all_prod(self):
return self._d[1]
def apply(self, left: int, right=None, f=None):
assert f is not None
if right is None:
p = left
assert 0 <= left < self._n
p += self._size
for i in range(self._log, 0, -1):
self._push(p >> i)
self._d[p] = self._mapping(f, self._d[p])
for i in range(1, self._log + 1):
self._update(p >> i)
else:
assert 0 <= left <= right <= self._n
if left == right:
return
left += self._size
right += self._size
for i in range(self._log, 0, -1):
if ((left >> i) << i) != left:
self._push(left >> i)
if ((right >> i) << i) != right:
self._push((right - 1) >> i)
l2 = left
r2 = right
while left < right:
if left & 1:
self._all_apply(left, f)
left += 1
if right & 1:
right -= 1
self._all_apply(right, f)
left >>= 1
right >>= 1
left = l2
right = r2
for i in range(1, self._log + 1):
if ((left >> i) << i) != left:
self._update(left >> i)
if ((right >> i) << i) != right:
self._update((right - 1) >> i)
def max_right(self, left: int, g) -> int:
assert 0 <= left <= self._n
assert g(self._e)
if left == self._n:
return self._n
left += self._size
for i in range(self._log, 0, -1):
self._push(left >> i)
sm = self._e
first = True
while first or (left & -left) != left:
first = False
while left % 2 == 0:
left >>= 1
if not g(self._op(sm, self._d[left])):
while left < self._size:
self._push(left)
left *= 2
if g(self._op(sm, self._d[left])):
sm = self._op(sm, self._d[left])
left += 1
return left - self._size
sm = self._op(sm, self._d[left])
left += 1
return self._n
def min_left(self, right: int, g) -> int:
assert 0 <= right <= self._n
assert g(self._e)
if right == 0:
return 0
right += self._size
for i in range(self._log, 0, -1):
self._push((right - 1) >> i)
sm = self._e
first = True
while first or (right & -right) != right:
first = False
right -= 1
while right > 1 and right % 2:
right >>= 1
if not g(self._op(self._d[right], sm)):
while right < self._size:
self._push(right)
right = 2 * right + 1
if g(self._op(self._d[right], sm)):
sm = self._op(self._d[right], sm)
right -= 1
return right + 1 - self._size
sm = self._op(self._d[right], sm)
return 0
def _update(self, k: int) -> None:
self._d[k] = self._op(self._d[2 * k], self._d[2 * k + 1])
def _all_apply(self, k: int, f) -> None:
self._d[k] = self._mapping(f, self._d[k])
if k < self._size:
self._lz[k] = self._composition(f, self._lz[k])
def _push(self, k: int) -> None:
self._all_apply(2 * k, self._lz[k])
self._all_apply(2 * k + 1, self._lz[k])
self._lz[k] = self._id
D = [1, 10]
E = [1, 11]
mod = 998244353
def op(a, b):
return (b[0] + a[0] * D[b[1]]) % mod, a[1] + b[1]
e = (0, 0)
def mapping(f, a):
if f is None:
return a[0], a[1]
if a[0] == 0:
return 0, 0
return (f * E[a[1] - 1]) % mod, a[1]
def composition(f, g):
if f is None:
return g
else:
return f
id = None
import sys
def input():
return sys.stdin.readline()[:-1]
def main():
N, Q = list(map(int, input().split()))
a = 10
for i in range(N + 1):
a *= 10
a %= mod
D.append(a)
E.append((E[-1] + a) % mod)
lst = LazySegTree(op, e, mapping, composition, id, [(1, 1) for i in range(N)])
for i in range(Q):
l, r, d = list(map(int, input().split()))
l, r = l - 1, r - 1
lst.apply(l, r + 1, d)
print(lst.all_prod()[0])
if __name__ == "__main__":
main()
|
Statement
You have a string S of length N. Initially, all characters in S are `1`s.
You will perform queries Q times. In the i-th query, you are given two
integers L_i, R_i and a character D_i (which is a digit). Then, you must
replace all characters from the L_i-th to the R_i-th (inclusive) with D_i.
After each query, read the string S as a decimal integer, and print its value
modulo 998,244,353.
|
[{"input": "8 5\n 3 6 2\n 1 4 7\n 3 8 3\n 2 2 2\n 4 5 1", "output": "11222211\n 77772211\n 77333333\n 72333333\n 72311333\n \n\n* * *"}, {"input": "200000 1\n 123 456 7", "output": "641437905\n \n\nDon't forget to take the modulo."}]
|
Print Q lines. In the i-th line print the value of S after the i-th query,
modulo 998,244,353.
* * *
|
s136960930
|
Runtime Error
|
p02538
|
Input is given from Standard Input in the following format:
N Q
L_1 R_1 D_1
:
L_Q R_Q D_Q
|
import sys
input = sys.stdin.readline
N, Q = map(int, input().split())
mod = 998244353
seg_el = 1 << (N.bit_length()) # Segment treeの台の要素数
seg_height = 1 + N.bit_length() # Segment treeの高さ
SEG = [0 for i in range(2 * seg_el)] # 区間の和
LAZY = [0 for i in range(2 * seg_el)]
POW10 = [pow(10, i, mod) for i in range(N + 1)]
gyaku = pow(9, -1, mod)
def seg_function(x, y):
return (x + y) % mod
for i in range(N): # Aを対応する箇所へupdate
SEG[i + seg_el] = POW10[i]
for i in range(seg_el - 1, 0, -1): # 親の部分もupdate
SEG[i] = seg_function(SEG[i * 2], SEG[i * 2 + 1])
def lazy_change(ind, b):
kousuu = 1 << (seg_height - (ind.bit_length()))
tyousei = (ind - (1 << ((ind.bit_length()) - 1))) * kousuu
# print(ind,tyousei,kousuu)
SEG[ind] = POW10[tyousei] * b * (POW10[kousuu] - 1) * gyaku % mod
def lazy_compose(ind, b):
LAZY[ind] = b
def indexes(
L, R
): # 遅延伝搬すべきノードのリストを下から上の順に返す. (つまり, updateやgetvaluesで見るノードより上にあるノードたち)
INDLIST = []
R -= 1
L >>= 1
R >>= 1
while L != R:
if L > R:
INDLIST.append(L)
L >>= 1
else:
INDLIST.append(R)
R >>= 1
while L != 0:
INDLIST.append(L)
L >>= 1
return INDLIST
def changes(l, r, b0): # 区間[l,r)更新
L = l + seg_el
R = r + seg_el
L //= L & (-L)
R //= R & (-R)
UPIND = indexes(L, R)
for ind in UPIND[::-1]:
if LAZY[ind] != 0:
b = LAZY[ind]
lazy_change(ind << 1, b)
lazy_change(1 + (ind << 1), b)
lazy_compose(ind << 1, b)
lazy_compose(1 + (ind << 1), b)
LAZY[ind] = 0
# print(SEG)
while L != R:
if L > R:
lazy_change(L, b0)
lazy_compose(L, b0)
L += 1
L //= L & (-L)
else:
R -= 1
lazy_change(R, b0)
lazy_compose(R, b0)
R //= R & (-R)
for ind in UPIND:
SEG[ind] = seg_function(SEG[ind << 1], SEG[1 + (ind << 1)])
def getvalues(l, r):
L = l + seg_el
R = r + seg_el
L //= L & (-L)
R //= R & (-R)
UPIND = indexes(L, R)
UPIND = indexes(L, R)
for ind in UPIND[::-1]:
if LAZY[ind] != 0:
b = LAZY[ind]
lazy_change(ind << 1, b)
lazy_change(1 + (ind << 1), b)
lazy_compose(ind << 1, b)
lazy_compose(1 + (ind << 1), b)
LAZY[ind] = 0
ANSL = 0
ANSR = 0
while L != R:
if L > R:
ANSL = seg_function(ANSL, SEG[L])
L += 1
L //= L & (-L)
else:
R -= 1
ANSR = seg_function(SEG[R], ANSR)
R //= R & (-R)
return seg_function(ANSL, ANSR)
for qu in range(Q):
L, R, D = map(int, input().split())
L, R = N - R + 1, N - L + 1
# print(SEG)
changes(L - 1, R, D)
sys.stdout.write(str(SEG[1]) + "\n")
|
Statement
You have a string S of length N. Initially, all characters in S are `1`s.
You will perform queries Q times. In the i-th query, you are given two
integers L_i, R_i and a character D_i (which is a digit). Then, you must
replace all characters from the L_i-th to the R_i-th (inclusive) with D_i.
After each query, read the string S as a decimal integer, and print its value
modulo 998,244,353.
|
[{"input": "8 5\n 3 6 2\n 1 4 7\n 3 8 3\n 2 2 2\n 4 5 1", "output": "11222211\n 77772211\n 77333333\n 72333333\n 72311333\n \n\n* * *"}, {"input": "200000 1\n 123 456 7", "output": "641437905\n \n\nDon't forget to take the modulo."}]
|
Print Q lines. In the i-th line print the value of S after the i-th query,
modulo 998,244,353.
* * *
|
s815098157
|
Runtime Error
|
p02538
|
Input is given from Standard Input in the following format:
N Q
L_1 R_1 D_1
:
L_Q R_Q D_Q
|
import sys
from atcoder.lazysegtree import LazySegTree
from atcoder.modint import ModContext, Modint
def main() -> None:
with ModContext(998244353):
n, q = map(int, sys.stdin.readline().split())
a = [(Modint(1), Modint(10))] * n
def op(x: (Modint, Modint), y: (Modint, Modint)) -> (Modint, Modint):
return x[0] * y[1] + y[0], x[1] * y[1]
e = Modint(0), Modint(1)
def mapping(f: int, y: (Modint, Modint)) -> (Modint, Modint):
if f == 0:
return y
return (y[1] - Modint(1)) * Modint(9).inv() * Modint(f), y[1]
def composition(f: int, g: int) -> int:
if f == 0:
return g
return f
id_ = 0
lazy_segtree = LazySegTree(op, e, mapping, composition, id_, a)
for _ in range(q):
l, r, d = map(int, input().split())
l -= 1
lazy_segtree.apply(l, r, d)
print(lazy_segtree.all_prod()[0].val())
if __name__ == "__main__":
main()
|
Statement
You have a string S of length N. Initially, all characters in S are `1`s.
You will perform queries Q times. In the i-th query, you are given two
integers L_i, R_i and a character D_i (which is a digit). Then, you must
replace all characters from the L_i-th to the R_i-th (inclusive) with D_i.
After each query, read the string S as a decimal integer, and print its value
modulo 998,244,353.
|
[{"input": "8 5\n 3 6 2\n 1 4 7\n 3 8 3\n 2 2 2\n 4 5 1", "output": "11222211\n 77772211\n 77333333\n 72333333\n 72311333\n \n\n* * *"}, {"input": "200000 1\n 123 456 7", "output": "641437905\n \n\nDon't forget to take the modulo."}]
|
Print Q lines. In the i-th line print the value of S after the i-th query,
modulo 998,244,353.
* * *
|
s001707340
|
Runtime Error
|
p02538
|
Input is given from Standard Input in the following format:
N Q
L_1 R_1 D_1
:
L_Q R_Q D_Q
|
r = input().split()
N = int(r[0])
Q = int(r[1])
data = "1" * N
d = [input().split() for i in range(Q)]
for i in range(Q):
data = (
data[0 : int(d[i][0]) - 1]
+ d[i][2] * (int(d[i][1]) - int(d[i][0] + 1))
+ data[int(d[i][1]) : N]
)
print(int(data) % 998244353)
|
Statement
You have a string S of length N. Initially, all characters in S are `1`s.
You will perform queries Q times. In the i-th query, you are given two
integers L_i, R_i and a character D_i (which is a digit). Then, you must
replace all characters from the L_i-th to the R_i-th (inclusive) with D_i.
After each query, read the string S as a decimal integer, and print its value
modulo 998,244,353.
|
[{"input": "8 5\n 3 6 2\n 1 4 7\n 3 8 3\n 2 2 2\n 4 5 1", "output": "11222211\n 77772211\n 77333333\n 72333333\n 72311333\n \n\n* * *"}, {"input": "200000 1\n 123 456 7", "output": "641437905\n \n\nDon't forget to take the modulo."}]
|
Print Q lines. In the i-th line print the value of S after the i-th query,
modulo 998,244,353.
* * *
|
s446161281
|
Wrong Answer
|
p02538
|
Input is given from Standard Input in the following format:
N Q
L_1 R_1 D_1
:
L_Q R_Q D_Q
|
a = None
if (a is None) or (a < 12):
print("Yes")
else:
print("No")
|
Statement
You have a string S of length N. Initially, all characters in S are `1`s.
You will perform queries Q times. In the i-th query, you are given two
integers L_i, R_i and a character D_i (which is a digit). Then, you must
replace all characters from the L_i-th to the R_i-th (inclusive) with D_i.
After each query, read the string S as a decimal integer, and print its value
modulo 998,244,353.
|
[{"input": "8 5\n 3 6 2\n 1 4 7\n 3 8 3\n 2 2 2\n 4 5 1", "output": "11222211\n 77772211\n 77333333\n 72333333\n 72311333\n \n\n* * *"}, {"input": "200000 1\n 123 456 7", "output": "641437905\n \n\nDon't forget to take the modulo."}]
|
Print Q lines. The i-th line should contain the number of the trains that runs
**strictly within** the section from City p_i to City q_i.
* * *
|
s753593793
|
Runtime Error
|
p03283
|
Input is given from Standard Input in the following format:
N M Q
L_1 R_1
L_2 R_2
:
L_M R_M
p_1 q_1
p_2 q_2
:
p_Q q_Q
|
mport bisect
from collections import defaultdict
N,M,Q = map(int,input().split())
lr = [tuple(map(int,input().split())) for i in range(M)]
pq = [tuple(map(int,input().split())) for i in range(Q)]
lr.sort()
l = [lr[i][0] for i in range(M)]
r = [lr[i][1] for i in range(M)]
l_I = {}
for p in range(1,N+1):
l_I[p] = bisect.bisect_left(l,p)
r_d = {}
for i in range(1,N+1):
r_d[i] = sorted(r[l_I[i]:])
ans = defaultdict(lambda:{})
for p in range(1,N+1):
for q in range(p,N+1):
ans[p][q] = bisect.bisect(r_d[p],q)
for i in range(Q):
p,q = pq[i]
print(ans[p][q])
|
Statement
In Takahashi Kingdom, there is a east-west railroad and N cities along it,
numbered 1, 2, 3, ..., N from west to east. A company called _AtCoder Express_
possesses M trains, and the train i runs from City L_i to City R_i (it is
possible that L_i = R_i). Takahashi the king is interested in the following Q
matters:
* The number of the trains that runs **strictly within** the section from City p_i to City q_i, that is, the number of trains j such that p_i \leq L_j and R_j \leq q_i.
Although he is genius, this is too much data to process by himself. Find the
answer for each of these Q queries to help him.
|
[{"input": "2 3 1\n 1 1\n 1 2\n 2 2\n 1 2", "output": "3\n \n\nAs all the trains runs within the section from City 1 to City 2, the answer to\nthe only query is 3.\n\n* * *"}, {"input": "10 3 2\n 1 5\n 2 8\n 7 10\n 1 7\n 3 10", "output": "1\n 1\n \n\nThe first query is on the section from City 1 to 7. There is only one train\nthat runs strictly within that section: Train 1. The second query is on the\nsection from City 3 to 10. There is only one train that runs strictly within\nthat section: Train 3.\n\n* * *"}, {"input": "10 10 10\n 1 6\n 2 9\n 4 5\n 4 7\n 4 7\n 5 8\n 6 6\n 6 7\n 7 9\n 10 10\n 1 8\n 1 9\n 1 10\n 2 8\n 2 9\n 2 10\n 3 8\n 3 9\n 3 10\n 1 10", "output": "7\n 9\n 10\n 6\n 8\n 9\n 6\n 7\n 8\n 10"}]
|
Print Q lines. The i-th line should contain the number of the trains that runs
**strictly within** the section from City p_i to City q_i.
* * *
|
s402435434
|
Runtime Error
|
p03283
|
Input is given from Standard Input in the following format:
N M Q
L_1 R_1
L_2 R_2
:
L_M R_M
p_1 q_1
p_2 q_2
:
p_Q q_Q
|
N, M , Q = map(int, input().split())
LR = [[0 for _ in range(N+2-i) for _ in range(N+2)]
for i in range(M):
L, R = map(int, input().split())
LR[L][R-L+1] += 1
for i in range(2,N+2):
for j in range(1,N-i+2):
LR[j][i] += LR[j][i-1] + LR[j+1][i-1] - LR[j+1][i-2]
for i in range(Q):
p, q = map(int, input().split())
print(LR[p][q-p+1]-LR[q+1][0])
|
Statement
In Takahashi Kingdom, there is a east-west railroad and N cities along it,
numbered 1, 2, 3, ..., N from west to east. A company called _AtCoder Express_
possesses M trains, and the train i runs from City L_i to City R_i (it is
possible that L_i = R_i). Takahashi the king is interested in the following Q
matters:
* The number of the trains that runs **strictly within** the section from City p_i to City q_i, that is, the number of trains j such that p_i \leq L_j and R_j \leq q_i.
Although he is genius, this is too much data to process by himself. Find the
answer for each of these Q queries to help him.
|
[{"input": "2 3 1\n 1 1\n 1 2\n 2 2\n 1 2", "output": "3\n \n\nAs all the trains runs within the section from City 1 to City 2, the answer to\nthe only query is 3.\n\n* * *"}, {"input": "10 3 2\n 1 5\n 2 8\n 7 10\n 1 7\n 3 10", "output": "1\n 1\n \n\nThe first query is on the section from City 1 to 7. There is only one train\nthat runs strictly within that section: Train 1. The second query is on the\nsection from City 3 to 10. There is only one train that runs strictly within\nthat section: Train 3.\n\n* * *"}, {"input": "10 10 10\n 1 6\n 2 9\n 4 5\n 4 7\n 4 7\n 5 8\n 6 6\n 6 7\n 7 9\n 10 10\n 1 8\n 1 9\n 1 10\n 2 8\n 2 9\n 2 10\n 3 8\n 3 9\n 3 10\n 1 10", "output": "7\n 9\n 10\n 6\n 8\n 9\n 6\n 7\n 8\n 10"}]
|
Print Q lines. The i-th line should contain the number of the trains that runs
**strictly within** the section from City p_i to City q_i.
* * *
|
s265096104
|
Runtime Error
|
p03283
|
Input is given from Standard Input in the following format:
N M Q
L_1 R_1
L_2 R_2
:
L_M R_M
p_1 q_1
p_2 q_2
:
p_Q q_Q
|
N, M, Q = map(int, input().split())
tL = []
tR = []
for i in range(M):
a, b = map(int, input().split())
tL.append(a)
tR.append(b)
ql = []
qr = []
for j in range(Q):
c, d = map(int, input().split())
ql.append(c)
qr.append(d)
for j in range(Q):
count = 0
for i in range(M):
if ql[j] => tL[i] or tR[i] => qr[j]:
continue
else:
count += 1
print(count)
|
Statement
In Takahashi Kingdom, there is a east-west railroad and N cities along it,
numbered 1, 2, 3, ..., N from west to east. A company called _AtCoder Express_
possesses M trains, and the train i runs from City L_i to City R_i (it is
possible that L_i = R_i). Takahashi the king is interested in the following Q
matters:
* The number of the trains that runs **strictly within** the section from City p_i to City q_i, that is, the number of trains j such that p_i \leq L_j and R_j \leq q_i.
Although he is genius, this is too much data to process by himself. Find the
answer for each of these Q queries to help him.
|
[{"input": "2 3 1\n 1 1\n 1 2\n 2 2\n 1 2", "output": "3\n \n\nAs all the trains runs within the section from City 1 to City 2, the answer to\nthe only query is 3.\n\n* * *"}, {"input": "10 3 2\n 1 5\n 2 8\n 7 10\n 1 7\n 3 10", "output": "1\n 1\n \n\nThe first query is on the section from City 1 to 7. There is only one train\nthat runs strictly within that section: Train 1. The second query is on the\nsection from City 3 to 10. There is only one train that runs strictly within\nthat section: Train 3.\n\n* * *"}, {"input": "10 10 10\n 1 6\n 2 9\n 4 5\n 4 7\n 4 7\n 5 8\n 6 6\n 6 7\n 7 9\n 10 10\n 1 8\n 1 9\n 1 10\n 2 8\n 2 9\n 2 10\n 3 8\n 3 9\n 3 10\n 1 10", "output": "7\n 9\n 10\n 6\n 8\n 9\n 6\n 7\n 8\n 10"}]
|
Print Q lines. The i-th line should contain the number of the trains that runs
**strictly within** the section from City p_i to City q_i.
* * *
|
s034752190
|
Runtime Error
|
p03283
|
Input is given from Standard Input in the following format:
N M Q
L_1 R_1
L_2 R_2
:
L_M R_M
p_1 q_1
p_2 q_2
:
p_Q q_Q
|
N, M, Q = map(int, input().split())
LR = []
pq = []
for i in range(M):
LR.append(list(map(int, input().split())))
for i in range(Q):
pq.append(list(
map(int, input().split())))
for i in pq:
count = 0
for j in LR:
if j[0] >= i[0]:
elif j[1] <= i[1]:
count += 1
print(count)
|
Statement
In Takahashi Kingdom, there is a east-west railroad and N cities along it,
numbered 1, 2, 3, ..., N from west to east. A company called _AtCoder Express_
possesses M trains, and the train i runs from City L_i to City R_i (it is
possible that L_i = R_i). Takahashi the king is interested in the following Q
matters:
* The number of the trains that runs **strictly within** the section from City p_i to City q_i, that is, the number of trains j such that p_i \leq L_j and R_j \leq q_i.
Although he is genius, this is too much data to process by himself. Find the
answer for each of these Q queries to help him.
|
[{"input": "2 3 1\n 1 1\n 1 2\n 2 2\n 1 2", "output": "3\n \n\nAs all the trains runs within the section from City 1 to City 2, the answer to\nthe only query is 3.\n\n* * *"}, {"input": "10 3 2\n 1 5\n 2 8\n 7 10\n 1 7\n 3 10", "output": "1\n 1\n \n\nThe first query is on the section from City 1 to 7. There is only one train\nthat runs strictly within that section: Train 1. The second query is on the\nsection from City 3 to 10. There is only one train that runs strictly within\nthat section: Train 3.\n\n* * *"}, {"input": "10 10 10\n 1 6\n 2 9\n 4 5\n 4 7\n 4 7\n 5 8\n 6 6\n 6 7\n 7 9\n 10 10\n 1 8\n 1 9\n 1 10\n 2 8\n 2 9\n 2 10\n 3 8\n 3 9\n 3 10\n 1 10", "output": "7\n 9\n 10\n 6\n 8\n 9\n 6\n 7\n 8\n 10"}]
|
Print Q lines. The i-th line should contain the number of the trains that runs
**strictly within** the section from City p_i to City q_i.
* * *
|
s009296734
|
Runtime Error
|
p03283
|
Input is given from Standard Input in the following format:
N M Q
L_1 R_1
L_2 R_2
:
L_M R_M
p_1 q_1
p_2 q_2
:
p_Q q_Q
|
2 3 1
1 1
1 2
2 2
1 2
|
Statement
In Takahashi Kingdom, there is a east-west railroad and N cities along it,
numbered 1, 2, 3, ..., N from west to east. A company called _AtCoder Express_
possesses M trains, and the train i runs from City L_i to City R_i (it is
possible that L_i = R_i). Takahashi the king is interested in the following Q
matters:
* The number of the trains that runs **strictly within** the section from City p_i to City q_i, that is, the number of trains j such that p_i \leq L_j and R_j \leq q_i.
Although he is genius, this is too much data to process by himself. Find the
answer for each of these Q queries to help him.
|
[{"input": "2 3 1\n 1 1\n 1 2\n 2 2\n 1 2", "output": "3\n \n\nAs all the trains runs within the section from City 1 to City 2, the answer to\nthe only query is 3.\n\n* * *"}, {"input": "10 3 2\n 1 5\n 2 8\n 7 10\n 1 7\n 3 10", "output": "1\n 1\n \n\nThe first query is on the section from City 1 to 7. There is only one train\nthat runs strictly within that section: Train 1. The second query is on the\nsection from City 3 to 10. There is only one train that runs strictly within\nthat section: Train 3.\n\n* * *"}, {"input": "10 10 10\n 1 6\n 2 9\n 4 5\n 4 7\n 4 7\n 5 8\n 6 6\n 6 7\n 7 9\n 10 10\n 1 8\n 1 9\n 1 10\n 2 8\n 2 9\n 2 10\n 3 8\n 3 9\n 3 10\n 1 10", "output": "7\n 9\n 10\n 6\n 8\n 9\n 6\n 7\n 8\n 10"}]
|
Print Q lines. The i-th line should contain the number of the trains that runs
**strictly within** the section from City p_i to City q_i.
* * *
|
s455775331
|
Runtime Error
|
p03283
|
Input is given from Standard Input in the following format:
N M Q
L_1 R_1
L_2 R_2
:
L_M R_M
p_1 q_1
p_2 q_2
:
p_Q q_Q
|
N, M, Q = map(int,input().split())
C = [[0 for in range(N)] in range(N)]
for i in range(M):
L,R = map(int,input().split())
C[L][R] += 1
for j in range(Q):
p,q = map(int,input().split())
s = 0
for i in range(p,q+1):
for j in range(p,q+1):
s += C[i][j]
print(s)
|
Statement
In Takahashi Kingdom, there is a east-west railroad and N cities along it,
numbered 1, 2, 3, ..., N from west to east. A company called _AtCoder Express_
possesses M trains, and the train i runs from City L_i to City R_i (it is
possible that L_i = R_i). Takahashi the king is interested in the following Q
matters:
* The number of the trains that runs **strictly within** the section from City p_i to City q_i, that is, the number of trains j such that p_i \leq L_j and R_j \leq q_i.
Although he is genius, this is too much data to process by himself. Find the
answer for each of these Q queries to help him.
|
[{"input": "2 3 1\n 1 1\n 1 2\n 2 2\n 1 2", "output": "3\n \n\nAs all the trains runs within the section from City 1 to City 2, the answer to\nthe only query is 3.\n\n* * *"}, {"input": "10 3 2\n 1 5\n 2 8\n 7 10\n 1 7\n 3 10", "output": "1\n 1\n \n\nThe first query is on the section from City 1 to 7. There is only one train\nthat runs strictly within that section: Train 1. The second query is on the\nsection from City 3 to 10. There is only one train that runs strictly within\nthat section: Train 3.\n\n* * *"}, {"input": "10 10 10\n 1 6\n 2 9\n 4 5\n 4 7\n 4 7\n 5 8\n 6 6\n 6 7\n 7 9\n 10 10\n 1 8\n 1 9\n 1 10\n 2 8\n 2 9\n 2 10\n 3 8\n 3 9\n 3 10\n 1 10", "output": "7\n 9\n 10\n 6\n 8\n 9\n 6\n 7\n 8\n 10"}]
|
Print Q lines. The i-th line should contain the number of the trains that runs
**strictly within** the section from City p_i to City q_i.
* * *
|
s553193029
|
Runtime Error
|
p03283
|
Input is given from Standard Input in the following format:
N M Q
L_1 R_1
L_2 R_2
:
L_M R_M
p_1 q_1
p_2 q_2
:
p_Q q_Q
|
import copy
n, m, q = map(int, input().split())
train_map = []
numbers = []
for i in range(n):
train_map.append([])
for j in range(n):
train_map[i].append(0)
s = copy.deepcopy(train_map)
for i in range(m):
l, r = map(int, input().split())
train_map[l-1][r-1] += 1
for i in range(n):
tmp = 0
for j in range(n):
tmp += train_map[i][j]
s[i][j] = tmp
for i in range(q):
st, go = map(int, input().split())
number = 0
for j in range(st-1, go):
#number += s[j][go-1]
numbers.append(number)
for num in numbers:
print(num)
|
Statement
In Takahashi Kingdom, there is a east-west railroad and N cities along it,
numbered 1, 2, 3, ..., N from west to east. A company called _AtCoder Express_
possesses M trains, and the train i runs from City L_i to City R_i (it is
possible that L_i = R_i). Takahashi the king is interested in the following Q
matters:
* The number of the trains that runs **strictly within** the section from City p_i to City q_i, that is, the number of trains j such that p_i \leq L_j and R_j \leq q_i.
Although he is genius, this is too much data to process by himself. Find the
answer for each of these Q queries to help him.
|
[{"input": "2 3 1\n 1 1\n 1 2\n 2 2\n 1 2", "output": "3\n \n\nAs all the trains runs within the section from City 1 to City 2, the answer to\nthe only query is 3.\n\n* * *"}, {"input": "10 3 2\n 1 5\n 2 8\n 7 10\n 1 7\n 3 10", "output": "1\n 1\n \n\nThe first query is on the section from City 1 to 7. There is only one train\nthat runs strictly within that section: Train 1. The second query is on the\nsection from City 3 to 10. There is only one train that runs strictly within\nthat section: Train 3.\n\n* * *"}, {"input": "10 10 10\n 1 6\n 2 9\n 4 5\n 4 7\n 4 7\n 5 8\n 6 6\n 6 7\n 7 9\n 10 10\n 1 8\n 1 9\n 1 10\n 2 8\n 2 9\n 2 10\n 3 8\n 3 9\n 3 10\n 1 10", "output": "7\n 9\n 10\n 6\n 8\n 9\n 6\n 7\n 8\n 10"}]
|
Print Q lines. The i-th line should contain the number of the trains that runs
**strictly within** the section from City p_i to City q_i.
* * *
|
s374633228
|
Runtime Error
|
p03283
|
Input is given from Standard Input in the following format:
N M Q
L_1 R_1
L_2 R_2
:
L_M R_M
p_1 q_1
p_2 q_2
:
p_Q q_Q
|
import itertools
import numpy as np
n,m,q=map(int, input().split())
a=[list(map(int, input().split())) for i in range(m)]
b=[list(map(int, input().split())) for i in range(q)]
x=[[0]*(501) for i in range(501)]
x=np.array
for i in range(m):
x[a[i][0],a[i][1]]+=1
for i in range(501):
x[i] = list(itertools.accumulate(x[i]))
for i in range(501):
x[:,i] = list(itertools.accumulate(x[:,i]))
for i in range(q):
print(x[b[i][1],b[i][1]]-x[b[i][1],b[i][0]-1]-x[b[i][0-1,b[i][1]]+x[b[i][0-1,b[i][0-1])
|
Statement
In Takahashi Kingdom, there is a east-west railroad and N cities along it,
numbered 1, 2, 3, ..., N from west to east. A company called _AtCoder Express_
possesses M trains, and the train i runs from City L_i to City R_i (it is
possible that L_i = R_i). Takahashi the king is interested in the following Q
matters:
* The number of the trains that runs **strictly within** the section from City p_i to City q_i, that is, the number of trains j such that p_i \leq L_j and R_j \leq q_i.
Although he is genius, this is too much data to process by himself. Find the
answer for each of these Q queries to help him.
|
[{"input": "2 3 1\n 1 1\n 1 2\n 2 2\n 1 2", "output": "3\n \n\nAs all the trains runs within the section from City 1 to City 2, the answer to\nthe only query is 3.\n\n* * *"}, {"input": "10 3 2\n 1 5\n 2 8\n 7 10\n 1 7\n 3 10", "output": "1\n 1\n \n\nThe first query is on the section from City 1 to 7. There is only one train\nthat runs strictly within that section: Train 1. The second query is on the\nsection from City 3 to 10. There is only one train that runs strictly within\nthat section: Train 3.\n\n* * *"}, {"input": "10 10 10\n 1 6\n 2 9\n 4 5\n 4 7\n 4 7\n 5 8\n 6 6\n 6 7\n 7 9\n 10 10\n 1 8\n 1 9\n 1 10\n 2 8\n 2 9\n 2 10\n 3 8\n 3 9\n 3 10\n 1 10", "output": "7\n 9\n 10\n 6\n 8\n 9\n 6\n 7\n 8\n 10"}]
|
Print Q lines. The i-th line should contain the number of the trains that runs
**strictly within** the section from City p_i to City q_i.
* * *
|
s297103383
|
Runtime Error
|
p03283
|
Input is given from Standard Input in the following format:
N M Q
L_1 R_1
L_2 R_2
:
L_M R_M
p_1 q_1
p_2 q_2
:
p_Q q_Q
|
#include<iostream>
#include<algorithm>
#include<math.h>
#include<queue>
#include<string>
#include<vector>
#include<stack>
#include<iomanip>
#include<map>
#define rep(i,n) for(int i=0;i<((int)n);i++)
#define drep(i,n) for(int i=((int)n)-1;i>-1;i--)
#define Rep(i,n0,n) for(int i=n0;i<((int)n);i++)
#define Com(i,j,n) for(int i=0;i<n-1;i++)for(int j=i+1;j<((int)n);j++)
#define W(x) cout<<x<<endl;
#define Debug(x) cout<<"#DEBUG "<<x<<endl;
#define INF (1<<29)
#define INF2 (long long)8*(long long)INF*(long long)INF
#define mod 1000000007
typedef long long ll;
using namespace std;
int min(int x,int y){if(y<x)return y;else return x;}
int max(int x,int y){if(y>x)return y;else return x;}
int fact(int x){int i=1;rep(j,x){i*=(j+1);} return i;}
long long fact(long long x){long long i=1;rep(j,x){i*=(j+1);} return i;}
int gcd(int x, int y){if(x%y==0)return y;else if(y%x==0)return x;else return gcd(x%y,y%x);}
ll gcd(ll x, ll y){if(x%y==0)return y;else if(y%x==0)return x;else return gcd(x%y,y%x);}
void say(bool x){if(x){cout<<"Yes"<<endl;}else {cout<<"No"<<endl;}return;}
int dd[500][500];
int main()
{
int n,m,Q;
cin >>n >>m >>Q;
int l,r;
rep(i,m)
{
cin>>l>>r;
l--;
r--;
dd[l][r]++;
}
rep(i,n)
{
rep(j,n-1)
{
dd[i][j+1]+=dd[i][j];
}
}
rep(i,n)
{
drep(j,n-1)
{
dd[j][i]+=dd[j+1][i];
}
}
int p,q;
rep(i,Q)
{
cin>>p>>q;
p--;
q--;
W(dd[p][q])
}
return 0;
}
|
Statement
In Takahashi Kingdom, there is a east-west railroad and N cities along it,
numbered 1, 2, 3, ..., N from west to east. A company called _AtCoder Express_
possesses M trains, and the train i runs from City L_i to City R_i (it is
possible that L_i = R_i). Takahashi the king is interested in the following Q
matters:
* The number of the trains that runs **strictly within** the section from City p_i to City q_i, that is, the number of trains j such that p_i \leq L_j and R_j \leq q_i.
Although he is genius, this is too much data to process by himself. Find the
answer for each of these Q queries to help him.
|
[{"input": "2 3 1\n 1 1\n 1 2\n 2 2\n 1 2", "output": "3\n \n\nAs all the trains runs within the section from City 1 to City 2, the answer to\nthe only query is 3.\n\n* * *"}, {"input": "10 3 2\n 1 5\n 2 8\n 7 10\n 1 7\n 3 10", "output": "1\n 1\n \n\nThe first query is on the section from City 1 to 7. There is only one train\nthat runs strictly within that section: Train 1. The second query is on the\nsection from City 3 to 10. There is only one train that runs strictly within\nthat section: Train 3.\n\n* * *"}, {"input": "10 10 10\n 1 6\n 2 9\n 4 5\n 4 7\n 4 7\n 5 8\n 6 6\n 6 7\n 7 9\n 10 10\n 1 8\n 1 9\n 1 10\n 2 8\n 2 9\n 2 10\n 3 8\n 3 9\n 3 10\n 1 10", "output": "7\n 9\n 10\n 6\n 8\n 9\n 6\n 7\n 8\n 10"}]
|
Print Q lines. The i-th line should contain the number of the trains that runs
**strictly within** the section from City p_i to City q_i.
* * *
|
s043795670
|
Runtime Error
|
p03283
|
Input is given from Standard Input in the following format:
N M Q
L_1 R_1
L_2 R_2
:
L_M R_M
p_1 q_1
p_2 q_2
:
p_Q q_Q
|
N, M, Q = map(int, input().split())
rail = []
for i in range(M):
r = list(map(int, input().split()))
rail.append(r)
query = []
for i in range(Q):
q = list(map(int, input().split()))
query.append(q)
f = [[0 for i in range(N)] for j in range(N)]
g = [[0 for i in range(N)] for j in range(N)]
for i in range(M):
f[rail[i][0]-1][rail[i][1]-1] += 1
for i in range(N):
j = 0
while j + i < N:
if i == 0:
g[j][j+i] = f[j][j+i]
else:
g[j][j+i] = f[j][j+i] + g[j+1][j+i] + g[j][j+i-1] - g[j+1][j+i-1]
j += 1
for i in range(Q):
print(g[query[i][0]-1][query[i][1]-1])
|
Statement
In Takahashi Kingdom, there is a east-west railroad and N cities along it,
numbered 1, 2, 3, ..., N from west to east. A company called _AtCoder Express_
possesses M trains, and the train i runs from City L_i to City R_i (it is
possible that L_i = R_i). Takahashi the king is interested in the following Q
matters:
* The number of the trains that runs **strictly within** the section from City p_i to City q_i, that is, the number of trains j such that p_i \leq L_j and R_j \leq q_i.
Although he is genius, this is too much data to process by himself. Find the
answer for each of these Q queries to help him.
|
[{"input": "2 3 1\n 1 1\n 1 2\n 2 2\n 1 2", "output": "3\n \n\nAs all the trains runs within the section from City 1 to City 2, the answer to\nthe only query is 3.\n\n* * *"}, {"input": "10 3 2\n 1 5\n 2 8\n 7 10\n 1 7\n 3 10", "output": "1\n 1\n \n\nThe first query is on the section from City 1 to 7. There is only one train\nthat runs strictly within that section: Train 1. The second query is on the\nsection from City 3 to 10. There is only one train that runs strictly within\nthat section: Train 3.\n\n* * *"}, {"input": "10 10 10\n 1 6\n 2 9\n 4 5\n 4 7\n 4 7\n 5 8\n 6 6\n 6 7\n 7 9\n 10 10\n 1 8\n 1 9\n 1 10\n 2 8\n 2 9\n 2 10\n 3 8\n 3 9\n 3 10\n 1 10", "output": "7\n 9\n 10\n 6\n 8\n 9\n 6\n 7\n 8\n 10"}]
|
Print Q lines. The i-th line should contain the number of the trains that runs
**strictly within** the section from City p_i to City q_i.
* * *
|
s976281769
|
Runtime Error
|
p03283
|
Input is given from Standard Input in the following format:
N M Q
L_1 R_1
L_2 R_2
:
L_M R_M
p_1 q_1
p_2 q_2
:
p_Q q_Q
|
n, m, q = map(int, input().split())
train = [tuple(map(int, input().split())) for _ in range(m)]
quest = [tuple(map(int, input().split())) for _ in range(q)]
dp = [[0 for _ in range(n)] for _ in range(n)]
d = {}
for l in range(n):
for r in range(l,n):
d[(l,r)] = 0
for p, q in train:
else:
d[(p,q)] += 1
for l in range(n):
dp[l][l] = d[(l+1,l+1)]
for w in range(1,n):
for l in range(n-w):
dp[l][l+w] = dp[l][l+w-1] + d[(l,l+w)]
for l, r in quest:
print(dp[l-1][r-1])
|
Statement
In Takahashi Kingdom, there is a east-west railroad and N cities along it,
numbered 1, 2, 3, ..., N from west to east. A company called _AtCoder Express_
possesses M trains, and the train i runs from City L_i to City R_i (it is
possible that L_i = R_i). Takahashi the king is interested in the following Q
matters:
* The number of the trains that runs **strictly within** the section from City p_i to City q_i, that is, the number of trains j such that p_i \leq L_j and R_j \leq q_i.
Although he is genius, this is too much data to process by himself. Find the
answer for each of these Q queries to help him.
|
[{"input": "2 3 1\n 1 1\n 1 2\n 2 2\n 1 2", "output": "3\n \n\nAs all the trains runs within the section from City 1 to City 2, the answer to\nthe only query is 3.\n\n* * *"}, {"input": "10 3 2\n 1 5\n 2 8\n 7 10\n 1 7\n 3 10", "output": "1\n 1\n \n\nThe first query is on the section from City 1 to 7. There is only one train\nthat runs strictly within that section: Train 1. The second query is on the\nsection from City 3 to 10. There is only one train that runs strictly within\nthat section: Train 3.\n\n* * *"}, {"input": "10 10 10\n 1 6\n 2 9\n 4 5\n 4 7\n 4 7\n 5 8\n 6 6\n 6 7\n 7 9\n 10 10\n 1 8\n 1 9\n 1 10\n 2 8\n 2 9\n 2 10\n 3 8\n 3 9\n 3 10\n 1 10", "output": "7\n 9\n 10\n 6\n 8\n 9\n 6\n 7\n 8\n 10"}]
|
Print Q lines. The i-th line should contain the number of the trains that runs
**strictly within** the section from City p_i to City q_i.
* * *
|
s254199033
|
Accepted
|
p03283
|
Input is given from Standard Input in the following format:
N M Q
L_1 R_1
L_2 R_2
:
L_M R_M
p_1 q_1
p_2 q_2
:
p_Q q_Q
|
class Cumsum2d(object):
def __init__(self, a):
self.a = a
self.h = len(a)
self.w = len(a[0])
self._cumsum = [[0 for _ in range(self.w + 1)] for _ in range(self.h + 1)]
self._preprocess()
def _preprocess(self):
for i in range(1, self.h + 1):
for j in range(1, self.w + 1):
self._cumsum[i][j] = (
self.a[i - 1][j - 1]
+ self._cumsum[i][j - 1]
+ self._cumsum[i - 1][j]
- self._cumsum[i - 1][j - 1]
)
def query(self, h1, h2, w1, w2):
return (
self._cumsum[h2][w2]
- self._cumsum[h1][w2]
- self._cumsum[h2][w1]
+ self._cumsum[h1][w1]
)
if __name__ == "__main__":
N, M, Q = [int(x) for x in input().split(" ")]
# L = [0 for _ in range(N + 2)]
count = [[0 for _ in range(N + 1)] for _ in range(N + 1)]
for _ in range(M):
l, r = [int(x) for x in input().split(" ")]
count[l][r] += 1
cumsum = Cumsum2d(count)
for _ in range(Q):
p, q = [int(x) for x in input().split(" ")]
print(cumsum.query(p, q + 1, p, q + 1))
|
Statement
In Takahashi Kingdom, there is a east-west railroad and N cities along it,
numbered 1, 2, 3, ..., N from west to east. A company called _AtCoder Express_
possesses M trains, and the train i runs from City L_i to City R_i (it is
possible that L_i = R_i). Takahashi the king is interested in the following Q
matters:
* The number of the trains that runs **strictly within** the section from City p_i to City q_i, that is, the number of trains j such that p_i \leq L_j and R_j \leq q_i.
Although he is genius, this is too much data to process by himself. Find the
answer for each of these Q queries to help him.
|
[{"input": "2 3 1\n 1 1\n 1 2\n 2 2\n 1 2", "output": "3\n \n\nAs all the trains runs within the section from City 1 to City 2, the answer to\nthe only query is 3.\n\n* * *"}, {"input": "10 3 2\n 1 5\n 2 8\n 7 10\n 1 7\n 3 10", "output": "1\n 1\n \n\nThe first query is on the section from City 1 to 7. There is only one train\nthat runs strictly within that section: Train 1. The second query is on the\nsection from City 3 to 10. There is only one train that runs strictly within\nthat section: Train 3.\n\n* * *"}, {"input": "10 10 10\n 1 6\n 2 9\n 4 5\n 4 7\n 4 7\n 5 8\n 6 6\n 6 7\n 7 9\n 10 10\n 1 8\n 1 9\n 1 10\n 2 8\n 2 9\n 2 10\n 3 8\n 3 9\n 3 10\n 1 10", "output": "7\n 9\n 10\n 6\n 8\n 9\n 6\n 7\n 8\n 10"}]
|
Print Q lines. The i-th line should contain the number of the trains that runs
**strictly within** the section from City p_i to City q_i.
* * *
|
s654473927
|
Accepted
|
p03283
|
Input is given from Standard Input in the following format:
N M Q
L_1 R_1
L_2 R_2
:
L_M R_M
p_1 q_1
p_2 q_2
:
p_Q q_Q
|
import os
import sys
if os.getenv("LOCAL"):
sys.stdin = open("_in.txt", "r")
sys.setrecursionlimit(10**9)
INF = float("inf")
IINF = 10**18
MOD = 10**9 + 7
# MOD = 998244353
class BinaryIndexedTree:
# http://hos.ac/slides/20140319_bit.pdf
def __init__(self, size):
"""
:param int size:
"""
self._bit = [0] * size
self._size = size
def add(self, i, w):
"""
i 番目に w を加える
:param int i:
:param int w:
"""
x = i + 1
while x <= self._size:
self._bit[x - 1] += w
x += x & -x
def sum(self, i):
"""
[0, i) の合計
:param int i:
"""
ret = 0
while i > 0:
ret += self._bit[i - 1]
i -= i & -i
return ret
def __len__(self):
return self._size
def argsort(li, key=None, reverse=False):
return [
i
for _, i in sorted(
[(a, i) for i, a in enumerate(li)],
key=(lambda t: key(t[0])) if key else None,
reverse=reverse,
)
]
N, M, Q = list(map(int, sys.stdin.buffer.readline().split()))
LR = [list(map(int, sys.stdin.buffer.readline().split())) for _ in range(M)]
PQ = [list(map(int, sys.stdin.buffer.readline().split())) for _ in range(Q)]
LR.sort(reverse=True)
idx = argsort(PQ, reverse=True)
PQ.sort(reverse=True)
lri = 0
bit = BinaryIndexedTree(size=N + 1)
ans = [0] * Q
for i, (p, q) in enumerate(PQ):
while lri < len(LR) and LR[lri][0] >= p:
l, r = LR[lri]
bit.add(r, 1)
lri += 1
ans[idx[i]] = bit.sum(q + 1)
print(*ans, sep="\n")
|
Statement
In Takahashi Kingdom, there is a east-west railroad and N cities along it,
numbered 1, 2, 3, ..., N from west to east. A company called _AtCoder Express_
possesses M trains, and the train i runs from City L_i to City R_i (it is
possible that L_i = R_i). Takahashi the king is interested in the following Q
matters:
* The number of the trains that runs **strictly within** the section from City p_i to City q_i, that is, the number of trains j such that p_i \leq L_j and R_j \leq q_i.
Although he is genius, this is too much data to process by himself. Find the
answer for each of these Q queries to help him.
|
[{"input": "2 3 1\n 1 1\n 1 2\n 2 2\n 1 2", "output": "3\n \n\nAs all the trains runs within the section from City 1 to City 2, the answer to\nthe only query is 3.\n\n* * *"}, {"input": "10 3 2\n 1 5\n 2 8\n 7 10\n 1 7\n 3 10", "output": "1\n 1\n \n\nThe first query is on the section from City 1 to 7. There is only one train\nthat runs strictly within that section: Train 1. The second query is on the\nsection from City 3 to 10. There is only one train that runs strictly within\nthat section: Train 3.\n\n* * *"}, {"input": "10 10 10\n 1 6\n 2 9\n 4 5\n 4 7\n 4 7\n 5 8\n 6 6\n 6 7\n 7 9\n 10 10\n 1 8\n 1 9\n 1 10\n 2 8\n 2 9\n 2 10\n 3 8\n 3 9\n 3 10\n 1 10", "output": "7\n 9\n 10\n 6\n 8\n 9\n 6\n 7\n 8\n 10"}]
|
Print the earliest possible time for the kangaroo to reach coordinate X.
* * *
|
s892311684
|
Accepted
|
p03779
|
The input is given from Standard Input in the following format:
X
|
print(int(((8 * int(input()) + 1.000000000001) ** 0.5 - 1) / 2 + 0.99999999))
|
Statement
There is a kangaroo at coordinate 0 on an infinite number line that runs from
left to right, at time 0. During the period between time i-1 and time i, the
kangaroo can either stay at his position, or perform a jump of length exactly
i to the left or to the right. That is, if his coordinate at time i-1 is x, he
can be at coordinate x-i, x or x+i at time i. The kangaroo's nest is at
coordinate X, and he wants to travel to coordinate X as fast as possible. Find
the earliest possible time to reach coordinate X.
|
[{"input": "6", "output": "3\n \n\nThe kangaroo can reach his nest at time 3 by jumping to the right three times,\nwhich is the earliest possible time.\n\n* * *"}, {"input": "2", "output": "2\n \n\nHe can reach his nest at time 2 by staying at his position during the first\nsecond, and jumping to the right at the next second.\n\n* * *"}, {"input": "11", "output": "5"}]
|
Print the earliest possible time for the kangaroo to reach coordinate X.
* * *
|
s555199939
|
Runtime Error
|
p03779
|
The input is given from Standard Input in the following format:
X
|
X=abs(int(input()))
ct=1
sum=1
while X<=sum:
ct+=1
sub+=ct
print(ct)X=int(input())
ct=1
sum=1
while X>sum:
ct+=1
sum+=ct
print(ct)
|
Statement
There is a kangaroo at coordinate 0 on an infinite number line that runs from
left to right, at time 0. During the period between time i-1 and time i, the
kangaroo can either stay at his position, or perform a jump of length exactly
i to the left or to the right. That is, if his coordinate at time i-1 is x, he
can be at coordinate x-i, x or x+i at time i. The kangaroo's nest is at
coordinate X, and he wants to travel to coordinate X as fast as possible. Find
the earliest possible time to reach coordinate X.
|
[{"input": "6", "output": "3\n \n\nThe kangaroo can reach his nest at time 3 by jumping to the right three times,\nwhich is the earliest possible time.\n\n* * *"}, {"input": "2", "output": "2\n \n\nHe can reach his nest at time 2 by staying at his position during the first\nsecond, and jumping to the right at the next second.\n\n* * *"}, {"input": "11", "output": "5"}]
|
Print the earliest possible time for the kangaroo to reach coordinate X.
* * *
|
s728949422
|
Wrong Answer
|
p03779
|
The input is given from Standard Input in the following format:
X
|
y = int(input()) * 2
a = [x * (x + 1) for x in range(100000) if x * (x + 1) <= y]
print(len(a))
|
Statement
There is a kangaroo at coordinate 0 on an infinite number line that runs from
left to right, at time 0. During the period between time i-1 and time i, the
kangaroo can either stay at his position, or perform a jump of length exactly
i to the left or to the right. That is, if his coordinate at time i-1 is x, he
can be at coordinate x-i, x or x+i at time i. The kangaroo's nest is at
coordinate X, and he wants to travel to coordinate X as fast as possible. Find
the earliest possible time to reach coordinate X.
|
[{"input": "6", "output": "3\n \n\nThe kangaroo can reach his nest at time 3 by jumping to the right three times,\nwhich is the earliest possible time.\n\n* * *"}, {"input": "2", "output": "2\n \n\nHe can reach his nest at time 2 by staying at his position during the first\nsecond, and jumping to the right at the next second.\n\n* * *"}, {"input": "11", "output": "5"}]
|
Print the earliest possible time for the kangaroo to reach coordinate X.
* * *
|
s135210386
|
Accepted
|
p03779
|
The input is given from Standard Input in the following format:
X
|
ans = (int(input()) * 8 + 1) ** 0.5 - 1
if not ans.is_integer():
ans += 2
print(int(ans // 2))
|
Statement
There is a kangaroo at coordinate 0 on an infinite number line that runs from
left to right, at time 0. During the period between time i-1 and time i, the
kangaroo can either stay at his position, or perform a jump of length exactly
i to the left or to the right. That is, if his coordinate at time i-1 is x, he
can be at coordinate x-i, x or x+i at time i. The kangaroo's nest is at
coordinate X, and he wants to travel to coordinate X as fast as possible. Find
the earliest possible time to reach coordinate X.
|
[{"input": "6", "output": "3\n \n\nThe kangaroo can reach his nest at time 3 by jumping to the right three times,\nwhich is the earliest possible time.\n\n* * *"}, {"input": "2", "output": "2\n \n\nHe can reach his nest at time 2 by staying at his position during the first\nsecond, and jumping to the right at the next second.\n\n* * *"}, {"input": "11", "output": "5"}]
|
Print the earliest possible time for the kangaroo to reach coordinate X.
* * *
|
s591833032
|
Runtime Error
|
p03779
|
The input is given from Standard Input in the following format:
X
|
import numpy as np
x = int(input())
t = (-1 + np.sqrt(1 + 8 * x)) /? 2
t = int(t)
print(t + 1)
|
Statement
There is a kangaroo at coordinate 0 on an infinite number line that runs from
left to right, at time 0. During the period between time i-1 and time i, the
kangaroo can either stay at his position, or perform a jump of length exactly
i to the left or to the right. That is, if his coordinate at time i-1 is x, he
can be at coordinate x-i, x or x+i at time i. The kangaroo's nest is at
coordinate X, and he wants to travel to coordinate X as fast as possible. Find
the earliest possible time to reach coordinate X.
|
[{"input": "6", "output": "3\n \n\nThe kangaroo can reach his nest at time 3 by jumping to the right three times,\nwhich is the earliest possible time.\n\n* * *"}, {"input": "2", "output": "2\n \n\nHe can reach his nest at time 2 by staying at his position during the first\nsecond, and jumping to the right at the next second.\n\n* * *"}, {"input": "11", "output": "5"}]
|
Print the earliest possible time for the kangaroo to reach coordinate X.
* * *
|
s973563923
|
Runtime Error
|
p03779
|
The input is given from Standard Input in the following format:
X
|
https://www.lifehacker.jp/2017/11/171127_kakei_17.html?utm_source=dlvr.it&utm_medium=twitter
|
Statement
There is a kangaroo at coordinate 0 on an infinite number line that runs from
left to right, at time 0. During the period between time i-1 and time i, the
kangaroo can either stay at his position, or perform a jump of length exactly
i to the left or to the right. That is, if his coordinate at time i-1 is x, he
can be at coordinate x-i, x or x+i at time i. The kangaroo's nest is at
coordinate X, and he wants to travel to coordinate X as fast as possible. Find
the earliest possible time to reach coordinate X.
|
[{"input": "6", "output": "3\n \n\nThe kangaroo can reach his nest at time 3 by jumping to the right three times,\nwhich is the earliest possible time.\n\n* * *"}, {"input": "2", "output": "2\n \n\nHe can reach his nest at time 2 by staying at his position during the first\nsecond, and jumping to the right at the next second.\n\n* * *"}, {"input": "11", "output": "5"}]
|
Print the earliest possible time for the kangaroo to reach coordinate X.
* * *
|
s592360787
|
Accepted
|
p03779
|
The input is given from Standard Input in the following format:
X
|
print(int((1 + (8 * int(input()) - 7) ** 0.5) / 2))
|
Statement
There is a kangaroo at coordinate 0 on an infinite number line that runs from
left to right, at time 0. During the period between time i-1 and time i, the
kangaroo can either stay at his position, or perform a jump of length exactly
i to the left or to the right. That is, if his coordinate at time i-1 is x, he
can be at coordinate x-i, x or x+i at time i. The kangaroo's nest is at
coordinate X, and he wants to travel to coordinate X as fast as possible. Find
the earliest possible time to reach coordinate X.
|
[{"input": "6", "output": "3\n \n\nThe kangaroo can reach his nest at time 3 by jumping to the right three times,\nwhich is the earliest possible time.\n\n* * *"}, {"input": "2", "output": "2\n \n\nHe can reach his nest at time 2 by staying at his position during the first\nsecond, and jumping to the right at the next second.\n\n* * *"}, {"input": "11", "output": "5"}]
|
Print the earliest possible time for the kangaroo to reach coordinate X.
* * *
|
s831284117
|
Accepted
|
p03779
|
The input is given from Standard Input in the following format:
X
|
n = int(input())
p = int(-0.5 + (2 * n + 0.25) ** 0.5)
q = p * (p + 1) // 2
print(p if q == n else p + 1)
|
Statement
There is a kangaroo at coordinate 0 on an infinite number line that runs from
left to right, at time 0. During the period between time i-1 and time i, the
kangaroo can either stay at his position, or perform a jump of length exactly
i to the left or to the right. That is, if his coordinate at time i-1 is x, he
can be at coordinate x-i, x or x+i at time i. The kangaroo's nest is at
coordinate X, and he wants to travel to coordinate X as fast as possible. Find
the earliest possible time to reach coordinate X.
|
[{"input": "6", "output": "3\n \n\nThe kangaroo can reach his nest at time 3 by jumping to the right three times,\nwhich is the earliest possible time.\n\n* * *"}, {"input": "2", "output": "2\n \n\nHe can reach his nest at time 2 by staying at his position during the first\nsecond, and jumping to the right at the next second.\n\n* * *"}, {"input": "11", "output": "5"}]
|
Print the earliest possible time for the kangaroo to reach coordinate X.
* * *
|
s593161085
|
Accepted
|
p03779
|
The input is given from Standard Input in the following format:
X
|
print(round((2 * int(input())) ** 0.5))
|
Statement
There is a kangaroo at coordinate 0 on an infinite number line that runs from
left to right, at time 0. During the period between time i-1 and time i, the
kangaroo can either stay at his position, or perform a jump of length exactly
i to the left or to the right. That is, if his coordinate at time i-1 is x, he
can be at coordinate x-i, x or x+i at time i. The kangaroo's nest is at
coordinate X, and he wants to travel to coordinate X as fast as possible. Find
the earliest possible time to reach coordinate X.
|
[{"input": "6", "output": "3\n \n\nThe kangaroo can reach his nest at time 3 by jumping to the right three times,\nwhich is the earliest possible time.\n\n* * *"}, {"input": "2", "output": "2\n \n\nHe can reach his nest at time 2 by staying at his position during the first\nsecond, and jumping to the right at the next second.\n\n* * *"}, {"input": "11", "output": "5"}]
|
Print the earliest possible time for the kangaroo to reach coordinate X.
* * *
|
s586258331
|
Runtime Error
|
p03779
|
The input is given from Standard Input in the following format:
X
|
X = int(input())
L = 0
for i in range(1, X) :
L += i
if L >= X :
|
Statement
There is a kangaroo at coordinate 0 on an infinite number line that runs from
left to right, at time 0. During the period between time i-1 and time i, the
kangaroo can either stay at his position, or perform a jump of length exactly
i to the left or to the right. That is, if his coordinate at time i-1 is x, he
can be at coordinate x-i, x or x+i at time i. The kangaroo's nest is at
coordinate X, and he wants to travel to coordinate X as fast as possible. Find
the earliest possible time to reach coordinate X.
|
[{"input": "6", "output": "3\n \n\nThe kangaroo can reach his nest at time 3 by jumping to the right three times,\nwhich is the earliest possible time.\n\n* * *"}, {"input": "2", "output": "2\n \n\nHe can reach his nest at time 2 by staying at his position during the first\nsecond, and jumping to the right at the next second.\n\n* * *"}, {"input": "11", "output": "5"}]
|
Print the earliest possible time for the kangaroo to reach coordinate X.
* * *
|
s936856555
|
Runtime Error
|
p03779
|
The input is given from Standard Input in the following format:
X
|
x=int(input())
n=0
while 2x>n*n+n:
n+=1
print(n)
|
Statement
There is a kangaroo at coordinate 0 on an infinite number line that runs from
left to right, at time 0. During the period between time i-1 and time i, the
kangaroo can either stay at his position, or perform a jump of length exactly
i to the left or to the right. That is, if his coordinate at time i-1 is x, he
can be at coordinate x-i, x or x+i at time i. The kangaroo's nest is at
coordinate X, and he wants to travel to coordinate X as fast as possible. Find
the earliest possible time to reach coordinate X.
|
[{"input": "6", "output": "3\n \n\nThe kangaroo can reach his nest at time 3 by jumping to the right three times,\nwhich is the earliest possible time.\n\n* * *"}, {"input": "2", "output": "2\n \n\nHe can reach his nest at time 2 by staying at his position during the first\nsecond, and jumping to the right at the next second.\n\n* * *"}, {"input": "11", "output": "5"}]
|
Print the earliest possible time for the kangaroo to reach coordinate X.
* * *
|
s299108132
|
Runtime Error
|
p03779
|
The input is given from Standard Input in the following format:
X
|
X = int(input())
i = 0
sum = 0
while sum < X:
i += 1
sum += i
print(i)
|
Statement
There is a kangaroo at coordinate 0 on an infinite number line that runs from
left to right, at time 0. During the period between time i-1 and time i, the
kangaroo can either stay at his position, or perform a jump of length exactly
i to the left or to the right. That is, if his coordinate at time i-1 is x, he
can be at coordinate x-i, x or x+i at time i. The kangaroo's nest is at
coordinate X, and he wants to travel to coordinate X as fast as possible. Find
the earliest possible time to reach coordinate X.
|
[{"input": "6", "output": "3\n \n\nThe kangaroo can reach his nest at time 3 by jumping to the right three times,\nwhich is the earliest possible time.\n\n* * *"}, {"input": "2", "output": "2\n \n\nHe can reach his nest at time 2 by staying at his position during the first\nsecond, and jumping to the right at the next second.\n\n* * *"}, {"input": "11", "output": "5"}]
|
Print the earliest possible time for the kangaroo to reach coordinate X.
* * *
|
s624807185
|
Wrong Answer
|
p03779
|
The input is given from Standard Input in the following format:
X
|
# むねん
|
Statement
There is a kangaroo at coordinate 0 on an infinite number line that runs from
left to right, at time 0. During the period between time i-1 and time i, the
kangaroo can either stay at his position, or perform a jump of length exactly
i to the left or to the right. That is, if his coordinate at time i-1 is x, he
can be at coordinate x-i, x or x+i at time i. The kangaroo's nest is at
coordinate X, and he wants to travel to coordinate X as fast as possible. Find
the earliest possible time to reach coordinate X.
|
[{"input": "6", "output": "3\n \n\nThe kangaroo can reach his nest at time 3 by jumping to the right three times,\nwhich is the earliest possible time.\n\n* * *"}, {"input": "2", "output": "2\n \n\nHe can reach his nest at time 2 by staying at his position during the first\nsecond, and jumping to the right at the next second.\n\n* * *"}, {"input": "11", "output": "5"}]
|
Print the earliest possible time for the kangaroo to reach coordinate X.
* * *
|
s885479296
|
Wrong Answer
|
p03779
|
The input is given from Standard Input in the following format:
X
|
print(((-1 + (1 + 8 * int(input())) ** 0.5) // 2 + 1))
|
Statement
There is a kangaroo at coordinate 0 on an infinite number line that runs from
left to right, at time 0. During the period between time i-1 and time i, the
kangaroo can either stay at his position, or perform a jump of length exactly
i to the left or to the right. That is, if his coordinate at time i-1 is x, he
can be at coordinate x-i, x or x+i at time i. The kangaroo's nest is at
coordinate X, and he wants to travel to coordinate X as fast as possible. Find
the earliest possible time to reach coordinate X.
|
[{"input": "6", "output": "3\n \n\nThe kangaroo can reach his nest at time 3 by jumping to the right three times,\nwhich is the earliest possible time.\n\n* * *"}, {"input": "2", "output": "2\n \n\nHe can reach his nest at time 2 by staying at his position during the first\nsecond, and jumping to the right at the next second.\n\n* * *"}, {"input": "11", "output": "5"}]
|
Print the earliest possible time for the kangaroo to reach coordinate X.
* * *
|
s334234166
|
Wrong Answer
|
p03779
|
The input is given from Standard Input in the following format:
X
|
import fileinput
def algorithm(X):
return int(X // 2) if X > 2 else X
def pass_inputs(input_lines):
X = input_lines[0][0]
return algorithm(X)
def convert_int(s):
try:
r = int(s)
except ValueError:
r = s
return r
def run():
out = pass_inputs(
[[convert_int(v) for v in l.strip().split(" ")] for l in fileinput.input()]
)
print(out)
if __name__ == "__main__":
run()
|
Statement
There is a kangaroo at coordinate 0 on an infinite number line that runs from
left to right, at time 0. During the period between time i-1 and time i, the
kangaroo can either stay at his position, or perform a jump of length exactly
i to the left or to the right. That is, if his coordinate at time i-1 is x, he
can be at coordinate x-i, x or x+i at time i. The kangaroo's nest is at
coordinate X, and he wants to travel to coordinate X as fast as possible. Find
the earliest possible time to reach coordinate X.
|
[{"input": "6", "output": "3\n \n\nThe kangaroo can reach his nest at time 3 by jumping to the right three times,\nwhich is the earliest possible time.\n\n* * *"}, {"input": "2", "output": "2\n \n\nHe can reach his nest at time 2 by staying at his position during the first\nsecond, and jumping to the right at the next second.\n\n* * *"}, {"input": "11", "output": "5"}]
|
Print the earliest possible time for the kangaroo to reach coordinate X.
* * *
|
s584353770
|
Runtime Error
|
p03779
|
The input is given from Standard Input in the following format:
X
|
import sys
f = open('ABC.txt', 'r')
sys.stdin = f
import bisect
n = int(input())
x = 0
i = 1
x_list = []
while x <= n:
x += i
if x > n:
break
x_list.append(x)
i += 1
if n == 2:
print(2)
else:
if n in x_list:
print(x_list.index(n)+1)"""
else:
idx = bisect.bisect_left(x_list, n)
idx -= 2
print(n-x_list[idx])"""
|
Statement
There is a kangaroo at coordinate 0 on an infinite number line that runs from
left to right, at time 0. During the period between time i-1 and time i, the
kangaroo can either stay at his position, or perform a jump of length exactly
i to the left or to the right. That is, if his coordinate at time i-1 is x, he
can be at coordinate x-i, x or x+i at time i. The kangaroo's nest is at
coordinate X, and he wants to travel to coordinate X as fast as possible. Find
the earliest possible time to reach coordinate X.
|
[{"input": "6", "output": "3\n \n\nThe kangaroo can reach his nest at time 3 by jumping to the right three times,\nwhich is the earliest possible time.\n\n* * *"}, {"input": "2", "output": "2\n \n\nHe can reach his nest at time 2 by staying at his position during the first\nsecond, and jumping to the right at the next second.\n\n* * *"}, {"input": "11", "output": "5"}]
|
Print the earliest possible time for the kangaroo to reach coordinate X.
* * *
|
s074698754
|
Runtime Error
|
p03779
|
The input is given from Standard Input in the following format:
X
|
a = int(input())
i = 1
j = 0
ans = 0
while True:
ans += 1
j += i
i += 1
if j >= a:
print(ans)
break
|
Statement
There is a kangaroo at coordinate 0 on an infinite number line that runs from
left to right, at time 0. During the period between time i-1 and time i, the
kangaroo can either stay at his position, or perform a jump of length exactly
i to the left or to the right. That is, if his coordinate at time i-1 is x, he
can be at coordinate x-i, x or x+i at time i. The kangaroo's nest is at
coordinate X, and he wants to travel to coordinate X as fast as possible. Find
the earliest possible time to reach coordinate X.
|
[{"input": "6", "output": "3\n \n\nThe kangaroo can reach his nest at time 3 by jumping to the right three times,\nwhich is the earliest possible time.\n\n* * *"}, {"input": "2", "output": "2\n \n\nHe can reach his nest at time 2 by staying at his position during the first\nsecond, and jumping to the right at the next second.\n\n* * *"}, {"input": "11", "output": "5"}]
|
Print the earliest possible time for the kangaroo to reach coordinate X.
* * *
|
s416423850
|
Runtime Error
|
p03779
|
The input is given from Standard Input in the following format:
X
|
n = int(input())
ng =0 ok=n
while abs(ok-ng)>1:
mid=(ok+ng)//2
if mid*(1+mid)//2>=n:
ok=mid
else:
ng = mid
if ok != n:
ok+=1
print(ok)
|
Statement
There is a kangaroo at coordinate 0 on an infinite number line that runs from
left to right, at time 0. During the period between time i-1 and time i, the
kangaroo can either stay at his position, or perform a jump of length exactly
i to the left or to the right. That is, if his coordinate at time i-1 is x, he
can be at coordinate x-i, x or x+i at time i. The kangaroo's nest is at
coordinate X, and he wants to travel to coordinate X as fast as possible. Find
the earliest possible time to reach coordinate X.
|
[{"input": "6", "output": "3\n \n\nThe kangaroo can reach his nest at time 3 by jumping to the right three times,\nwhich is the earliest possible time.\n\n* * *"}, {"input": "2", "output": "2\n \n\nHe can reach his nest at time 2 by staying at his position during the first\nsecond, and jumping to the right at the next second.\n\n* * *"}, {"input": "11", "output": "5"}]
|
Print the earliest possible time for the kangaroo to reach coordinate X.
* * *
|
s730644991
|
Runtime Error
|
p03779
|
The input is given from Standard Input in the following format:
X
|
X = int(input())
L = 0
for t in range(1, X) :
L += t
if L >= X :
print(t)
break
|
Statement
There is a kangaroo at coordinate 0 on an infinite number line that runs from
left to right, at time 0. During the period between time i-1 and time i, the
kangaroo can either stay at his position, or perform a jump of length exactly
i to the left or to the right. That is, if his coordinate at time i-1 is x, he
can be at coordinate x-i, x or x+i at time i. The kangaroo's nest is at
coordinate X, and he wants to travel to coordinate X as fast as possible. Find
the earliest possible time to reach coordinate X.
|
[{"input": "6", "output": "3\n \n\nThe kangaroo can reach his nest at time 3 by jumping to the right three times,\nwhich is the earliest possible time.\n\n* * *"}, {"input": "2", "output": "2\n \n\nHe can reach his nest at time 2 by staying at his position during the first\nsecond, and jumping to the right at the next second.\n\n* * *"}, {"input": "11", "output": "5"}]
|
Print the earliest possible time for the kangaroo to reach coordinate X.
* * *
|
s789905856
|
Runtime Error
|
p03779
|
The input is given from Standard Input in the following format:
X
|
X = int(input())
for t in range(1:X):
total = t*(t+1)/2
if total>=X:
print(t)
break
|
Statement
There is a kangaroo at coordinate 0 on an infinite number line that runs from
left to right, at time 0. During the period between time i-1 and time i, the
kangaroo can either stay at his position, or perform a jump of length exactly
i to the left or to the right. That is, if his coordinate at time i-1 is x, he
can be at coordinate x-i, x or x+i at time i. The kangaroo's nest is at
coordinate X, and he wants to travel to coordinate X as fast as possible. Find
the earliest possible time to reach coordinate X.
|
[{"input": "6", "output": "3\n \n\nThe kangaroo can reach his nest at time 3 by jumping to the right three times,\nwhich is the earliest possible time.\n\n* * *"}, {"input": "2", "output": "2\n \n\nHe can reach his nest at time 2 by staying at his position during the first\nsecond, and jumping to the right at the next second.\n\n* * *"}, {"input": "11", "output": "5"}]
|
If at least x operations are required to withdraw exactly N yen in total,
print x.
* * *
|
s684224996
|
Accepted
|
p03329
|
Input is given from Standard Input in the following format:
N
|
N = int(input())
list1 = [0] * (N + 1)
for i in range(1, N + 1):
list2 = [list1[i - 1]]
l = list2.append
if i >= 6:
l(list1[i - 6])
if i >= 9:
l(list1[i - 9])
if i >= 36:
l(list1[i - 36])
if i >= 81:
l(list1[i - 81])
if i >= 216:
l(list1[i - 216])
if i >= 729:
l(list1[i - 729])
if i >= 1296:
l(list1[i - 1296])
if i >= 6561:
l(list1[i - 6561])
if i >= 7776:
l(list1[i - 7776])
if i >= 46656:
l(list1[i - 46656])
if i >= 59049:
l(list1[i - 59049])
list1[i] = min(list2) + 1
print(list1[N])
|
Statement
To make it difficult to withdraw money, a certain bank allows its customers to
withdraw only one of the following amounts in one operation:
* 1 yen (the currency of Japan)
* 6 yen, 6^2(=36) yen, 6^3(=216) yen, ...
* 9 yen, 9^2(=81) yen, 9^3(=729) yen, ...
At least how many operations are required to withdraw exactly N yen in total?
It is not allowed to re-deposit the money you withdrew.
|
[{"input": "127", "output": "4\n \n\nBy withdrawing 1 yen, 9 yen, 36(=6^2) yen and 81(=9^2) yen, we can withdraw\n127 yen in four operations.\n\n* * *"}, {"input": "3", "output": "3\n \n\nBy withdrawing 1 yen three times, we can withdraw 3 yen in three operations.\n\n* * *"}, {"input": "44852", "output": "16"}]
|
If at least x operations are required to withdraw exactly N yen in total,
print x.
* * *
|
s788677991
|
Wrong Answer
|
p03329
|
Input is given from Standard Input in the following format:
N
|
def dfs(a, b, c):
todo = [[]]
ret = []
while len(todo) > 0:
t = todo.pop()
l = len(t)
if l == a:
ret.append(t)
else:
s = 0
for i in range(1, l + 1):
s += 6**i * t[i - 1]
for i in range(b + 1):
if s + 6 ** (l + 1) * i <= c:
tc = t.copy()
tc.append(i)
todo.append(tc)
return ret
a = 6
b = 5
c = int(input())
l = dfs(a, b, c)
ans = c
for li in l:
ansi = sum(li)
now = c - sum([6 ** (i + 1) * li[i] for i in range(len(li))])
for i in range(1, 6):
ansi += now % 9
now //= 9
ans = min(ans, ansi)
print(ans)
|
Statement
To make it difficult to withdraw money, a certain bank allows its customers to
withdraw only one of the following amounts in one operation:
* 1 yen (the currency of Japan)
* 6 yen, 6^2(=36) yen, 6^3(=216) yen, ...
* 9 yen, 9^2(=81) yen, 9^3(=729) yen, ...
At least how many operations are required to withdraw exactly N yen in total?
It is not allowed to re-deposit the money you withdrew.
|
[{"input": "127", "output": "4\n \n\nBy withdrawing 1 yen, 9 yen, 36(=6^2) yen and 81(=9^2) yen, we can withdraw\n127 yen in four operations.\n\n* * *"}, {"input": "3", "output": "3\n \n\nBy withdrawing 1 yen three times, we can withdraw 3 yen in three operations.\n\n* * *"}, {"input": "44852", "output": "16"}]
|
If at least x operations are required to withdraw exactly N yen in total,
print x.
* * *
|
s563006658
|
Accepted
|
p03329
|
Input is given from Standard Input in the following format:
N
|
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from functools import *
from itertools import permutations, combinations, groupby
import sys
import bisect
import string
import math
import time
import random
def Golf():
(*a,) = map(int, open(0))
def S_():
return input()
def IS():
return input().split()
def LS():
return [i for i in input().split()]
def I():
return int(input())
def MI():
return map(int, input().split())
def LI():
return [int(i) for i in input().split()]
def LI_():
return [int(i) - 1 for i in input().split()]
def NI(n):
return [int(input()) for i in range(n)]
def NI_(n):
return [int(input()) - 1 for i in range(n)]
def StoI():
return [ord(i) - 97 for i in input()]
def ItoS(nn):
return chr(nn + 97)
def LtoS(ls):
return "".join([chr(i + 97) for i in ls])
def GI(V, E, Directed=False, index=0):
org_inp = []
g = [[] for i in range(n)]
for i in range(E):
inp = LI()
org_inp.append(inp)
if index == 0:
inp[0] -= 1
inp[1] -= 1
if len(inp) == 2:
a, b = inp
g[a].append(b)
if not Directed:
g[b].append(a)
elif len(inp) == 3:
a, b, c = inp
aa = (inp[0], inp[2])
bb = (inp[1], inp[2])
g[a].append(bb)
if not Directed:
g[b].append(aa)
return g, org_inp
def GGI(h, w, search=None, replacement_of_found=".", mp_def={"#": 1, ".": 0}):
# h,w,g,sg=GGI(h,w,search=['S','G'],replacement_of_found='.',mp_def={'#':1,'.':0}) # sample usage
mp = [1] * (w + 2)
found = {}
for i in range(h):
s = input()
for char in search:
if char in s:
found[char] = (i + 1) * (w + 2) + s.index(char) + 1
mp_def[char] = mp_def[replacement_of_found]
mp += [1] + [mp_def[j] for j in s] + [1]
mp += [1] * (w + 2)
return h + 2, w + 2, mp, found
def bit_combination(k, n=2):
rt = []
for tb in range(n**k):
s = [tb // (n**bt) % n for bt in range(k)]
rt += [s]
return rt
def show(*inp, end="\n"):
if show_flg:
print(*inp, end=end)
YN = ["YES", "NO"]
mo = 10**9 + 7
inf = float("inf")
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
# sys.setrecursionlimit(10**7)
input = lambda: sys.stdin.readline().rstrip()
def ran_input():
import random
n = random.randint(4, 16)
rmin, rmax = 1, 10
a = [random.randint(rmin, rmax) for _ in range(n)]
return n, a
show_flg = False
show_flg = True
ans = 0
n = I()
N = 10**5 + 1
dp = [inf] * (N)
dp[0] = 0
six = [6**i for i in range(1, 7)]
nine = [9**i for i in range(6)]
a = six + nine
for i in range(n):
for j in a:
if i + j < N:
dp[i + j] = min(dp[i + j], dp[i] + 1)
print(dp[n])
|
Statement
To make it difficult to withdraw money, a certain bank allows its customers to
withdraw only one of the following amounts in one operation:
* 1 yen (the currency of Japan)
* 6 yen, 6^2(=36) yen, 6^3(=216) yen, ...
* 9 yen, 9^2(=81) yen, 9^3(=729) yen, ...
At least how many operations are required to withdraw exactly N yen in total?
It is not allowed to re-deposit the money you withdrew.
|
[{"input": "127", "output": "4\n \n\nBy withdrawing 1 yen, 9 yen, 36(=6^2) yen and 81(=9^2) yen, we can withdraw\n127 yen in four operations.\n\n* * *"}, {"input": "3", "output": "3\n \n\nBy withdrawing 1 yen three times, we can withdraw 3 yen in three operations.\n\n* * *"}, {"input": "44852", "output": "16"}]
|
If at least x operations are required to withdraw exactly N yen in total,
print x.
* * *
|
s969220942
|
Runtime Error
|
p03329
|
Input is given from Standard Input in the following format:
N
|
INF = 10 ** 20
N = int(input())
coin_list = [1] + [6**i for i in range(1, 7)] + [9**i for i in range(1, 6)]
dp = [INF]*(N+1)
dp[0] = 0
for i in range(1,N+1):
for coin in coin_list:
if i-coin >= 0: dp[i] = min(dp[i], dp[i-coin]+1)
print(dp[N])
|
Statement
To make it difficult to withdraw money, a certain bank allows its customers to
withdraw only one of the following amounts in one operation:
* 1 yen (the currency of Japan)
* 6 yen, 6^2(=36) yen, 6^3(=216) yen, ...
* 9 yen, 9^2(=81) yen, 9^3(=729) yen, ...
At least how many operations are required to withdraw exactly N yen in total?
It is not allowed to re-deposit the money you withdrew.
|
[{"input": "127", "output": "4\n \n\nBy withdrawing 1 yen, 9 yen, 36(=6^2) yen and 81(=9^2) yen, we can withdraw\n127 yen in four operations.\n\n* * *"}, {"input": "3", "output": "3\n \n\nBy withdrawing 1 yen three times, we can withdraw 3 yen in three operations.\n\n* * *"}, {"input": "44852", "output": "16"}]
|
If at least x operations are required to withdraw exactly N yen in total,
print x.
* * *
|
s206139831
|
Runtime Error
|
p03329
|
Input is given from Standard Input in the following format:
N
|
%
n = int(input())
def func(n, i):
ans = 0
while n > 0:
ans += n % i
n // = i
return ans
b = n
for i in range(n+1):
tmp = func(i, 6) + func(n-1, 9)
b = min(tmp, b)
print(b)
|
Statement
To make it difficult to withdraw money, a certain bank allows its customers to
withdraw only one of the following amounts in one operation:
* 1 yen (the currency of Japan)
* 6 yen, 6^2(=36) yen, 6^3(=216) yen, ...
* 9 yen, 9^2(=81) yen, 9^3(=729) yen, ...
At least how many operations are required to withdraw exactly N yen in total?
It is not allowed to re-deposit the money you withdrew.
|
[{"input": "127", "output": "4\n \n\nBy withdrawing 1 yen, 9 yen, 36(=6^2) yen and 81(=9^2) yen, we can withdraw\n127 yen in four operations.\n\n* * *"}, {"input": "3", "output": "3\n \n\nBy withdrawing 1 yen three times, we can withdraw 3 yen in three operations.\n\n* * *"}, {"input": "44852", "output": "16"}]
|
If at least x operations are required to withdraw exactly N yen in total,
print x.
* * *
|
s992152214
|
Accepted
|
p03329
|
Input is given from Standard Input in the following format:
N
|
N = int(input())
cnt = 0
i = 10
dp = [0, 1, 2, 3, 4, 5, 1, 2, 3, 1]
while i <= N:
idx_n, idx_s = 0, 0
while i - (9**idx_n) >= 0:
idx_n += 1
idx_n -= 1
while i - (6**idx_s) >= 0:
idx_s += 1
idx_s -= 1
dp.append(min(1 + dp[i - (9**idx_n)], 1 + dp[i - (6**idx_s)]))
i += 1
print(dp[N])
|
Statement
To make it difficult to withdraw money, a certain bank allows its customers to
withdraw only one of the following amounts in one operation:
* 1 yen (the currency of Japan)
* 6 yen, 6^2(=36) yen, 6^3(=216) yen, ...
* 9 yen, 9^2(=81) yen, 9^3(=729) yen, ...
At least how many operations are required to withdraw exactly N yen in total?
It is not allowed to re-deposit the money you withdrew.
|
[{"input": "127", "output": "4\n \n\nBy withdrawing 1 yen, 9 yen, 36(=6^2) yen and 81(=9^2) yen, we can withdraw\n127 yen in four operations.\n\n* * *"}, {"input": "3", "output": "3\n \n\nBy withdrawing 1 yen three times, we can withdraw 3 yen in three operations.\n\n* * *"}, {"input": "44852", "output": "16"}]
|
If at least x operations are required to withdraw exactly N yen in total,
print x.
* * *
|
s915215362
|
Runtime Error
|
p03329
|
Input is given from Standard Input in the following format:
N
|
n=int(input())
#初期化
#コイン1円
dp=[i for i in range(n+1)]
#コイン6円
i=1
while 6**i<=n:
dp[6**i]=1
i+=1
#コイン6円
i=1
while 9**i<=n:
dp[9**i]=1
i+=1
for i in range(1,n+1):
for j in range(i):
dp[i]=min(dp[i],dp[j]+dp[i-j])
if i%1000==0:
#print(i)
print(dp[-1])
|
Statement
To make it difficult to withdraw money, a certain bank allows its customers to
withdraw only one of the following amounts in one operation:
* 1 yen (the currency of Japan)
* 6 yen, 6^2(=36) yen, 6^3(=216) yen, ...
* 9 yen, 9^2(=81) yen, 9^3(=729) yen, ...
At least how many operations are required to withdraw exactly N yen in total?
It is not allowed to re-deposit the money you withdrew.
|
[{"input": "127", "output": "4\n \n\nBy withdrawing 1 yen, 9 yen, 36(=6^2) yen and 81(=9^2) yen, we can withdraw\n127 yen in four operations.\n\n* * *"}, {"input": "3", "output": "3\n \n\nBy withdrawing 1 yen three times, we can withdraw 3 yen in three operations.\n\n* * *"}, {"input": "44852", "output": "16"}]
|
If at least x operations are required to withdraw exactly N yen in total,
print x.
* * *
|
s204350876
|
Wrong Answer
|
p03329
|
Input is given from Standard Input in the following format:
N
|
table = [1] + [10**10 for i in range(10**6)]
six = [6**i for i in range(1, 8)]
nine = [9**i for i in range(1, 7)]
for i in range(10**5):
table[i + 1] = min(table[i + 1], table[i] + 1)
for x in six:
table[i + x] = min(table[i + x], table[i] + 1)
for y in nine:
table[i + y] = min(table[i + y], table[i] + 1)
print(table[int(input()) - 1])
|
Statement
To make it difficult to withdraw money, a certain bank allows its customers to
withdraw only one of the following amounts in one operation:
* 1 yen (the currency of Japan)
* 6 yen, 6^2(=36) yen, 6^3(=216) yen, ...
* 9 yen, 9^2(=81) yen, 9^3(=729) yen, ...
At least how many operations are required to withdraw exactly N yen in total?
It is not allowed to re-deposit the money you withdrew.
|
[{"input": "127", "output": "4\n \n\nBy withdrawing 1 yen, 9 yen, 36(=6^2) yen and 81(=9^2) yen, we can withdraw\n127 yen in four operations.\n\n* * *"}, {"input": "3", "output": "3\n \n\nBy withdrawing 1 yen three times, we can withdraw 3 yen in three operations.\n\n* * *"}, {"input": "44852", "output": "16"}]
|
If at least x operations are required to withdraw exactly N yen in total,
print x.
* * *
|
s917600710
|
Accepted
|
p03329
|
Input is given from Standard Input in the following format:
N
|
N = int(input())
mi = 100000
for q in range(11120):
a = 0
n = q * 9
pn = N - n
if n > N:
break
for i in range(6, 0, -1):
if n >= 9**i:
a += n // (9**i)
n %= 9**i
for i in range(8, 0, -1):
if pn >= 6**i:
a += pn // (6**i)
pn %= 6**i
a += pn
mi = min(mi, a)
print(mi)
|
Statement
To make it difficult to withdraw money, a certain bank allows its customers to
withdraw only one of the following amounts in one operation:
* 1 yen (the currency of Japan)
* 6 yen, 6^2(=36) yen, 6^3(=216) yen, ...
* 9 yen, 9^2(=81) yen, 9^3(=729) yen, ...
At least how many operations are required to withdraw exactly N yen in total?
It is not allowed to re-deposit the money you withdrew.
|
[{"input": "127", "output": "4\n \n\nBy withdrawing 1 yen, 9 yen, 36(=6^2) yen and 81(=9^2) yen, we can withdraw\n127 yen in four operations.\n\n* * *"}, {"input": "3", "output": "3\n \n\nBy withdrawing 1 yen three times, we can withdraw 3 yen in three operations.\n\n* * *"}, {"input": "44852", "output": "16"}]
|
If at least x operations are required to withdraw exactly N yen in total,
print x.
* * *
|
s868737532
|
Accepted
|
p03329
|
Input is given from Standard Input in the following format:
N
|
###############################################################################
from sys import stdout
from bisect import bisect_left as binl
from copy import copy, deepcopy
from collections import defaultdict
mod = 1
def intin():
input_tuple = input().split()
if len(input_tuple) <= 1:
return int(input_tuple[0])
return tuple(map(int, input_tuple))
def intina():
return [int(i) for i in input().split()]
def intinl(count):
return [intin() for _ in range(count)]
def modadd(x, y):
global mod
return (x + y) % mod
def modmlt(x, y):
global mod
return (x * y) % mod
def lcm(x, y):
while y != 0:
z = x % y
x = y
y = z
return x
def combination(x, y):
assert x >= y
if y > x // 2:
y = x - y
ret = 1
for i in range(0, y):
j = x - i
i = i + 1
ret = ret * j
ret = ret // i
return ret
def get_divisors(x):
retlist = []
for i in range(1, int(x**0.5) + 3):
if x % i == 0:
retlist.append(i)
retlist.append(x // i)
return retlist
def get_factors(x):
retlist = []
for i in range(2, int(x**0.5) + 3):
while x % i == 0:
retlist.append(i)
x = x // i
retlist.append(x)
return retlist
def make_linklist(xylist):
linklist = {}
for a, b in xylist:
linklist.setdefault(a, [])
linklist.setdefault(b, [])
linklist[a].append(b)
linklist[b].append(a)
return linklist
def calc_longest_distance(linklist, v=1):
distance_list = {}
distance_count = 0
distance = 0
vlist_previous = []
vlist = [v]
nodecount = len(linklist)
while distance_count < nodecount:
vlist_next = []
for v in vlist:
distance_list[v] = distance
distance_count += 1
vlist_next.extend(linklist[v])
distance += 1
vlist_to_del = vlist_previous
vlist_previous = vlist
vlist = list(set(vlist_next) - set(vlist_to_del))
max_distance = -1
max_v = None
for v, distance in distance_list.items():
if distance > max_distance:
max_distance = distance
max_v = v
return (max_distance, max_v)
def calc_tree_diameter(linklist, v=1):
_, u = calc_longest_distance(linklist, v)
distance, _ = calc_longest_distance(linklist, u)
return distance
###############################################################################
def main():
n = intin()
ans = n
for i in range(n // 6 + 1):
count = 0
s6 = i * 6
ii = i
for j in range(1, n + 1):
scount = ii % 6
count += scount
ii = ii // 6
s6 -= (6**j) * scount
if not s6:
break
s9 = n - i * 6
ii = s9
for j in range(0, n + 1):
scount = ii % 9
count += scount
ii = ii // 9
s9 -= (9**j) * scount
if not s9:
break
ans = min(ans, count)
print(ans)
if __name__ == "__main__":
main()
|
Statement
To make it difficult to withdraw money, a certain bank allows its customers to
withdraw only one of the following amounts in one operation:
* 1 yen (the currency of Japan)
* 6 yen, 6^2(=36) yen, 6^3(=216) yen, ...
* 9 yen, 9^2(=81) yen, 9^3(=729) yen, ...
At least how many operations are required to withdraw exactly N yen in total?
It is not allowed to re-deposit the money you withdrew.
|
[{"input": "127", "output": "4\n \n\nBy withdrawing 1 yen, 9 yen, 36(=6^2) yen and 81(=9^2) yen, we can withdraw\n127 yen in four operations.\n\n* * *"}, {"input": "3", "output": "3\n \n\nBy withdrawing 1 yen three times, we can withdraw 3 yen in three operations.\n\n* * *"}, {"input": "44852", "output": "16"}]
|
If at least x operations are required to withdraw exactly N yen in total,
print x.
* * *
|
s263909423
|
Runtime Error
|
p03329
|
Input is given from Standard Input in the following format:
N
|
n = int(input())
ans, index6, index9, num6, num9 = 0, 0, 0, 0, 0
INF = float("inf")
def a10_to_n(x, n):
if x // n:
return a10_to_n(x // n, n) + str(x % n)
else:
return str(x)
def index(n, num6, index6, num9, index9):
val = str(a10_to_n(n, 6))
for i, j in enumerate(val):
if int(j) != 0:
num6 = int(j)
index6 = len(val) - i - 1
break
val = str(a10_to_n(n, 9))
for i, j in enumerate(val):
if int(j) != 0:
num9 = int(j)
index9 = len(val) - i - 1
break
return num6, index6, num9, index9
num6, index6, num9, index9 = index(n, num6, index6, num9, index9)
while index6 > 1 or index9 > 1:
if 6**index6 <= 9**index9:
n -= num9 * 9**index9
ans += num9
else:
n -= num6 * 6**index6
ans += num6
num6, index6, num9, index9 = index(n, num6, index6, num9, index9)
a = [INF for _ in range(n + 1)]
a[n] = 0
for i in range(n, -1, -1):
if i - 9 >= 0:
a[i - 9] = min(a[i] + 1, a[i - 9])
if i - 6 >= 0:
a[i - 6] = min(a[i] + 1, a[i - 6])
if i - 1 >= 0:
a[i - 1] = min(a[i] + 1, a[i - 1])
print(ans + a[0])
|
Statement
To make it difficult to withdraw money, a certain bank allows its customers to
withdraw only one of the following amounts in one operation:
* 1 yen (the currency of Japan)
* 6 yen, 6^2(=36) yen, 6^3(=216) yen, ...
* 9 yen, 9^2(=81) yen, 9^3(=729) yen, ...
At least how many operations are required to withdraw exactly N yen in total?
It is not allowed to re-deposit the money you withdrew.
|
[{"input": "127", "output": "4\n \n\nBy withdrawing 1 yen, 9 yen, 36(=6^2) yen and 81(=9^2) yen, we can withdraw\n127 yen in four operations.\n\n* * *"}, {"input": "3", "output": "3\n \n\nBy withdrawing 1 yen three times, we can withdraw 3 yen in three operations.\n\n* * *"}, {"input": "44852", "output": "16"}]
|
If at least x operations are required to withdraw exactly N yen in total,
print x.
* * *
|
s063721349
|
Wrong Answer
|
p03329
|
Input is given from Standard Input in the following format:
N
|
x = int(input())
count = 0
if x >= 9**5:
x -= 9**5
count += 1
for i in range(6, 1, -1):
if x >= 9**i:
while x >= 9**i:
x -= 9**i
count += 1
if x >= 6**i:
while x >= 6**i:
x -= 6**i
count += 1
a = x
p = x
for i in range(x):
for j in range(x):
for l in range(x):
if 9 * i + 6 * j + 1 * l == 23:
b = i + j + l
p = min(p, b)
print(count + p)
|
Statement
To make it difficult to withdraw money, a certain bank allows its customers to
withdraw only one of the following amounts in one operation:
* 1 yen (the currency of Japan)
* 6 yen, 6^2(=36) yen, 6^3(=216) yen, ...
* 9 yen, 9^2(=81) yen, 9^3(=729) yen, ...
At least how many operations are required to withdraw exactly N yen in total?
It is not allowed to re-deposit the money you withdrew.
|
[{"input": "127", "output": "4\n \n\nBy withdrawing 1 yen, 9 yen, 36(=6^2) yen and 81(=9^2) yen, we can withdraw\n127 yen in four operations.\n\n* * *"}, {"input": "3", "output": "3\n \n\nBy withdrawing 1 yen three times, we can withdraw 3 yen in three operations.\n\n* * *"}, {"input": "44852", "output": "16"}]
|
If at least x operations are required to withdraw exactly N yen in total,
print x.
* * *
|
s643093768
|
Accepted
|
p03329
|
Input is given from Standard Input in the following format:
N
|
#####################################################################################################
##### コイン問題
#####################################################################################################
"""
ベンチマーク
コイン問題 (※ larger = False): http://judge.u-aizu.ac.jp/onlinejudge/review.jsp?rid=4696859#1
E - Crested Ibis vs Monster (※ larger = True): https://atcoder.jp/contests/abc153/submissions/15396586
"""
def coin(larger=False, single=False):
"""
ナップサックに入れる重さが W 丁度になる時の価値の最小値
:param larger: False = (重さ = W)の時の最小価値
True = (重さ =< W)の時の最小価値
:param single: False = 重複あり
dp[weight <= W+1] = 重さを固定した時の最小価値
dp[W+1] = 重さがWより大きい時の最小価値
"""
W2 = W + 1 # dp[W+1] に W より大きい時の全ての場合の情報を持たせる
dp_max = float("inf") # 総和価値の最大値
dp = [dp_max] * (W2 + 1)
dp[0] = 0 # 重さ 0 の時は価値 0
for item in range(N):
if single:
S = range(W2, weight_list[item] - 1, -1)
else:
S = range(W2)
for weight in S:
dp[min2(weight + weight_list[item], W2)] = min2(
dp[min2(weight + weight_list[item], W2)], dp[weight] + cost_list[item]
)
if larger:
return min(dp[w] for w in range(W, W2 + 1))
else:
return dp[W]
#######################################################################################################
import sys
input = sys.stdin.readline
def max2(x, y):
return x if x > y else y
def min2(x, y):
return x if x < y else y
W = int(input())
cost_list = [1]
weight_list = [1]
p = 6
while p <= W:
cost_list.append(1)
weight_list.append(p)
p *= 6
p = 9
while p <= W:
cost_list.append(1)
weight_list.append(p)
p *= 9
N = len(weight_list)
print(coin(larger=False, single=False))
|
Statement
To make it difficult to withdraw money, a certain bank allows its customers to
withdraw only one of the following amounts in one operation:
* 1 yen (the currency of Japan)
* 6 yen, 6^2(=36) yen, 6^3(=216) yen, ...
* 9 yen, 9^2(=81) yen, 9^3(=729) yen, ...
At least how many operations are required to withdraw exactly N yen in total?
It is not allowed to re-deposit the money you withdrew.
|
[{"input": "127", "output": "4\n \n\nBy withdrawing 1 yen, 9 yen, 36(=6^2) yen and 81(=9^2) yen, we can withdraw\n127 yen in four operations.\n\n* * *"}, {"input": "3", "output": "3\n \n\nBy withdrawing 1 yen three times, we can withdraw 3 yen in three operations.\n\n* * *"}, {"input": "44852", "output": "16"}]
|
If at least x operations are required to withdraw exactly N yen in total,
print x.
* * *
|
s214417938
|
Runtime Error
|
p03329
|
Input is given from Standard Input in the following format:
N
|
from goto import goto, label
kingaku = int(input())
kaisu = 0
while 1:
label.start
if kingaku > 9**5:
kingaku -= 9**5
kaisu += 1
goto.start
if kingaku > 6**6:
kingaku -= 6**6
kaisu += 1
goto.start
if kingaku > 9**4:
kingaku -= 9**4
kaisu += 1
goto.start
if kingaku > 6**5:
kingaku -= 6**5
kaisu += 1
goto.start
if kingaku > 9**3:
kingaku -= 9**3
kaisu += 1
goto.start
if kingaku > 6**4:
kingaku -= 6**4
kaisu += 1
goto.start
if kingaku > 9**2:
kingaku -= 9**2
kaisu += 1
goto.start
if kingaku > 6**3:
kingaku -= 6**3
kaisu += 1
goto.start
if kingaku > 9**1:
kingaku -= 9**1
kaisu += 1
goto.start
if kingaku > 6**2:
kingaku -= 6**2
kaisu += 1
goto.start
if kingaku > 6**1:
kingaku -= 6**1
kaisu += 1
goto.start
if kingaku > 9**0:
kingaku -= 9**0
kaisu += 1
goto.start
if kingaku == 1:
kaisu += 1
break
print(kaisu)
|
Statement
To make it difficult to withdraw money, a certain bank allows its customers to
withdraw only one of the following amounts in one operation:
* 1 yen (the currency of Japan)
* 6 yen, 6^2(=36) yen, 6^3(=216) yen, ...
* 9 yen, 9^2(=81) yen, 9^3(=729) yen, ...
At least how many operations are required to withdraw exactly N yen in total?
It is not allowed to re-deposit the money you withdrew.
|
[{"input": "127", "output": "4\n \n\nBy withdrawing 1 yen, 9 yen, 36(=6^2) yen and 81(=9^2) yen, we can withdraw\n127 yen in four operations.\n\n* * *"}, {"input": "3", "output": "3\n \n\nBy withdrawing 1 yen three times, we can withdraw 3 yen in three operations.\n\n* * *"}, {"input": "44852", "output": "16"}]
|
If at least x operations are required to withdraw exactly N yen in total,
print x.
* * *
|
s870160837
|
Wrong Answer
|
p03329
|
Input is given from Standard Input in the following format:
N
|
iN = int(input())
"""
9**i
0 1
1 9
2 81
3 729
4 6561
5 59049
1 6
2 36
3 216
4 1296
5 7776
6 46656
1 6
1 9
2 36
2 81
3 216
3 729
4 1296
4 6561
5 7776
6 46656
5 59049
"""
aG = [531441, 59049, 46656, 7776, 6561, 1296, 729, 216, 81, 36, 9, 6, 1]
# aG = [1]
# for i in range(1,7):
# aG.append(9**i)
# aG.append(6**i)
# aG.sort(reverse=True)
# iL = len(aG)
iL = 13
aC = [0] * iL
iC = 0
for i in range(iL):
iPe = 0
a = aG[i]
while a <= iN:
iN -= a
iPe += 1
iC += 1
aC[i] = iPe
# 2*9 + 3 = 1*9 + 2*6 # 5個 -> 3個
if aC[10] >= 2 and aC[12] >= 3:
iC -= 2
print(iC)
|
Statement
To make it difficult to withdraw money, a certain bank allows its customers to
withdraw only one of the following amounts in one operation:
* 1 yen (the currency of Japan)
* 6 yen, 6^2(=36) yen, 6^3(=216) yen, ...
* 9 yen, 9^2(=81) yen, 9^3(=729) yen, ...
At least how many operations are required to withdraw exactly N yen in total?
It is not allowed to re-deposit the money you withdrew.
|
[{"input": "127", "output": "4\n \n\nBy withdrawing 1 yen, 9 yen, 36(=6^2) yen and 81(=9^2) yen, we can withdraw\n127 yen in four operations.\n\n* * *"}, {"input": "3", "output": "3\n \n\nBy withdrawing 1 yen three times, we can withdraw 3 yen in three operations.\n\n* * *"}, {"input": "44852", "output": "16"}]
|
If at least x operations are required to withdraw exactly N yen in total,
print x.
* * *
|
s323804573
|
Runtime Error
|
p03329
|
Input is given from Standard Input in the following format:
N
|
import math
import sys
N = int(sys.stdin.readline())
min_leaf_cnt = math.inf
class Node:
def __init__(self, N, cnt, v):
self.N = N
self.cnt = cnt
self.v = v
self.left = None
self.right = None
if self.cnt < min_leaf_cnt:
self._fill_leaf()
def _fill_leaf(self):
if self.N >= 6:
v = math.pow(6, math.floor(math.log(self.N, 6)))
self.left = Node(self.N - v, self.cnt + 1, v)
if self.N >= 9:
v = math.pow(9, math.floor(math.log(self.N, 9)))
self.right = Node(self.N - v, self.cnt + 1, v)
if self.left is None and self.right is None:
global min_leaf_cnt
if self.cnt + self.N < min_leaf_cnt:
min_leaf_cnt = self.cnt + int(self.N)
Node(N, 0, 0)
print(min_leaf_cnt)
|
Statement
To make it difficult to withdraw money, a certain bank allows its customers to
withdraw only one of the following amounts in one operation:
* 1 yen (the currency of Japan)
* 6 yen, 6^2(=36) yen, 6^3(=216) yen, ...
* 9 yen, 9^2(=81) yen, 9^3(=729) yen, ...
At least how many operations are required to withdraw exactly N yen in total?
It is not allowed to re-deposit the money you withdrew.
|
[{"input": "127", "output": "4\n \n\nBy withdrawing 1 yen, 9 yen, 36(=6^2) yen and 81(=9^2) yen, we can withdraw\n127 yen in four operations.\n\n* * *"}, {"input": "3", "output": "3\n \n\nBy withdrawing 1 yen three times, we can withdraw 3 yen in three operations.\n\n* * *"}, {"input": "44852", "output": "16"}]
|
If at least x operations are required to withdraw exactly N yen in total,
print x.
* * *
|
s114176435
|
Runtime Error
|
p03329
|
Input is given from Standard Input in the following format:
N
|
N = int(input())
i = 0
j = 0
a = [1,6,36,216,1296,7776,46656,9,81,729,6561,59049]
b = a.sort(reverse=True)
while N > 0:
if a[j] > N:
j += 1
if a[j] = N:
N = 0
i += 1
print(i)
if a[j] < N:
N = N-a[j]
i += 1
|
Statement
To make it difficult to withdraw money, a certain bank allows its customers to
withdraw only one of the following amounts in one operation:
* 1 yen (the currency of Japan)
* 6 yen, 6^2(=36) yen, 6^3(=216) yen, ...
* 9 yen, 9^2(=81) yen, 9^3(=729) yen, ...
At least how many operations are required to withdraw exactly N yen in total?
It is not allowed to re-deposit the money you withdrew.
|
[{"input": "127", "output": "4\n \n\nBy withdrawing 1 yen, 9 yen, 36(=6^2) yen and 81(=9^2) yen, we can withdraw\n127 yen in four operations.\n\n* * *"}, {"input": "3", "output": "3\n \n\nBy withdrawing 1 yen three times, we can withdraw 3 yen in three operations.\n\n* * *"}, {"input": "44852", "output": "16"}]
|
If at least x operations are required to withdraw exactly N yen in total,
print x.
* * *
|
s176665938
|
Runtime Error
|
p03329
|
Input is given from Standard Input in the following format:
N
|
N = int(input())
List9 = [9 ** i for i in range(6) if 9 ** i <= N]
List6 = [6 ** i for i in range(6) if 6 ** i <= N]
def recur(n,con):
if n == 0:
return con
"""
elif n < 6:
return con + n
elif n < 9:
return con + (n - 5)
"""
else:
max9 = max([i for i in List9 if i <= n])
max6 = max([i for i in List6 if i <= n])
return min(recur(n - max9,con + 1),recur(n - max6,con + 1))
print(recur(N,0))
|
Statement
To make it difficult to withdraw money, a certain bank allows its customers to
withdraw only one of the following amounts in one operation:
* 1 yen (the currency of Japan)
* 6 yen, 6^2(=36) yen, 6^3(=216) yen, ...
* 9 yen, 9^2(=81) yen, 9^3(=729) yen, ...
At least how many operations are required to withdraw exactly N yen in total?
It is not allowed to re-deposit the money you withdrew.
|
[{"input": "127", "output": "4\n \n\nBy withdrawing 1 yen, 9 yen, 36(=6^2) yen and 81(=9^2) yen, we can withdraw\n127 yen in four operations.\n\n* * *"}, {"input": "3", "output": "3\n \n\nBy withdrawing 1 yen three times, we can withdraw 3 yen in three operations.\n\n* * *"}, {"input": "44852", "output": "16"}]
|
If at least x operations are required to withdraw exactly N yen in total,
print x.
* * *
|
s689541791
|
Runtime Error
|
p03329
|
Input is given from Standard Input in the following format:
N
|
# coding: utf-8
# Your code here!
N=int(input())
l=[1]
count=0
def cand(num):
i=1
while N>=num**i:
l.append(num**i)
i+=1
def sub(target,index):
i=0
if target==0:
elif index==0:
while target-l[index]>0:
sub(target-l[index]**i,l[index-1])
cand(6)
cand(9)
l.sort()
print(l)
#メモ この方針があってるのかもわからん
|
Statement
To make it difficult to withdraw money, a certain bank allows its customers to
withdraw only one of the following amounts in one operation:
* 1 yen (the currency of Japan)
* 6 yen, 6^2(=36) yen, 6^3(=216) yen, ...
* 9 yen, 9^2(=81) yen, 9^3(=729) yen, ...
At least how many operations are required to withdraw exactly N yen in total?
It is not allowed to re-deposit the money you withdrew.
|
[{"input": "127", "output": "4\n \n\nBy withdrawing 1 yen, 9 yen, 36(=6^2) yen and 81(=9^2) yen, we can withdraw\n127 yen in four operations.\n\n* * *"}, {"input": "3", "output": "3\n \n\nBy withdrawing 1 yen three times, we can withdraw 3 yen in three operations.\n\n* * *"}, {"input": "44852", "output": "16"}]
|
If at least x operations are required to withdraw exactly N yen in total,
print x.
* * *
|
s246091849
|
Runtime Error
|
p03329
|
Input is given from Standard Input in the following format:
N
|
six_list = [6 ** i for i in range(1,7)]
nine_list =[9 ** i for i in range(1,6)]
sn_list = sorted(six_list + nine_list)[::-1]
counter = 0
d = 1
while (N > 5):
while(d < 0):
for i in sn_list:
d = N -i
w = i
N = N % w
counter += N //w
counter += N
print(counter)
|
Statement
To make it difficult to withdraw money, a certain bank allows its customers to
withdraw only one of the following amounts in one operation:
* 1 yen (the currency of Japan)
* 6 yen, 6^2(=36) yen, 6^3(=216) yen, ...
* 9 yen, 9^2(=81) yen, 9^3(=729) yen, ...
At least how many operations are required to withdraw exactly N yen in total?
It is not allowed to re-deposit the money you withdrew.
|
[{"input": "127", "output": "4\n \n\nBy withdrawing 1 yen, 9 yen, 36(=6^2) yen and 81(=9^2) yen, we can withdraw\n127 yen in four operations.\n\n* * *"}, {"input": "3", "output": "3\n \n\nBy withdrawing 1 yen three times, we can withdraw 3 yen in three operations.\n\n* * *"}, {"input": "44852", "output": "16"}]
|
If at least x operations are required to withdraw exactly N yen in total,
print x.
* * *
|
s836831060
|
Runtime Error
|
p03329
|
Input is given from Standard Input in the following format:
N
|
from collections import defaultdict
N, C = map(int, input().split())
D = [[int(i) for i in input().split()] for j in range(C)]
co = [[int(i) for i in input().split()] for j in range(N)]
d0 = defaultdict(int)
d1 = defaultdict(int)
d2 = defaultdict(int)
for i in range(N):
for j in range(N):
if (j + i) % 3 == 0:
d0[co[j][i]] += 1
elif (j + i) % 3 == 1:
d1[co[j][i]] += 1
else:
d2[co[j][i]] += 1
A0 = [] # i色に帰るのに必要な違和感
A1 = []
A2 = []
for i in range(C):
iwa = 0
for s in d0.keys():
iwa += D[s - 1][i - 1] * d0[s]
A0.append([iwa, i])
for i in range(C):
iwa = 0
for s in d1.keys():
iwa += D[s - 1][i - 1] * d1[s]
A1.append([iwa, i])
for i in range(C):
iwa = 0
for s in d2.keys():
iwa += D[s - 1][i - 1] * d2[s]
A2.append([iwa, i])
A0.sort()
A1.sort()
A2.sort()
B = [[] for i in range(3)]
for i in range(3):
B[0].append(A0[i])
for i in range(3):
B[1].append(A1[i])
for i in range(3):
B[2].append(A2[i])
ans = []
for i in range(3):
for j in range(3):
for k in range(3):
if B[0][i][1] == B[1][j][1]:
continue
if B[0][i][1] == B[2][k][1]:
continue
if B[1][j][1] == B[2][k][1]:
continue
ans.append(B[0][i][0] + B[1][j][0] + B[2][k][0])
print(min(ans))
|
Statement
To make it difficult to withdraw money, a certain bank allows its customers to
withdraw only one of the following amounts in one operation:
* 1 yen (the currency of Japan)
* 6 yen, 6^2(=36) yen, 6^3(=216) yen, ...
* 9 yen, 9^2(=81) yen, 9^3(=729) yen, ...
At least how many operations are required to withdraw exactly N yen in total?
It is not allowed to re-deposit the money you withdrew.
|
[{"input": "127", "output": "4\n \n\nBy withdrawing 1 yen, 9 yen, 36(=6^2) yen and 81(=9^2) yen, we can withdraw\n127 yen in four operations.\n\n* * *"}, {"input": "3", "output": "3\n \n\nBy withdrawing 1 yen three times, we can withdraw 3 yen in three operations.\n\n* * *"}, {"input": "44852", "output": "16"}]
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.