output_description
stringlengths 15
956
| submission_id
stringlengths 10
10
| status
stringclasses 3
values | problem_id
stringlengths 6
6
| input_description
stringlengths 9
2.55k
| attempt
stringlengths 1
13.7k
| problem_description
stringlengths 7
5.24k
| samples
stringlengths 2
2.72k
|
---|---|---|---|---|---|---|---|
Print the number of the subsequences such that all characters are different,
modulo 10^9+7.
* * *
|
s614365760
|
Runtime Error
|
p03095
|
Input is given from Standard Input in the following format:
N
S
|
n = int(input())
a = [[] for row in range(200000)]
b = 0
e = [int(input()) for i in range(n)]
d = [0]
mini_ans = 0
for i, c in enumerate(e):
if b != c:
for j in a[c]:
mini_ans += d[j] + 1
a[c].append(i)
d.append(mini_ans)
b = c
print(d[-1] + 1)
|
Statement
You are given a string S of length N. Among its subsequences, count the ones
such that all characters are different, modulo 10^9+7. Two subsequences are
considered different if their characters come from different positions in the
string, even if they are the same as strings.
Here, a subsequence of a string is a concatenation of **one or more**
characters from the string without changing the order.
|
[{"input": "4\n abcd", "output": "15\n \n\nSince all characters in S itself are different, all its subsequences satisfy\nthe condition.\n\n* * *"}, {"input": "3\n baa", "output": "5\n \n\nThe answer is five: `b`, two occurrences of `a`, two occurrences of `ba`. Note\nthat we do not count `baa`, since it contains two `a`s.\n\n* * *"}, {"input": "5\n abcab", "output": "17"}]
|
Print the number of the subsequences such that all characters are different,
modulo 10^9+7.
* * *
|
s062522185
|
Wrong Answer
|
p03095
|
Input is given from Standard Input in the following format:
N
S
|
import numpy as np
n = int(input())
s = list(input())
count = []
for i in range(26):
count.append(1)
for i in s:
if i == "a":
count[0] = count[0] + 1
elif i == "b":
count[1] = count[1] + 1
elif i == "c":
count[2] = count[2] + 1
elif i == "d":
count[3] = count[3] + 1
elif i == "e":
count[4] = count[4] + 1
elif i == "f":
count[5] = count[5] + 1
elif i == "g":
count[6] = count[6] + 1
elif i == "h":
count[7] = count[7] + 1
elif i == "i":
count[8] = count[8] + 1
elif i == "j":
count[9] = count[9] + 1
elif i == "k":
count[10] = count[10] + 1
elif i == "l":
count[11] = count[11] + 1
elif i == "m":
count[12] = count[12] + 1
elif i == "n":
count[13] = count[13] + 1
elif i == "o":
count[14] = count[14] + 1
elif i == "p":
count[15] = count[15] + 1
elif i == "q":
count[16] = count[16] + 1
elif i == "r":
count[17] = count[17] + 1
elif i == "s":
count[18] = count[18] + 1
elif i == "t":
count[19] = count[19] + 1
elif i == "u":
count[20] = count[20] + 1
elif i == "v":
count[21] = count[21] + 1
elif i == "w":
count[22] = count[22] + 1
elif i == "x":
count[23] = count[23] + 1
elif i == "y":
count[24] = count[24] + 1
elif i == "z":
count[25] = count[25] + 1
print((np.prod(count) - 1) % (10**9 + 7))
|
Statement
You are given a string S of length N. Among its subsequences, count the ones
such that all characters are different, modulo 10^9+7. Two subsequences are
considered different if their characters come from different positions in the
string, even if they are the same as strings.
Here, a subsequence of a string is a concatenation of **one or more**
characters from the string without changing the order.
|
[{"input": "4\n abcd", "output": "15\n \n\nSince all characters in S itself are different, all its subsequences satisfy\nthe condition.\n\n* * *"}, {"input": "3\n baa", "output": "5\n \n\nThe answer is five: `b`, two occurrences of `a`, two occurrences of `ba`. Note\nthat we do not count `baa`, since it contains two `a`s.\n\n* * *"}, {"input": "5\n abcab", "output": "17"}]
|
Print the number of the subsequences such that all characters are different,
modulo 10^9+7.
* * *
|
s329284013
|
Wrong Answer
|
p03095
|
Input is given from Standard Input in the following format:
N
S
|
import sys
sys.setrecursionlimit(1000000)
# def input():
# return sys.stdin.readline()[:-1]
"""
n=int(input())
for i in range(n):
a[i]=int(input())
a[i],b[i]=map(int,input().split())
a=[int(x) for x in input().split()]
n,m=map(int,input.split())
from operator import itemgetter
a = [(1, "c", 1), (1, "b", 3), (2, "a", 0), (1, "a", 2)]
print(sorted(a)) # 0 番目の要素でソート、先頭の要素が同じなら 1 番目以降の要素も見る
print(sorted(a, key=itemgetter(0))) # 0 番目の要素だけでソート
print(sorted(a, key=itemgetter(0, 2))) # 0 番目と 2 番目の要素でソート
print(sorted(a, key=lambda x: x[0] * x[2])) # 0 番目の要素 * 2 番目の要素でソート
print(sorted(a, reverse=True)) # 降順にソート
a.sort() # 破壊的にソート、sorted() よりも高速
try: # エラーキャッチ list index out of range
for i in range():
k=b[i]
except IndexError as e:
print(i)
"""
test_data1 = """\
4
abcd
"""
test_data2 = """\
3
baa
"""
test_data3 = """\
5
abcab
"""
td_num = 2
def GetTestData(index):
if index == 1:
return test_data1
if index == 2:
return test_data2
if index == 3:
return test_data3
if False:
with open("../test.txt", mode="w") as f:
f.write(GetTestData(td_num))
with open("../test.txt") as f:
# Start Input code ---------------------------------------
# n,m,c=map(int,f.readline().split())
n = int(f.readline())
s = str(f.readline())
# End Input code ---------------------------------------
else:
# Start Input code ---------------------------------------
n = int(input())
s = str(input())
# End Input code ---------------------------------------
# print(n,s)
import string
al = string.ascii_lowercase
cnt = []
for i in range(26):
alc = s.count(al[i])
if alc != 0:
cnt.append(alc)
# print(cnt)
m = len(cnt)
ans = 1
mo = 10**9 + 7
counter = 0
for i in range(m):
ans *= (1 + cnt[i]) % mo
ans -= 1
"""
for i in range(1,2**m):
counter+=1
pat=1
for j in range (m):
#print(int((i % 2**(j+1)) / 2**j))
ind=int((i % 2**(j+1)) / 2**j)
pat*=max(1,cnt[j]*ind) % mo
#print('ind,cnt[ind]=',ind,cnt[ind])
ans+=pat
#print(pat,ans)
#print(bin(i))
"""
print(ans)
|
Statement
You are given a string S of length N. Among its subsequences, count the ones
such that all characters are different, modulo 10^9+7. Two subsequences are
considered different if their characters come from different positions in the
string, even if they are the same as strings.
Here, a subsequence of a string is a concatenation of **one or more**
characters from the string without changing the order.
|
[{"input": "4\n abcd", "output": "15\n \n\nSince all characters in S itself are different, all its subsequences satisfy\nthe condition.\n\n* * *"}, {"input": "3\n baa", "output": "5\n \n\nThe answer is five: `b`, two occurrences of `a`, two occurrences of `ba`. Note\nthat we do not count `baa`, since it contains two `a`s.\n\n* * *"}, {"input": "5\n abcab", "output": "17"}]
|
Print the number of the subsequences such that all characters are different,
modulo 10^9+7.
* * *
|
s355845748
|
Wrong Answer
|
p03095
|
Input is given from Standard Input in the following format:
N
S
|
A = int(input())
V = list(input())
v = len(list(set(V)))
a = 0
if A - v == 0:
a = 1
else:
a = A - v
q = ((2**v) - 1) * a
print(q)
|
Statement
You are given a string S of length N. Among its subsequences, count the ones
such that all characters are different, modulo 10^9+7. Two subsequences are
considered different if their characters come from different positions in the
string, even if they are the same as strings.
Here, a subsequence of a string is a concatenation of **one or more**
characters from the string without changing the order.
|
[{"input": "4\n abcd", "output": "15\n \n\nSince all characters in S itself are different, all its subsequences satisfy\nthe condition.\n\n* * *"}, {"input": "3\n baa", "output": "5\n \n\nThe answer is five: `b`, two occurrences of `a`, two occurrences of `ba`. Note\nthat we do not count `baa`, since it contains two `a`s.\n\n* * *"}, {"input": "5\n abcab", "output": "17"}]
|
Print the number of the subsequences such that all characters are different,
modulo 10^9+7.
* * *
|
s244145686
|
Runtime Error
|
p03095
|
Input is given from Standard Input in the following format:
N
S
|
use std::io::stdin;
use std::collections::HashMap;
fn main() {
let mut st = String::new();
stdin().read_line(&mut st).unwrap();
let n = st.trim().parse::<usize>().unwrap();
let mut st = String::new();
stdin().read_line(&mut st).unwrap();
let s:Vec<char> = st.trim().chars().collect();
let mut map:HashMap<&char, i64> = HashMap::new();
for i in &s {
let count = map.entry(i).or_insert(1);
*count += 1;
};
let mo = 100000007;
let mut result:i64 = 1;
for (_i, j) in map.iter() {
result = (result*j)%mo;
};
println!("{}", result-1);
}
fn bisec(v:&Vec<i64>, num:&i64) -> usize {
let mut l:usize = 0;
let mut r = v.len() as usize;
let mut m = (l+r)/2 as usize;
while l < r {
if num <= &v[m] {
r = m;
} else {
l = m+1;
};
m = (l+r)/2;
};
l
}
fn max (a:&i64, b:&i64) -> i64 {
if a < b {
*b
} else {
*a
}
}
fn min (a:&i64, b:&i64) -> i64 {
if a > b {
*b
} else {
*a
}
}
|
Statement
You are given a string S of length N. Among its subsequences, count the ones
such that all characters are different, modulo 10^9+7. Two subsequences are
considered different if their characters come from different positions in the
string, even if they are the same as strings.
Here, a subsequence of a string is a concatenation of **one or more**
characters from the string without changing the order.
|
[{"input": "4\n abcd", "output": "15\n \n\nSince all characters in S itself are different, all its subsequences satisfy\nthe condition.\n\n* * *"}, {"input": "3\n baa", "output": "5\n \n\nThe answer is five: `b`, two occurrences of `a`, two occurrences of `ba`. Note\nthat we do not count `baa`, since it contains two `a`s.\n\n* * *"}, {"input": "5\n abcab", "output": "17"}]
|
Print the number of the subsequences such that all characters are different,
modulo 10^9+7.
* * *
|
s684562120
|
Runtime Error
|
p03095
|
Input is given from Standard Input in the following format:
N
S
|
N, A, B = list(map(int, input().split(" ")))
C = A ^ B
c = format(A ^ B, "b")
p = list()
p.append(A)
for i in range(len(c)):
if int(c[len(c) - 1 - i]) == 1:
tmp = p[-1] ^ (C & (1 << i))
p.append(tmp)
for i in range(2**N - len(p)):
p.append(p[-2])
if B == p[2**N - 1]:
print("YES")
for i in range(len(p)):
print(p[i], end=" ")
else:
print("NO")
|
Statement
You are given a string S of length N. Among its subsequences, count the ones
such that all characters are different, modulo 10^9+7. Two subsequences are
considered different if their characters come from different positions in the
string, even if they are the same as strings.
Here, a subsequence of a string is a concatenation of **one or more**
characters from the string without changing the order.
|
[{"input": "4\n abcd", "output": "15\n \n\nSince all characters in S itself are different, all its subsequences satisfy\nthe condition.\n\n* * *"}, {"input": "3\n baa", "output": "5\n \n\nThe answer is five: `b`, two occurrences of `a`, two occurrences of `ba`. Note\nthat we do not count `baa`, since it contains two `a`s.\n\n* * *"}, {"input": "5\n abcab", "output": "17"}]
|
Print the number of the subsequences such that all characters are different,
modulo 10^9+7.
* * *
|
s197177586
|
Runtime Error
|
p03095
|
Input is given from Standard Input in the following format:
N
S
|
N = int(input())
S = input()
co = 0
index =0
n =[]
str = ""
for i in range(N):
index=str.find(S[i])
if index == -1 :
str += S[i]
n.append(2)
else :
n[i]++
co = 1
for i in range(len(n)):
co = co * n[i]
co -= 1
print(co % 1000000007)
|
Statement
You are given a string S of length N. Among its subsequences, count the ones
such that all characters are different, modulo 10^9+7. Two subsequences are
considered different if their characters come from different positions in the
string, even if they are the same as strings.
Here, a subsequence of a string is a concatenation of **one or more**
characters from the string without changing the order.
|
[{"input": "4\n abcd", "output": "15\n \n\nSince all characters in S itself are different, all its subsequences satisfy\nthe condition.\n\n* * *"}, {"input": "3\n baa", "output": "5\n \n\nThe answer is five: `b`, two occurrences of `a`, two occurrences of `ba`. Note\nthat we do not count `baa`, since it contains two `a`s.\n\n* * *"}, {"input": "5\n abcab", "output": "17"}]
|
Print the number of the subsequences such that all characters are different,
modulo 10^9+7.
* * *
|
s267189790
|
Runtime Error
|
p03095
|
Input is given from Standard Input in the following format:
N
S
|
import math
import copy
def nCast(number):
if type(number) == str:
return int(number)
for idx in range(0, len(number)):
if type(number[idx]) == str:
number[idx] = int(number[idx])
else:
nCast(number[idx])
return number
def inputArr(w):
l = list()
for idx in range(0, w):
l.append(input())
return l
def inputArr1(w):
l = list()
for idx in range(0, w):
l.append(input().split())
return l
n = input()
s = input()
mod = 1000000007
def help1(a):
all = 0
a1 = 1
a2 = 1
b1 = 1
while a != 0:
a1 = a1 * a
a2 = a2 * b1
b1 += 1
tmp = (int)(a1 / a2)
a = a - 1
all = (all + tmp) % mod
return all
def func():
count = help1(len(s))
dic = {}
for c in s:
if c in dic:
dic[c] = dic[c] + 1
else:
dic[c] = 1
res = len(s)
l = []
for k in dic:
if dic[k] == 1:
l.append(k)
for obj in l:
del dic[obj]
count2 = 1
sum1 = 0
for k in dic:
sum1 += dic[k]
count2 = count2 * (1 + dic[k])
number3 = help1(sum1) - count2 + 1
number4 = help1(len(s) - sum1) + 1
number3 = number3 * number4
return count - number3
print(func())
|
Statement
You are given a string S of length N. Among its subsequences, count the ones
such that all characters are different, modulo 10^9+7. Two subsequences are
considered different if their characters come from different positions in the
string, even if they are the same as strings.
Here, a subsequence of a string is a concatenation of **one or more**
characters from the string without changing the order.
|
[{"input": "4\n abcd", "output": "15\n \n\nSince all characters in S itself are different, all its subsequences satisfy\nthe condition.\n\n* * *"}, {"input": "3\n baa", "output": "5\n \n\nThe answer is five: `b`, two occurrences of `a`, two occurrences of `ba`. Note\nthat we do not count `baa`, since it contains two `a`s.\n\n* * *"}, {"input": "5\n abcab", "output": "17"}]
|
Print the number of the subsequences such that all characters are different,
modulo 10^9+7.
* * *
|
s546795641
|
Runtime Error
|
p03095
|
Input is given from Standard Input in the following format:
N
S
|
n = int(input())
M = pow(10, 9) + 7
import sys
dc = {}
al = [0]
rr = [1]
def search(ss, start, end):
z = al[(start + end) // 2]
nz = al[(start + end) // 2 + 1]
if z <= ss and ss < nz:
return (start + end) // 2
elif ss < z:
return search(ss, start, (start + end) // 2)
else:
return search(ss, (start + end) // 2 + 1, end)
c = 0
cn = 0
for line in sys.stdin:
a = int(line)
if a in dc:
ss = dc[a]
if ss != c - 1:
if ss >= al[cn]:
rr.append((rr[cn] * 2) % M)
else:
i = search(ss, 0, cn)
rr.append((rr[cn] + rr[i]) % M)
al.append(c)
cn += 1
dc[a] = c
c += 1
print(rr[cn] % M)
|
Statement
You are given a string S of length N. Among its subsequences, count the ones
such that all characters are different, modulo 10^9+7. Two subsequences are
considered different if their characters come from different positions in the
string, even if they are the same as strings.
Here, a subsequence of a string is a concatenation of **one or more**
characters from the string without changing the order.
|
[{"input": "4\n abcd", "output": "15\n \n\nSince all characters in S itself are different, all its subsequences satisfy\nthe condition.\n\n* * *"}, {"input": "3\n baa", "output": "5\n \n\nThe answer is five: `b`, two occurrences of `a`, two occurrences of `ba`. Note\nthat we do not count `baa`, since it contains two `a`s.\n\n* * *"}, {"input": "5\n abcab", "output": "17"}]
|
Print the integer representing the town the king will be in if he starts at
Town 1 and uses a teleporter exactly K times from there.
* * *
|
s177332523
|
Wrong Answer
|
p02684
|
Input is given from Standard Input in the following format:
N K
A_1 A_2 \dots A_N
|
def readinput():
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
return n, k, a
def main(n, k, a):
tbl = {}
for i in range(1, n + 1):
tbl[i] = a[i - 1]
machi = 1
for i in range(k):
machi = tbl[machi]
return machi
def main2(n, k, a):
a.insert(0, 0)
# print(a)
nvisited = [0 for i in range(n + 1)]
# print(nvisited)
visited = []
current = 1
visited.append(current)
nvisited[current] += 1
next = a[current]
# print('next='+str(next))
while nvisited[next] == 0:
current = next
visited.append(current)
nvisited[current] += 1
next = a[current]
loophead = next
# print('loophead:'+str(loophead))
# print('visited'+str(visited))
beforeloop = visited.index(loophead)
# print('beforeloop:'+str(beforeloop))
loop = visited[beforeloop:]
# print('loop:'+str(loop))
looplen = len(loop)
if k < beforeloop:
return visited[k + 1]
else:
return loop[(k - beforeloop) % looplen]
def detectloop(a):
# loopを検出して
# loopに入る前に訪れた町リスト:head
# loop内で訪れる町リスト:loop
# を返す
nvisit = [0 for i in range(len(a))]
visited = []
n = a[0]
while nvisit[n - 1] == 0:
nvisit[n - 1] += 1
visited.append(n)
n = a[n - 1]
# print(visited,n)
i = visited.index(n)
# print(i)
if i == 0:
loop = visited[:]
head = []
else:
loop = visited[i:]
head = visited[:i]
return head, loop
def main3(n, k, a):
head, loop = detectloop(a)
print(head, loop, k)
if k <= len(head):
return head[k - 1]
else:
return loop[(k - len(head)) % len(loop) - 1]
if __name__ == "__main__":
n, k, a = readinput()
ans = main3(n, k, a)
print(ans)
|
Statement
The Kingdom of Takahashi has N towns, numbered 1 through N.
There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq
N) sends you to Town A_i.
Takahashi, the king, loves the positive integer K. The selfish king wonders
what town he will be in if he starts at Town 1 and uses a teleporter exactly K
times from there.
Help the king by writing a program that answers this question.
|
[{"input": "4 5\n 3 2 4 1", "output": "4\n \n\nIf we start at Town 1 and use the teleporter 5 times, our travel will be as\nfollows: 1 \\to 3 \\to 4 \\to 1 \\to 3 \\to 4.\n\n* * *"}, {"input": "6 727202214173249351\n 6 5 2 5 3 2", "output": "2"}]
|
Print the integer representing the town the king will be in if he starts at
Town 1 and uses a teleporter exactly K times from there.
* * *
|
s789471778
|
Runtime Error
|
p02684
|
Input is given from Standard Input in the following format:
N K
A_1 A_2 \dots A_N
|
a, b = map(int, input().split())
city = list(map(int, input().split()))
ne = [0] * (3000)
ne[0] = 1
for i in range(2999):
ne[i + 1] = city[ne[i] - 1]
rpp = []
nrp = []
for i in ne[1:1500]:
if i in ne[1501:3000]:
rpp.append(i)
for i in ne[0:1500]:
if i not in ne[1501:3000]:
nrp.append(i)
if len(nrp) >= b - 1:
print(ne[b])
else:
print(rpp[((b - len(nrp) - 1) % len(rpp))])
|
Statement
The Kingdom of Takahashi has N towns, numbered 1 through N.
There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq
N) sends you to Town A_i.
Takahashi, the king, loves the positive integer K. The selfish king wonders
what town he will be in if he starts at Town 1 and uses a teleporter exactly K
times from there.
Help the king by writing a program that answers this question.
|
[{"input": "4 5\n 3 2 4 1", "output": "4\n \n\nIf we start at Town 1 and use the teleporter 5 times, our travel will be as\nfollows: 1 \\to 3 \\to 4 \\to 1 \\to 3 \\to 4.\n\n* * *"}, {"input": "6 727202214173249351\n 6 5 2 5 3 2", "output": "2"}]
|
Print the integer representing the town the king will be in if he starts at
Town 1 and uses a teleporter exactly K times from there.
* * *
|
s277587620
|
Accepted
|
p02684
|
Input is given from Standard Input in the following format:
N K
A_1 A_2 \dots A_N
|
n, k = [int(i) for i in input().split()]
A = [0] + [int(i) for i in input().split()]
# first study the cycle of A
cycle = [A[1]]
i = A[1]
visited = set(cycle)
while A[i] not in visited:
cycle.append(A[i])
visited.add(A[i])
i = A[i]
interest_ind = cycle.index(A[i])
second_part = cycle[interest_ind:]
p = len(cycle) - interest_ind
k -= 1
if k < interest_ind:
print(cycle[k])
else:
k -= interest_ind
k %= p
print(cycle[interest_ind + k])
|
Statement
The Kingdom of Takahashi has N towns, numbered 1 through N.
There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq
N) sends you to Town A_i.
Takahashi, the king, loves the positive integer K. The selfish king wonders
what town he will be in if he starts at Town 1 and uses a teleporter exactly K
times from there.
Help the king by writing a program that answers this question.
|
[{"input": "4 5\n 3 2 4 1", "output": "4\n \n\nIf we start at Town 1 and use the teleporter 5 times, our travel will be as\nfollows: 1 \\to 3 \\to 4 \\to 1 \\to 3 \\to 4.\n\n* * *"}, {"input": "6 727202214173249351\n 6 5 2 5 3 2", "output": "2"}]
|
Print the integer representing the town the king will be in if he starts at
Town 1 and uses a teleporter exactly K times from there.
* * *
|
s801531427
|
Wrong Answer
|
p02684
|
Input is given from Standard Input in the following format:
N K
A_1 A_2 \dots A_N
|
n, k = map(int, input().split())
button = list(map(int, input().split()))
visit = [-1] * n
hisitory = []
push = 0
f = 0
for i in range(k):
visit[push] = i
hisitory.append(push)
push = button[push] - 1
if visit[push] != -1:
f = 1
start = visit[push]
last = push
end = i
break
if f == 0:
print(hisitory[-1] + 1)
else:
loop = end - start + 1
geta = start - 1
kmod = (k - start + 1) % loop
if kmod == 0:
kmod = loop
print(hisitory[geta + kmod] + 1)
|
Statement
The Kingdom of Takahashi has N towns, numbered 1 through N.
There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq
N) sends you to Town A_i.
Takahashi, the king, loves the positive integer K. The selfish king wonders
what town he will be in if he starts at Town 1 and uses a teleporter exactly K
times from there.
Help the king by writing a program that answers this question.
|
[{"input": "4 5\n 3 2 4 1", "output": "4\n \n\nIf we start at Town 1 and use the teleporter 5 times, our travel will be as\nfollows: 1 \\to 3 \\to 4 \\to 1 \\to 3 \\to 4.\n\n* * *"}, {"input": "6 727202214173249351\n 6 5 2 5 3 2", "output": "2"}]
|
Print the integer representing the town the king will be in if he starts at
Town 1 and uses a teleporter exactly K times from there.
* * *
|
s750428879
|
Wrong Answer
|
p02684
|
Input is given from Standard Input in the following format:
N K
A_1 A_2 \dots A_N
|
n, k = [int(x) for x in input().split()]
a_list = [0] + [int(x) for x in input().split()]
ci = 1
temp_dict = {1: 0}
temp_list = [1]
for i in range(1, k + 1):
temp = a_list[ci]
if temp in temp_dict:
print(temp_list[(k - i) % (i - temp_dict[temp]) + temp_dict[temp]])
break
temp_dict[temp] = i
temp_list.append(temp)
ci = temp
|
Statement
The Kingdom of Takahashi has N towns, numbered 1 through N.
There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq
N) sends you to Town A_i.
Takahashi, the king, loves the positive integer K. The selfish king wonders
what town he will be in if he starts at Town 1 and uses a teleporter exactly K
times from there.
Help the king by writing a program that answers this question.
|
[{"input": "4 5\n 3 2 4 1", "output": "4\n \n\nIf we start at Town 1 and use the teleporter 5 times, our travel will be as\nfollows: 1 \\to 3 \\to 4 \\to 1 \\to 3 \\to 4.\n\n* * *"}, {"input": "6 727202214173249351\n 6 5 2 5 3 2", "output": "2"}]
|
Print the integer representing the town the king will be in if he starts at
Town 1 and uses a teleporter exactly K times from there.
* * *
|
s519534539
|
Accepted
|
p02684
|
Input is given from Standard Input in the following format:
N K
A_1 A_2 \dots A_N
|
class solver:
def __init__(self):
self.n, self.k = map(int, input().split())
self.initVariables()
self.a = [int(i) - 1 for i in input().split()]
def initVariables(self):
self.vis = [False] * self.n
def solve(self):
cur, tot = 0, 0
travelled = list()
while tot < self.k and not self.vis[cur]:
self.vis[cur] = True
travelled.append(cur)
cur = self.a[cur]
tot += 1
if tot == self.k:
return cur + 1
cycle = list()
for i in travelled:
if i == cur or len(cycle) > 0:
cycle.append(i)
return cycle[(self.k - tot) % len(cycle)] + 1
print(solver().solve())
|
Statement
The Kingdom of Takahashi has N towns, numbered 1 through N.
There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq
N) sends you to Town A_i.
Takahashi, the king, loves the positive integer K. The selfish king wonders
what town he will be in if he starts at Town 1 and uses a teleporter exactly K
times from there.
Help the king by writing a program that answers this question.
|
[{"input": "4 5\n 3 2 4 1", "output": "4\n \n\nIf we start at Town 1 and use the teleporter 5 times, our travel will be as\nfollows: 1 \\to 3 \\to 4 \\to 1 \\to 3 \\to 4.\n\n* * *"}, {"input": "6 727202214173249351\n 6 5 2 5 3 2", "output": "2"}]
|
Print the integer representing the town the king will be in if he starts at
Town 1 and uses a teleporter exactly K times from there.
* * *
|
s471854787
|
Wrong Answer
|
p02684
|
Input is given from Standard Input in the following format:
N K
A_1 A_2 \dots A_N
|
N, K = map(int, input().split())
A = list(map(int, input().split()))
mati_check_set = {0}
mati_order = [0]
count = 0
mati = 0
check1, check2 = True, True
while check1 and check2:
next_town = A[mati] - 1
count += 1
if next_town not in mati_check_set:
mati_check_set.add(next_town)
mati_order.append(next_town)
mati = next_town
else:
loop = (next_town, mati)
mati_order.append(next_town)
check1 = False
break
if count - 1 == K:
check2 = False
ans = next_town + 1
print(ans)
if check1 == False:
count1 = 0
check3 = True
town = 0
if loop[0] != 0:
while check3:
next_town = A[town] - 1
count1 += 1
if next_town == loop[0]:
check3 = False
town = next_town
a = count1
b = len(mati_order) - 2
c = b - a + 1
amari = (K - a + 1) % (c + 1)
index = mati_order.index(loop[0]) + amari
print(mati_order[index])
else:
c = len(mati_order) - 1
index = K % c
print(mati_order[index] + 1)
|
Statement
The Kingdom of Takahashi has N towns, numbered 1 through N.
There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq
N) sends you to Town A_i.
Takahashi, the king, loves the positive integer K. The selfish king wonders
what town he will be in if he starts at Town 1 and uses a teleporter exactly K
times from there.
Help the king by writing a program that answers this question.
|
[{"input": "4 5\n 3 2 4 1", "output": "4\n \n\nIf we start at Town 1 and use the teleporter 5 times, our travel will be as\nfollows: 1 \\to 3 \\to 4 \\to 1 \\to 3 \\to 4.\n\n* * *"}, {"input": "6 727202214173249351\n 6 5 2 5 3 2", "output": "2"}]
|
Print the integer representing the town the king will be in if he starts at
Town 1 and uses a teleporter exactly K times from there.
* * *
|
s609917813
|
Wrong Answer
|
p02684
|
Input is given from Standard Input in the following format:
N K
A_1 A_2 \dots A_N
|
N, K = map(int, input().split())
aList = list(map(int, input().split()))
usedList = [0 for n in range(N)]
count = 1
for n in range(K + 1):
if n == 0:
index = aList[0] - 1
usedList[0] = 1
elif usedList[index] == 0:
index = aList[index] - 1
usedList[index] = 1
else:
tmp = aList[index]
while 1:
index = aList[index] - 1
count += 1
if tmp == aList[index]:
break
break
K %= count
for n in range(K + 1):
if n == 0:
index = aList[0] - 1
elif usedList[index] == 0:
index = aList[index] - 1
print(index + 1)
|
Statement
The Kingdom of Takahashi has N towns, numbered 1 through N.
There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq
N) sends you to Town A_i.
Takahashi, the king, loves the positive integer K. The selfish king wonders
what town he will be in if he starts at Town 1 and uses a teleporter exactly K
times from there.
Help the king by writing a program that answers this question.
|
[{"input": "4 5\n 3 2 4 1", "output": "4\n \n\nIf we start at Town 1 and use the teleporter 5 times, our travel will be as\nfollows: 1 \\to 3 \\to 4 \\to 1 \\to 3 \\to 4.\n\n* * *"}, {"input": "6 727202214173249351\n 6 5 2 5 3 2", "output": "2"}]
|
Print the integer representing the town the king will be in if he starts at
Town 1 and uses a teleporter exactly K times from there.
* * *
|
s478518266
|
Runtime Error
|
p02684
|
Input is given from Standard Input in the following format:
N K
A_1 A_2 \dots A_N
|
(N, K) = list(map(int, input().split()))
A = list(map(int, input().split()))
B = [A[0] - 1]
c = 0
for i in range(1, K):
B.append(A[B[i - 1]] - 1)
if B.count(B[i]) == 2:
c = B.index(B[i])
d = i - c
break
e = (K - c) % d
print(A[c + e])
|
Statement
The Kingdom of Takahashi has N towns, numbered 1 through N.
There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq
N) sends you to Town A_i.
Takahashi, the king, loves the positive integer K. The selfish king wonders
what town he will be in if he starts at Town 1 and uses a teleporter exactly K
times from there.
Help the king by writing a program that answers this question.
|
[{"input": "4 5\n 3 2 4 1", "output": "4\n \n\nIf we start at Town 1 and use the teleporter 5 times, our travel will be as\nfollows: 1 \\to 3 \\to 4 \\to 1 \\to 3 \\to 4.\n\n* * *"}, {"input": "6 727202214173249351\n 6 5 2 5 3 2", "output": "2"}]
|
Print the integer representing the town the king will be in if he starts at
Town 1 and uses a teleporter exactly K times from there.
* * *
|
s798050191
|
Runtime Error
|
p02684
|
Input is given from Standard Input in the following format:
N K
A_1 A_2 \dots A_N
|
#####################################################################################################
##### 深さ優先探索 幅優先探索 (グラフ)
#####################################################################################################
"""
キューに頂点を入れる回数は各々高々1回のみ。
各辺を使う回数は高々一回のみ(辺を戻るような探索は枝切りされている)
結果として、計算量はO(N + M)
"""
import sys
sys.setrecursionlimit(10**8)
input = sys.stdin.readline
from copy import deepcopy
class Graph:
def __init__(self, n, dictated=False, decrement=True, edge=[]):
self.n = n
self.dictated = dictated
self.decrement = decrement
self.edge = [set() for _ in range(self.n)]
self.parent = [-1] * self.n
self.info = [-1] * self.n
for x, y in edge:
self.add_edge(x, y)
def add_edge(self, x, y):
if self.decrement:
x -= 1
y -= 1
self.edge[x].add(y)
if self.dictated == False:
self.edge[y].add(x)
def add_adjacent_list(self, i, adjacent_list):
if self.decrement:
self.edge[i] = set(map(lambda x: x - 1, adjacent_list))
else:
self.edge[i] = set(adjacent_list)
def cycle_detector(self, start, time=0, save=False):
"""
:param p: スタート地点
:param save: True = 前回の探索結果を保持する
:return: 各点までの距離と何番目に発見したかを返す
"""
edge2 = deepcopy(self.edge)
if self.decrement:
start -= 1
if not save:
self.parent = [-1] * self.n
p, t = start, time
self.parent[p] = -2
cycle_end = False
cycle_time = 0
cycle = []
while True:
if edge2[p]:
q = edge2[p].pop()
if q == self.parent[p]:
"""逆流した時の処理"""
"""""" """""" """""" ""
continue
if self.parent[q] != -1:
"""サイクルで同一点を訪れた時の処理"""
if not cycle:
cycle.append(q + self.decrement)
cycle.append(p + self.decrement)
cycle_time = t
"""""" """""" """""" ""
continue
self.parent[q] = p
p, t = q, t + 1
else:
"""探索完了時の処理"""
"""""" """""" """""" ""
if p == start and t == time:
break
p, t = self.parent[p], t - 1
""" 二度目に訪問時の処理 """
if cycle and t == cycle_time - 1 and not cycle_end:
if cycle[0] == p + self.decrement:
cycle_end = True
continue
cycle.append(p + self.decrement)
cycle_time = t
"""""" """""" """""" ""
cycle = list(reversed(cycle))
return [cycle[-1]] + cycle[:-1]
def tree_counter(self, detail=False):
"""
:param detail: True = サイクルのリストを返す
:return: 木(閉路を含まない)の個数を返す
"""
self.parent = [-1] * self.n
connection_number = 0
cycle_list = []
for p in range(self.n):
if self.parent[p] == -1:
connection_number += 1
cycle = self.cycle_detector(p + self.decrement, save=True)
if cycle:
cycle_list.append(cycle)
if not detail:
return connection_number - len(cycle_list)
else:
return cycle_list
def draw(self):
"""
:return: グラフを可視化
"""
import matplotlib.pyplot as plt
import networkx as nx
if self.dictated:
G = nx.DiGraph()
else:
G = nx.Graph()
for x in range(self.n):
for y in self.edge[x]:
G.add_edge(x + self.decrement, y + self.decrement)
nx.draw_networkx(G)
plt.show()
##################################################################
N, K = map(int, input().split())
A = list(map(int, input().split()))
M = N
graph = Graph(N, dictated=True)
for i in range(1, M + 1):
x = i
y = A[i - 1]
graph.add_edge(x, y)
p = 0
cnt = 0
if K <= N:
while cnt + 1 <= K:
p = A[p] - 1
cnt += 1
res = p + 1
else:
cycle = list(graph.cycle_detector(1))
len_cycle = len(cycle)
p = 0
cnt = 0
res = 0
while p != cycle[0] - 1:
p = A[p] - 1
cnt += 1
k = (K - cnt) % len_cycle
res = cycle[k]
print(res)
|
Statement
The Kingdom of Takahashi has N towns, numbered 1 through N.
There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq
N) sends you to Town A_i.
Takahashi, the king, loves the positive integer K. The selfish king wonders
what town he will be in if he starts at Town 1 and uses a teleporter exactly K
times from there.
Help the king by writing a program that answers this question.
|
[{"input": "4 5\n 3 2 4 1", "output": "4\n \n\nIf we start at Town 1 and use the teleporter 5 times, our travel will be as\nfollows: 1 \\to 3 \\to 4 \\to 1 \\to 3 \\to 4.\n\n* * *"}, {"input": "6 727202214173249351\n 6 5 2 5 3 2", "output": "2"}]
|
Print the integer representing the town the king will be in if he starts at
Town 1 and uses a teleporter exactly K times from there.
* * *
|
s617158903
|
Runtime Error
|
p02684
|
Input is given from Standard Input in the following format:
N K
A_1 A_2 \dots A_N
|
N, K = map(int, input().split())
A = list(map(int, input().split()))
way = A[0]
List = [0 for n in range(N)]
List[way - 1] += 1
count = 0
string = f"{way}"
# print(f"string:{string}")
# print(f"way:{way}")
for i in range(10**7):
way = A[way - 1]
List[way - 1] += 1
count += 1
# print(f"way:{way}")
# print(f"count:{count}")
# print(List)
if max(List) == 3:
break
else:
string += f"{way}"
# print(f"string:{string}")
# print()
# print(List)
# print()
new_list = [i for i in List if i == 1]
length = len(new_list)
n_list = [j for j in List if j >= 2]
# print(new_list)
# print(n_list)
amari = (K - length) % len(n_list)
print(int(n_list[amari + 1]))
|
Statement
The Kingdom of Takahashi has N towns, numbered 1 through N.
There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq
N) sends you to Town A_i.
Takahashi, the king, loves the positive integer K. The selfish king wonders
what town he will be in if he starts at Town 1 and uses a teleporter exactly K
times from there.
Help the king by writing a program that answers this question.
|
[{"input": "4 5\n 3 2 4 1", "output": "4\n \n\nIf we start at Town 1 and use the teleporter 5 times, our travel will be as\nfollows: 1 \\to 3 \\to 4 \\to 1 \\to 3 \\to 4.\n\n* * *"}, {"input": "6 727202214173249351\n 6 5 2 5 3 2", "output": "2"}]
|
Print the integer representing the town the king will be in if he starts at
Town 1 and uses a teleporter exactly K times from there.
* * *
|
s846604913
|
Runtime Error
|
p02684
|
Input is given from Standard Input in the following format:
N K
A_1 A_2 \dots A_N
|
N, K = map(int, input().split())
a = list(map(int, input().split()))
list_a = []
list_b = []
list_a.append(1)
count_a = 1
count_b = 0
for i in range(1, K + 1):
if i == 1:
k = i
if a[k - 1] in list_b:
break
elif a[k - 1] in list_a:
list_b.append(a[k - 1])
count_b += 1
if a[k - 1] == 1:
handan = True
if a[k - 1] not in list_a:
list_a.append(a[k - 1])
count_a += 1
k = a[k - 1]
# print(list_a,list_b,count_a,count_b)
if count_b != 0:
num_k = K - (count_a - count_b)
num_k = num_k % count_b
if handan == True and list_b[0] != 1:
# list_b.remove(1)
list_b.insert(0, 1)
print(list_b[num_k])
elif count_b == 0:
print(list_a[count_a - 1])
|
Statement
The Kingdom of Takahashi has N towns, numbered 1 through N.
There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq
N) sends you to Town A_i.
Takahashi, the king, loves the positive integer K. The selfish king wonders
what town he will be in if he starts at Town 1 and uses a teleporter exactly K
times from there.
Help the king by writing a program that answers this question.
|
[{"input": "4 5\n 3 2 4 1", "output": "4\n \n\nIf we start at Town 1 and use the teleporter 5 times, our travel will be as\nfollows: 1 \\to 3 \\to 4 \\to 1 \\to 3 \\to 4.\n\n* * *"}, {"input": "6 727202214173249351\n 6 5 2 5 3 2", "output": "2"}]
|
Print the integer representing the town the king will be in if he starts at
Town 1 and uses a teleporter exactly K times from there.
* * *
|
s751320771
|
Runtime Error
|
p02684
|
Input is given from Standard Input in the following format:
N K
A_1 A_2 \dots A_N
|
N, K = map(int, input().split())
li = list(map(int, input().split()))
townlist = []
rooptown = 0
nowtown = 1
for i in range(0, 200000):
nowtown.append(nowtown)
nowtown = li[nowtown]
for j in list:
if nowtown == j and rooptown == 0:
rooptown == i
K = K % rooptown + rooptown
for i in range(0, K):
nowtown.append(nowtown)
nowtown = li[nowtown]
print(nowtown)
|
Statement
The Kingdom of Takahashi has N towns, numbered 1 through N.
There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq
N) sends you to Town A_i.
Takahashi, the king, loves the positive integer K. The selfish king wonders
what town he will be in if he starts at Town 1 and uses a teleporter exactly K
times from there.
Help the king by writing a program that answers this question.
|
[{"input": "4 5\n 3 2 4 1", "output": "4\n \n\nIf we start at Town 1 and use the teleporter 5 times, our travel will be as\nfollows: 1 \\to 3 \\to 4 \\to 1 \\to 3 \\to 4.\n\n* * *"}, {"input": "6 727202214173249351\n 6 5 2 5 3 2", "output": "2"}]
|
Print the integer representing the town the king will be in if he starts at
Town 1 and uses a teleporter exactly K times from there.
* * *
|
s673959685
|
Accepted
|
p02684
|
Input is given from Standard Input in the following format:
N K
A_1 A_2 \dots A_N
|
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
used = set()
history = []
cur = 0
used.add(0)
while True:
history.append(cur)
next_cur = A[cur] - 1
if next_cur in used:
loop_start = history.index(next_cur)
break
used.add(next_cur)
cur = next_cur
B = history[loop_start:]
if K <= loop_start:
result = history[K]
else:
result = B[(K - loop_start) % len(B)]
print(result + 1)
|
Statement
The Kingdom of Takahashi has N towns, numbered 1 through N.
There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq
N) sends you to Town A_i.
Takahashi, the king, loves the positive integer K. The selfish king wonders
what town he will be in if he starts at Town 1 and uses a teleporter exactly K
times from there.
Help the king by writing a program that answers this question.
|
[{"input": "4 5\n 3 2 4 1", "output": "4\n \n\nIf we start at Town 1 and use the teleporter 5 times, our travel will be as\nfollows: 1 \\to 3 \\to 4 \\to 1 \\to 3 \\to 4.\n\n* * *"}, {"input": "6 727202214173249351\n 6 5 2 5 3 2", "output": "2"}]
|
Print the integer representing the town the king will be in if he starts at
Town 1 and uses a teleporter exactly K times from there.
* * *
|
s971375920
|
Wrong Answer
|
p02684
|
Input is given from Standard Input in the following format:
N K
A_1 A_2 \dots A_N
|
n, k = map(int, input().split()) # int
a = input().replace(" ", "") # str
chokudai = "1" # str
fp = "1" # str
telenum = 0 # int
while True:
chokudai = a[int(chokudai) - 1]
telenum += 1
rooph = fp.find(chokudai) # int
if rooph != -1:
rooplen = len(fp) - rooph
break
else:
fp = fp + chokudai
if rooplen < k:
print(fp[rooph + (k - rooph) % rooplen])
else:
print(fp[k])
|
Statement
The Kingdom of Takahashi has N towns, numbered 1 through N.
There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq
N) sends you to Town A_i.
Takahashi, the king, loves the positive integer K. The selfish king wonders
what town he will be in if he starts at Town 1 and uses a teleporter exactly K
times from there.
Help the king by writing a program that answers this question.
|
[{"input": "4 5\n 3 2 4 1", "output": "4\n \n\nIf we start at Town 1 and use the teleporter 5 times, our travel will be as\nfollows: 1 \\to 3 \\to 4 \\to 1 \\to 3 \\to 4.\n\n* * *"}, {"input": "6 727202214173249351\n 6 5 2 5 3 2", "output": "2"}]
|
Print the integer representing the town the king will be in if he starts at
Town 1 and uses a teleporter exactly K times from there.
* * *
|
s154450615
|
Accepted
|
p02684
|
Input is given from Standard Input in the following format:
N K
A_1 A_2 \dots A_N
|
import glob
import os
bn = os.path.basename(__file__).split(".")[0]
dn = os.path.dirname(__file__).split("/")
# 問題ごとのディレクトリのトップからの相対パス
REL_PATH = dn[len(dn) - 2] + "\\" + dn[len(dn) - 1] + "\\" + bn
# テスト用ファイル置き場のトップ
TOP_PATH = "C:\\AtCoder"
class Common:
problem = []
index = 0
def __init__(self, rel_path):
self.rel_path = rel_path
def initialize(self, path):
file = open(path)
self.problem = file.readlines()
self.index = 0
return
def input_data(self):
try:
IS_TEST
self.index += 1
return self.problem[self.index - 1]
except NameError:
return input()
def resolve(self):
pass
def exec_resolve(self):
try:
IS_TEST
for path in glob.glob(TOP_PATH + "\\" + self.rel_path + "/*.txt"):
print("Test: " + path)
self.initialize(path)
self.resolve()
print("\n\n")
except NameError:
self.resolve()
class Solver(Common):
alph = []
def rec(self, result, now, max, N):
if now == N:
res = ""
for i in result:
res += self.alph[i]
print(res)
return
if now == 0:
result[0] = 0
self.rec(result, now + 1, 0, N)
return
for i in range(0, max + 2):
if i == N:
return
result[now] = i
if i > max:
self.rec(result, now + 1, i, N)
else:
self.rec(result, now + 1, max, N)
def resolve(self):
N, K = map(int, self.input_data().split())
A = list(map(int, self.input_data().split()))
A.insert(0, 0)
town_visit_time = [-1] * (N + 1)
num_loop = 0
loop_start_count = 0
loop_start_town = 0
next_town = 1
for i in range(0, N + 1):
if town_visit_time[next_town] != -1:
num_loop = i - town_visit_time[next_town]
loop_start_count = town_visit_time[next_town]
loop_start_town = next_town
break
town_visit_time[next_town] = i
next_town = A[next_town]
if i + 1 == K:
print(str(next_town))
exit(0)
remain = (K - loop_start_count) % num_loop
result = loop_start_town
for i in range(remain):
result = A[result]
print(str(result))
solver = Solver(REL_PATH)
solver.exec_resolve()
|
Statement
The Kingdom of Takahashi has N towns, numbered 1 through N.
There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq
N) sends you to Town A_i.
Takahashi, the king, loves the positive integer K. The selfish king wonders
what town he will be in if he starts at Town 1 and uses a teleporter exactly K
times from there.
Help the king by writing a program that answers this question.
|
[{"input": "4 5\n 3 2 4 1", "output": "4\n \n\nIf we start at Town 1 and use the teleporter 5 times, our travel will be as\nfollows: 1 \\to 3 \\to 4 \\to 1 \\to 3 \\to 4.\n\n* * *"}, {"input": "6 727202214173249351\n 6 5 2 5 3 2", "output": "2"}]
|
Print `Yes` if it is possible to make N arrays exactly the same after
performing the Q operations. Otherwise, print `No`.
* * *
|
s689787891
|
Runtime Error
|
p03996
|
The input is given from Standard Input in the following format:
N M
Q
a_1 a_2 ... a_Q
|
from collections import defaultdict
def ReadInput():
return [int(a) for a in input().split(' ')]
(N, M) = ReadInput()
Q = int(input())
Array = ReadInput()
def ifEqual(x):
temp = None
for i in x:
if (temp == None):
temp = x[i]
continue
elif (x[i] != temp):
print('ifEqual is 0')
return 0
return temp
def check(Array, N, M, *args):
Count = defaultdict(int)
Array.reverse()
if ("reverse") not in args:
for i in Array:
if (i == 1 or Count[i] < Count[i-1]):
Count[i] += 1
else:
return 0
Count.pop(N)
if(ifEqual(Count)):
return 1
else:
return 0
else:
for i in Array:
if (i == N or Count[i] < Count[i+1]):
Count[i] += 1
else:
return 0
Count.pop(1)
if(ifEqual(Count) >= M):
return 1
else
return 0
if (check(Array, N, M) or check(Array, N, M, "reverse")):
print("Yes")
else:
print("No")
|
Statement
There are N arrays. The length of each array is M and initially each array
contains integers (1,2,...,M) in this order.
Mr. Takahashi has decided to perform Q operations on those N arrays. For the
i-th (1≤i≤Q) time, he performs the following operation.
* Choose an arbitrary array from the N arrays and move the integer a_i (1≤a_i≤M) to the front of that array. For example, after performing the operation on a_i=2 and the array (5,4,3,2,1), this array becomes (2,5,4,3,1).
Mr. Takahashi wants to make N arrays exactly the same after performing the Q
operations. Determine if it is possible or not.
|
[{"input": "2 2\n 3\n 2 1 2", "output": "Yes\n \n\nYou can perform the operations as follows.\n\n\n\n* * *"}, {"input": "3 2\n 3\n 2 1 2", "output": "No\n \n\n* * *"}, {"input": "2 3\n 3\n 3 2 1", "output": "Yes\n \n\nYou can perform the operations as follows.\n\n\n\n* * *"}, {"input": "3 3\n 6\n 1 2 2 3 3 3", "output": "No"}]
|
Print `Yes` if it is possible to make N arrays exactly the same after
performing the Q operations. Otherwise, print `No`.
* * *
|
s056177830
|
Wrong Answer
|
p03996
|
The input is given from Standard Input in the following format:
N M
Q
a_1 a_2 ... a_Q
|
input()
input()
input()
print("Yes")
|
Statement
There are N arrays. The length of each array is M and initially each array
contains integers (1,2,...,M) in this order.
Mr. Takahashi has decided to perform Q operations on those N arrays. For the
i-th (1≤i≤Q) time, he performs the following operation.
* Choose an arbitrary array from the N arrays and move the integer a_i (1≤a_i≤M) to the front of that array. For example, after performing the operation on a_i=2 and the array (5,4,3,2,1), this array becomes (2,5,4,3,1).
Mr. Takahashi wants to make N arrays exactly the same after performing the Q
operations. Determine if it is possible or not.
|
[{"input": "2 2\n 3\n 2 1 2", "output": "Yes\n \n\nYou can perform the operations as follows.\n\n\n\n* * *"}, {"input": "3 2\n 3\n 2 1 2", "output": "No\n \n\n* * *"}, {"input": "2 3\n 3\n 3 2 1", "output": "Yes\n \n\nYou can perform the operations as follows.\n\n\n\n* * *"}, {"input": "3 3\n 6\n 1 2 2 3 3 3", "output": "No"}]
|
Print the number of children standing on each square after the children
performed the moves, in order from left to right.
* * *
|
s974892349
|
Runtime Error
|
p02954
|
Input is given from Standard Input in the following format:
S
|
l, r = list(map(int, input().split()))
s = []
if r - l > 2050:
print(0)
else:
for i in range(l, r + 1):
s.append(i % 2019)
s.sort()
print(s[0] * s[1])
|
Statement
Given is a string S consisting of `L` and `R`.
Let N be the length of S. There are N squares arranged from left to right, and
the i-th character of S from the left is written on the i-th square from the
left.
The character written on the leftmost square is always `R`, and the character
written on the rightmost square is always `L`.
Initially, one child is standing on each square.
Each child will perform the move below 10^{100} times:
* Move one square in the direction specified by the character written in the square on which the child is standing. `L` denotes left, and `R` denotes right.
Find the number of children standing on each square after the children
performed the moves.
|
[{"input": "RRLRL", "output": "0 1 2 1 1\n \n\n * After each child performed one move, the number of children standing on each square is 0, 2, 1, 1, 1 from left to right.\n * After each child performed two moves, the number of children standing on each square is 0, 1, 2, 1, 1 from left to right.\n * After each child performed 10^{100} moves, the number of children standing on each square is 0, 1, 2, 1, 1 from left to right.\n\n* * *"}, {"input": "RRLLLLRLRRLL", "output": "0 3 3 0 0 0 1 1 0 2 2 0\n \n\n* * *"}, {"input": "RRRLLRLLRRRLLLLL", "output": "0 0 3 2 0 2 1 0 0 0 4 4 0 0 0 0"}]
|
Print the number of children standing on each square after the children
performed the moves, in order from left to right.
* * *
|
s759821582
|
Accepted
|
p02954
|
Input is given from Standard Input in the following format:
S
|
S = input()
length = len(S)
ans = [0] * length
pre_s = ""
start_i = 0
for i, s in enumerate(S):
if pre_s == "R" and s == "L":
r_i = i - 1
l_i = i
elif pre_s == "L" and s == "R":
end_i = i - 1
n = end_i - start_i + 1
ans[r_i] = 1 + (end_i - l_i + 1) // 2 + (r_i - start_i) // 2
ans[l_i] = n - ans[r_i]
start_i = i
if i == length - 1:
end_i = i
n = end_i - start_i + 1
ans[r_i] = 1 + (end_i - l_i + 1) // 2 + (r_i - start_i) // 2
ans[l_i] = n - ans[r_i]
pre_s = s
print(" ".join([str(i) for i in ans]))
|
Statement
Given is a string S consisting of `L` and `R`.
Let N be the length of S. There are N squares arranged from left to right, and
the i-th character of S from the left is written on the i-th square from the
left.
The character written on the leftmost square is always `R`, and the character
written on the rightmost square is always `L`.
Initially, one child is standing on each square.
Each child will perform the move below 10^{100} times:
* Move one square in the direction specified by the character written in the square on which the child is standing. `L` denotes left, and `R` denotes right.
Find the number of children standing on each square after the children
performed the moves.
|
[{"input": "RRLRL", "output": "0 1 2 1 1\n \n\n * After each child performed one move, the number of children standing on each square is 0, 2, 1, 1, 1 from left to right.\n * After each child performed two moves, the number of children standing on each square is 0, 1, 2, 1, 1 from left to right.\n * After each child performed 10^{100} moves, the number of children standing on each square is 0, 1, 2, 1, 1 from left to right.\n\n* * *"}, {"input": "RRLLLLRLRRLL", "output": "0 3 3 0 0 0 1 1 0 2 2 0\n \n\n* * *"}, {"input": "RRRLLRLLRRRLLLLL", "output": "0 0 3 2 0 2 1 0 0 0 4 4 0 0 0 0"}]
|
Print the number of children standing on each square after the children
performed the moves, in order from left to right.
* * *
|
s327301019
|
Accepted
|
p02954
|
Input is given from Standard Input in the following format:
S
|
s = input()
n = len(s)
kodomo = [0 for i in range(n)]
cr1 = 0
cr2 = 0
rflag = False
rlflag = False
for i in range(n):
if s[i] == "R":
rlflag = False
if rflag:
cr2 += 1
rflag = False
else:
cr1 += 1
rflag = True
else:
if rlflag:
continue
else:
rlflag = True
if rflag:
kodomo[i - 1] += cr1
kodomo[i] += cr2
cr1 = 0
cr2 = 0
else:
kodomo[i - 1] += cr2
kodomo[i] += cr1
cr1 = 0
cr2 = 0
rflag = False
cl1 = 0
cl2 = 0
lflag = False
lrflag = False
for i in range(n):
if s[n - 1 - i] == "L":
lrflag = False
if lflag:
cl2 += 1
lflag = False
else:
cl1 += 1
lflag = True
else:
if lrflag:
continue
else:
lrflag = True
if lflag:
kodomo[n - i] += cl1
kodomo[n - i - 1] += cl2
cl1 = 0
cl2 = 0
else:
kodomo[n - i] += cl2
kodomo[n - i - 1] += cl1
cl1 = 0
cl2 = 0
lflag = False
print(" ".join(map(str, kodomo)))
|
Statement
Given is a string S consisting of `L` and `R`.
Let N be the length of S. There are N squares arranged from left to right, and
the i-th character of S from the left is written on the i-th square from the
left.
The character written on the leftmost square is always `R`, and the character
written on the rightmost square is always `L`.
Initially, one child is standing on each square.
Each child will perform the move below 10^{100} times:
* Move one square in the direction specified by the character written in the square on which the child is standing. `L` denotes left, and `R` denotes right.
Find the number of children standing on each square after the children
performed the moves.
|
[{"input": "RRLRL", "output": "0 1 2 1 1\n \n\n * After each child performed one move, the number of children standing on each square is 0, 2, 1, 1, 1 from left to right.\n * After each child performed two moves, the number of children standing on each square is 0, 1, 2, 1, 1 from left to right.\n * After each child performed 10^{100} moves, the number of children standing on each square is 0, 1, 2, 1, 1 from left to right.\n\n* * *"}, {"input": "RRLLLLRLRRLL", "output": "0 3 3 0 0 0 1 1 0 2 2 0\n \n\n* * *"}, {"input": "RRRLLRLLRRRLLLLL", "output": "0 0 3 2 0 2 1 0 0 0 4 4 0 0 0 0"}]
|
Print the number of children standing on each square after the children
performed the moves, in order from left to right.
* * *
|
s028519646
|
Runtime Error
|
p02954
|
Input is given from Standard Input in the following format:
S
|
s = input().split()
if len(s) == 2:
print(1, 1)
exit()
chk = [0] * len(s)
cntR = 1
r = 0
cntL = 0
for i in range(len(s) - 1):
if s[i] == "R" and s[i + 1] == "L":
r = i
chk[r] += (cntR + 1) // 2
chk[r + 1] += (cntR) // 2
cntL = 1
if s[i] == "R" and s[i + 1] == "R":
cntR += 1
if s[i] == "L" and s[i + 1] == "L":
cntL += 1
if s[i] == "L" and s[i + 1] == "R":
chk[r] += (cntL) // 2
chk[r + 1] += (cntL + 1) // 2
cntL = 0
cntR = 1
chk[r] += (cntL) // 2
chk[r + 1] += (cntL + 1) // 2
chk = list(map(str, chk))
print(" ".join(chk))
|
Statement
Given is a string S consisting of `L` and `R`.
Let N be the length of S. There are N squares arranged from left to right, and
the i-th character of S from the left is written on the i-th square from the
left.
The character written on the leftmost square is always `R`, and the character
written on the rightmost square is always `L`.
Initially, one child is standing on each square.
Each child will perform the move below 10^{100} times:
* Move one square in the direction specified by the character written in the square on which the child is standing. `L` denotes left, and `R` denotes right.
Find the number of children standing on each square after the children
performed the moves.
|
[{"input": "RRLRL", "output": "0 1 2 1 1\n \n\n * After each child performed one move, the number of children standing on each square is 0, 2, 1, 1, 1 from left to right.\n * After each child performed two moves, the number of children standing on each square is 0, 1, 2, 1, 1 from left to right.\n * After each child performed 10^{100} moves, the number of children standing on each square is 0, 1, 2, 1, 1 from left to right.\n\n* * *"}, {"input": "RRLLLLRLRRLL", "output": "0 3 3 0 0 0 1 1 0 2 2 0\n \n\n* * *"}, {"input": "RRRLLRLLRRRLLLLL", "output": "0 0 3 2 0 2 1 0 0 0 4 4 0 0 0 0"}]
|
Print the number of children standing on each square after the children
performed the moves, in order from left to right.
* * *
|
s690916355
|
Wrong Answer
|
p02954
|
Input is given from Standard Input in the following format:
S
|
# 自信なし
S = input().replace("LR", "L R")
l = list(S.split())
ans = []
for s in l:
t = len(s)
a = str((t + 1) // 2)
b = str(t // 2)
k = list(s.replace("RL", "R L").split())
if len(k[0]) & 1:
ans.append("0" * (len(k[0]) - 1) + a + b + (len(k[1]) - 1) * "0")
else:
ans.append("0" * (len(k[0]) - 1) + b + a + (len(k[1]) - 1) * "0")
print(*list("".join(ans)))
|
Statement
Given is a string S consisting of `L` and `R`.
Let N be the length of S. There are N squares arranged from left to right, and
the i-th character of S from the left is written on the i-th square from the
left.
The character written on the leftmost square is always `R`, and the character
written on the rightmost square is always `L`.
Initially, one child is standing on each square.
Each child will perform the move below 10^{100} times:
* Move one square in the direction specified by the character written in the square on which the child is standing. `L` denotes left, and `R` denotes right.
Find the number of children standing on each square after the children
performed the moves.
|
[{"input": "RRLRL", "output": "0 1 2 1 1\n \n\n * After each child performed one move, the number of children standing on each square is 0, 2, 1, 1, 1 from left to right.\n * After each child performed two moves, the number of children standing on each square is 0, 1, 2, 1, 1 from left to right.\n * After each child performed 10^{100} moves, the number of children standing on each square is 0, 1, 2, 1, 1 from left to right.\n\n* * *"}, {"input": "RRLLLLRLRRLL", "output": "0 3 3 0 0 0 1 1 0 2 2 0\n \n\n* * *"}, {"input": "RRRLLRLLRRRLLLLL", "output": "0 0 3 2 0 2 1 0 0 0 4 4 0 0 0 0"}]
|
Print the number of children standing on each square after the children
performed the moves, in order from left to right.
* * *
|
s076031332
|
Wrong Answer
|
p02954
|
Input is given from Standard Input in the following format:
S
|
S = input() + "O"
N = len(S)
n = [0] * (N - 1)
t = []
i = 0
j = 0
while S[i] != "O":
count = 0
if S[i] == "R":
while S[i] == "R":
count += 1
i += 1
elif S[i] == "L":
while S[i] == "L":
count += 1
i += 1
t.append(count)
T = int(len(t) / 2) # len(t)は必ず偶数
for i in range(T):
j += t[2 * i]
if t[2 * i] % 2 == 0:
if t[2 * i + 1] % 2 == 0:
n[j - 1] = int((t[2 * i] + t[2 * i + 1]) / 2)
n[j] = n[j - 1]
elif t[2 * i + 1] % 2 == 1:
n[j - 1] = t[2 * i + 1]
n[j] = t[2 * i]
elif t[2 * i] % 2 == 1:
if t[2 * i + 1] % 2 == 0:
n[j - 1] = int((t[2 * i] + t[2 * i + 1] + 1) / 2)
n[j] = n[j - 1] - 1
elif t[2 * i + 1] % 2 == 1:
n[j - 1] = int((t[2 * i] + t[2 * i + 1]) / 2)
n[j] = n[j - 1]
j += t[2 * i + 1]
print(" ".join(map(str, n)))
|
Statement
Given is a string S consisting of `L` and `R`.
Let N be the length of S. There are N squares arranged from left to right, and
the i-th character of S from the left is written on the i-th square from the
left.
The character written on the leftmost square is always `R`, and the character
written on the rightmost square is always `L`.
Initially, one child is standing on each square.
Each child will perform the move below 10^{100} times:
* Move one square in the direction specified by the character written in the square on which the child is standing. `L` denotes left, and `R` denotes right.
Find the number of children standing on each square after the children
performed the moves.
|
[{"input": "RRLRL", "output": "0 1 2 1 1\n \n\n * After each child performed one move, the number of children standing on each square is 0, 2, 1, 1, 1 from left to right.\n * After each child performed two moves, the number of children standing on each square is 0, 1, 2, 1, 1 from left to right.\n * After each child performed 10^{100} moves, the number of children standing on each square is 0, 1, 2, 1, 1 from left to right.\n\n* * *"}, {"input": "RRLLLLRLRRLL", "output": "0 3 3 0 0 0 1 1 0 2 2 0\n \n\n* * *"}, {"input": "RRRLLRLLRRRLLLLL", "output": "0 0 3 2 0 2 1 0 0 0 4 4 0 0 0 0"}]
|
Print the number of children standing on each square after the children
performed the moves, in order from left to right.
* * *
|
s215637462
|
Accepted
|
p02954
|
Input is given from Standard Input in the following format:
S
|
S = input()
rl = [0]
f = 0
for c in S:
if (c == "R" and f % 2 == 1) or (c == "L" and f % 2 == 0):
f += 1
rl.append(0)
rl[f] += 1
rla = [0] * len(rl)
rla[0] = rl[0]
for i in range(len(rl) - 1):
rla[i + 1] = rla[i] + rl[i + 1]
a = [0] * len(S)
for i in range(len(rl) // 2):
a[rla[i * 2] - 1] = (rl[i * 2] + 1) // 2 + rl[i * 2 + 1] // 2
for i in range(len(rl) // 2):
a[rla[i * 2]] = rl[i * 2] // 2 + (rl[i * 2 + 1] + 1) // 2
print(*a)
|
Statement
Given is a string S consisting of `L` and `R`.
Let N be the length of S. There are N squares arranged from left to right, and
the i-th character of S from the left is written on the i-th square from the
left.
The character written on the leftmost square is always `R`, and the character
written on the rightmost square is always `L`.
Initially, one child is standing on each square.
Each child will perform the move below 10^{100} times:
* Move one square in the direction specified by the character written in the square on which the child is standing. `L` denotes left, and `R` denotes right.
Find the number of children standing on each square after the children
performed the moves.
|
[{"input": "RRLRL", "output": "0 1 2 1 1\n \n\n * After each child performed one move, the number of children standing on each square is 0, 2, 1, 1, 1 from left to right.\n * After each child performed two moves, the number of children standing on each square is 0, 1, 2, 1, 1 from left to right.\n * After each child performed 10^{100} moves, the number of children standing on each square is 0, 1, 2, 1, 1 from left to right.\n\n* * *"}, {"input": "RRLLLLRLRRLL", "output": "0 3 3 0 0 0 1 1 0 2 2 0\n \n\n* * *"}, {"input": "RRRLLRLLRRRLLLLL", "output": "0 0 3 2 0 2 1 0 0 0 4 4 0 0 0 0"}]
|
Print the number of children standing on each square after the children
performed the moves, in order from left to right.
* * *
|
s075015721
|
Accepted
|
p02954
|
Input is given from Standard Input in the following format:
S
|
# 2019-11-16 10:55:08(JST)
import sys
# import collections
# import math
# from string import ascii_lowercase, ascii_uppercase, digits
# from bisect import bisect_left as bi_l, bisect_right as bi_r
# import itertools
# from functools import reduce
# import operator as op
# from scipy.misc import comb # float
# import numpy as np
import re
def main():
# 左がRで右がLとなっている箇所でそれぞれどちらかにあつまる。10^100 は実質無限なので距離が奇数か偶数かで場合わけ
s = (
sys.stdin.readline().rstrip() + "R"
) # 後々のループ処理のときのことを考えて最後にRを足しておく
n = len(s) - 1
all_occurrences_of_rl = [m.start() for m in re.finditer("RL", s)]
counts = [0 for _ in range(n)]
left = 0
for i in range(len(all_occurrences_of_rl)):
right = all_occurrences_of_rl[i] + 1
while s[right + 1] == "L": # 次がLだったら右端を拡張していく
right += 1
r_count = (
1
+ (all_occurrences_of_rl[i] - left) // 2
+ (right - all_occurrences_of_rl[i]) // 2
)
l_count = (right - left + 1) - r_count
counts[all_occurrences_of_rl[i]] = r_count
counts[all_occurrences_of_rl[i] + 1] = l_count
left = right + 1
for i in range(n):
print(counts[i], end=" ")
if __name__ == "__main__":
main()
|
Statement
Given is a string S consisting of `L` and `R`.
Let N be the length of S. There are N squares arranged from left to right, and
the i-th character of S from the left is written on the i-th square from the
left.
The character written on the leftmost square is always `R`, and the character
written on the rightmost square is always `L`.
Initially, one child is standing on each square.
Each child will perform the move below 10^{100} times:
* Move one square in the direction specified by the character written in the square on which the child is standing. `L` denotes left, and `R` denotes right.
Find the number of children standing on each square after the children
performed the moves.
|
[{"input": "RRLRL", "output": "0 1 2 1 1\n \n\n * After each child performed one move, the number of children standing on each square is 0, 2, 1, 1, 1 from left to right.\n * After each child performed two moves, the number of children standing on each square is 0, 1, 2, 1, 1 from left to right.\n * After each child performed 10^{100} moves, the number of children standing on each square is 0, 1, 2, 1, 1 from left to right.\n\n* * *"}, {"input": "RRLLLLRLRRLL", "output": "0 3 3 0 0 0 1 1 0 2 2 0\n \n\n* * *"}, {"input": "RRRLLRLLRRRLLLLL", "output": "0 0 3 2 0 2 1 0 0 0 4 4 0 0 0 0"}]
|
Print the number of children standing on each square after the children
performed the moves, in order from left to right.
* * *
|
s120388268
|
Wrong Answer
|
p02954
|
Input is given from Standard Input in the following format:
S
|
S = input() # 文字列を変数に格納
N = len(S)
now = "R"
A_R = 0
B_R = 0
A_L = 0
B_L = 0
List = []
for i in range(N - 1):
if now == "R" and S[i + 1] == "R":
if A_R <= B_R:
A_R += 1
else:
B_R += 1
elif now == "L" and S[i + 1] == "L":
if A_L <= B_L:
A_L += 1
else:
B_L += 1
elif now == "R" and S[i + 1] == "L":
now = "L"
if i == (N - 2):
for j in range(A_R + B_R):
List.append(0)
if A_R > B_R and A_L > B_L:
List.append(B_R + A_L + 1)
List.append(A_R + B_L + 1)
elif A_R > B_R and A_L == B_L:
List.append(B_R + A_L + 1)
List.append(A_R + B_L + 1)
elif A_R == B_R and A_L > B_L:
List.append(A_R + A_L + 1)
List.append(B_R + B_L + 1)
else:
List.append(A_R + A_L + 1)
List.append(B_R + B_L + 1)
elif now == "L" and (S[i + 1] == "R" or i == (N - 2)):
for j in range(A_R + B_R):
List.append(0)
if A_R > B_R and A_L > B_L:
List.append(B_R + A_L + 1)
List.append(A_R + B_L + 1)
elif A_R > B_R and A_L == B_L:
List.append(B_R + A_L + 1)
List.append(A_R + B_L + 1)
elif A_R == B_R and A_L > B_L:
List.append(A_R + A_L + 1)
List.append(B_R + B_L + 1)
else:
List.append(A_R + A_L + 1)
List.append(B_R + B_L + 1)
for k in range(A_L + B_L):
List.append(0)
A_R = 0
B_R = 0
A_L = 0
B_L = 0
now = "R"
print(List)
|
Statement
Given is a string S consisting of `L` and `R`.
Let N be the length of S. There are N squares arranged from left to right, and
the i-th character of S from the left is written on the i-th square from the
left.
The character written on the leftmost square is always `R`, and the character
written on the rightmost square is always `L`.
Initially, one child is standing on each square.
Each child will perform the move below 10^{100} times:
* Move one square in the direction specified by the character written in the square on which the child is standing. `L` denotes left, and `R` denotes right.
Find the number of children standing on each square after the children
performed the moves.
|
[{"input": "RRLRL", "output": "0 1 2 1 1\n \n\n * After each child performed one move, the number of children standing on each square is 0, 2, 1, 1, 1 from left to right.\n * After each child performed two moves, the number of children standing on each square is 0, 1, 2, 1, 1 from left to right.\n * After each child performed 10^{100} moves, the number of children standing on each square is 0, 1, 2, 1, 1 from left to right.\n\n* * *"}, {"input": "RRLLLLRLRRLL", "output": "0 3 3 0 0 0 1 1 0 2 2 0\n \n\n* * *"}, {"input": "RRRLLRLLRRRLLLLL", "output": "0 0 3 2 0 2 1 0 0 0 4 4 0 0 0 0"}]
|
Print the number of children standing on each square after the children
performed the moves, in order from left to right.
* * *
|
s309434516
|
Wrong Answer
|
p02954
|
Input is given from Standard Input in the following format:
S
|
String = input()
sbstr_list = ["R" + substr + "L" for substr in String.split("LR")]
sbstr_list[0] = sbstr_list[0][1:]
sbstr_list[-1] = sbstr_list[-1][:-1]
print(sbstr_list)
for sbstr in sbstr_list:
length = len(sbstr)
subans = ["0"] * length
pos = sbstr.find("RL")
# print(pos)
subans[pos] = str(1 + pos // 2 + (length - pos - 1) // 2)
subans[pos + 1] = str(1 + (pos + 1) // 2 + (length - pos - 2) // 2)
print(" ".join(subans), end=" ")
print("")
|
Statement
Given is a string S consisting of `L` and `R`.
Let N be the length of S. There are N squares arranged from left to right, and
the i-th character of S from the left is written on the i-th square from the
left.
The character written on the leftmost square is always `R`, and the character
written on the rightmost square is always `L`.
Initially, one child is standing on each square.
Each child will perform the move below 10^{100} times:
* Move one square in the direction specified by the character written in the square on which the child is standing. `L` denotes left, and `R` denotes right.
Find the number of children standing on each square after the children
performed the moves.
|
[{"input": "RRLRL", "output": "0 1 2 1 1\n \n\n * After each child performed one move, the number of children standing on each square is 0, 2, 1, 1, 1 from left to right.\n * After each child performed two moves, the number of children standing on each square is 0, 1, 2, 1, 1 from left to right.\n * After each child performed 10^{100} moves, the number of children standing on each square is 0, 1, 2, 1, 1 from left to right.\n\n* * *"}, {"input": "RRLLLLRLRRLL", "output": "0 3 3 0 0 0 1 1 0 2 2 0\n \n\n* * *"}, {"input": "RRRLLRLLRRRLLLLL", "output": "0 0 3 2 0 2 1 0 0 0 4 4 0 0 0 0"}]
|
Print the number of children standing on each square after the children
performed the moves, in order from left to right.
* * *
|
s101218232
|
Wrong Answer
|
p02954
|
Input is given from Standard Input in the following format:
S
|
S = input()
start_posi = [int(i) for i in range(len(S))]
cnt = 0
posi = start_posi
pre_posi = {}
next_posi = start_posi
while not posi in pre_posi.values():
pre_posi[cnt] = next_posi
next_posi = []
for i in posi:
next_posi.append(i + 1 if S[i] == "R" else i - 1)
posi = next_posi
cnt += 1
print(cnt)
for key, v in pre_posi.items():
if posi == v:
loop_width = cnt - key
loop_point = key
break
loop = (10**100 - loop_point) % loop_width
print(pre_posi)
print(pre_posi[loop + loop_point])
answer_dict = {i: 0 for i in range(len(S))}
for mass in pre_posi[loop + loop_point]:
answer_dict[mass] += 1
print(" ".join(map(str, answer_dict.values())))
|
Statement
Given is a string S consisting of `L` and `R`.
Let N be the length of S. There are N squares arranged from left to right, and
the i-th character of S from the left is written on the i-th square from the
left.
The character written on the leftmost square is always `R`, and the character
written on the rightmost square is always `L`.
Initially, one child is standing on each square.
Each child will perform the move below 10^{100} times:
* Move one square in the direction specified by the character written in the square on which the child is standing. `L` denotes left, and `R` denotes right.
Find the number of children standing on each square after the children
performed the moves.
|
[{"input": "RRLRL", "output": "0 1 2 1 1\n \n\n * After each child performed one move, the number of children standing on each square is 0, 2, 1, 1, 1 from left to right.\n * After each child performed two moves, the number of children standing on each square is 0, 1, 2, 1, 1 from left to right.\n * After each child performed 10^{100} moves, the number of children standing on each square is 0, 1, 2, 1, 1 from left to right.\n\n* * *"}, {"input": "RRLLLLRLRRLL", "output": "0 3 3 0 0 0 1 1 0 2 2 0\n \n\n* * *"}, {"input": "RRRLLRLLRRRLLLLL", "output": "0 0 3 2 0 2 1 0 0 0 4 4 0 0 0 0"}]
|
Print the number of children standing on each square after the children
performed the moves, in order from left to right.
* * *
|
s958250947
|
Wrong Answer
|
p02954
|
Input is given from Standard Input in the following format:
S
|
# @author
import sys
class DGatheringChildren:
def solve(self):
s = input()
n = len(s)
i = 0
last = 0
ans = [0] * n
while i < n - 1:
if s[i] == "R" and s[i + 1] == "L":
ans[i + 1] += 1
for j in range(last, i + 1):
if (i - j) % 2 == 0:
ans[i] += 1
else:
ans[i + 1] += 1
k = i + 2
while k < n and s[k] == "L":
if (k - i) % 2 == 0:
ans[i] += 1
else:
ans[i + 1] += 1
k += 1
last = k
i += 1
i += 1
print(*ans)
solver = DGatheringChildren()
input = sys.stdin.readline
solver.solve()
|
Statement
Given is a string S consisting of `L` and `R`.
Let N be the length of S. There are N squares arranged from left to right, and
the i-th character of S from the left is written on the i-th square from the
left.
The character written on the leftmost square is always `R`, and the character
written on the rightmost square is always `L`.
Initially, one child is standing on each square.
Each child will perform the move below 10^{100} times:
* Move one square in the direction specified by the character written in the square on which the child is standing. `L` denotes left, and `R` denotes right.
Find the number of children standing on each square after the children
performed the moves.
|
[{"input": "RRLRL", "output": "0 1 2 1 1\n \n\n * After each child performed one move, the number of children standing on each square is 0, 2, 1, 1, 1 from left to right.\n * After each child performed two moves, the number of children standing on each square is 0, 1, 2, 1, 1 from left to right.\n * After each child performed 10^{100} moves, the number of children standing on each square is 0, 1, 2, 1, 1 from left to right.\n\n* * *"}, {"input": "RRLLLLRLRRLL", "output": "0 3 3 0 0 0 1 1 0 2 2 0\n \n\n* * *"}, {"input": "RRRLLRLLRRRLLLLL", "output": "0 0 3 2 0 2 1 0 0 0 4 4 0 0 0 0"}]
|
Print the number of children standing on each square after the children
performed the moves, in order from left to right.
* * *
|
s713211426
|
Wrong Answer
|
p02954
|
Input is given from Standard Input in the following format:
S
|
import numpy as np
def replace_RL(RL_str, word):
buf = []
for s in RL_str:
if s == word:
buf.append(1)
else:
buf.append(0)
return np.array(buf)
RL_str = list(input())
menber = np.array([1] * len(RL_str))
R_list = replace_RL(RL_str, "R")
L_list = replace_RL(RL_str, "L")
for n in range(999):
men_R = menber * R_list
men_L = menber * L_list
# shift
men_R = np.roll(men_R, 1)
men_L = np.roll(men_L, -1)
menber = men_R + men_L
print(menber)
|
Statement
Given is a string S consisting of `L` and `R`.
Let N be the length of S. There are N squares arranged from left to right, and
the i-th character of S from the left is written on the i-th square from the
left.
The character written on the leftmost square is always `R`, and the character
written on the rightmost square is always `L`.
Initially, one child is standing on each square.
Each child will perform the move below 10^{100} times:
* Move one square in the direction specified by the character written in the square on which the child is standing. `L` denotes left, and `R` denotes right.
Find the number of children standing on each square after the children
performed the moves.
|
[{"input": "RRLRL", "output": "0 1 2 1 1\n \n\n * After each child performed one move, the number of children standing on each square is 0, 2, 1, 1, 1 from left to right.\n * After each child performed two moves, the number of children standing on each square is 0, 1, 2, 1, 1 from left to right.\n * After each child performed 10^{100} moves, the number of children standing on each square is 0, 1, 2, 1, 1 from left to right.\n\n* * *"}, {"input": "RRLLLLRLRRLL", "output": "0 3 3 0 0 0 1 1 0 2 2 0\n \n\n* * *"}, {"input": "RRRLLRLLRRRLLLLL", "output": "0 0 3 2 0 2 1 0 0 0 4 4 0 0 0 0"}]
|
Print the number of children standing on each square after the children
performed the moves, in order from left to right.
* * *
|
s642982075
|
Wrong Answer
|
p02954
|
Input is given from Standard Input in the following format:
S
|
s = [s for s in input()]
c = [1 for i in s]
poc = []
pec = []
def x():
global c
for i, z in enumerate(s):
if z == "R" and c[i] > 0:
c[i] -= 1
c[i + 1] += 1
elif z == "L" and c[i] > 0:
c[i] -= 1
c[i - 1] += 1
for i in range(10**100):
x()
if i % 2:
if poc:
if poc == c:
break
poc = c.copy()
else:
if pec:
if pec == c:
break
pec = c.copy()
print(" ".join([str(s) for s in c]))
|
Statement
Given is a string S consisting of `L` and `R`.
Let N be the length of S. There are N squares arranged from left to right, and
the i-th character of S from the left is written on the i-th square from the
left.
The character written on the leftmost square is always `R`, and the character
written on the rightmost square is always `L`.
Initially, one child is standing on each square.
Each child will perform the move below 10^{100} times:
* Move one square in the direction specified by the character written in the square on which the child is standing. `L` denotes left, and `R` denotes right.
Find the number of children standing on each square after the children
performed the moves.
|
[{"input": "RRLRL", "output": "0 1 2 1 1\n \n\n * After each child performed one move, the number of children standing on each square is 0, 2, 1, 1, 1 from left to right.\n * After each child performed two moves, the number of children standing on each square is 0, 1, 2, 1, 1 from left to right.\n * After each child performed 10^{100} moves, the number of children standing on each square is 0, 1, 2, 1, 1 from left to right.\n\n* * *"}, {"input": "RRLLLLRLRRLL", "output": "0 3 3 0 0 0 1 1 0 2 2 0\n \n\n* * *"}, {"input": "RRRLLRLLRRRLLLLL", "output": "0 0 3 2 0 2 1 0 0 0 4 4 0 0 0 0"}]
|
Print the number of children standing on each square after the children
performed the moves, in order from left to right.
* * *
|
s523509774
|
Wrong Answer
|
p02954
|
Input is given from Standard Input in the following format:
S
|
maps = [s for s in str(input())]
people = [1] * len(maps)
store = {}
max_count = 10 * 100
def update(people):
n_people = [0] * len(maps)
for i in range(len(people)):
for n in range(people[i]):
if maps[i] == "R":
n_people[i] -= 1
n_people[i + 1] += 1
else:
n_people[i] -= 1
n_people[i - 1] += 1
return [people[i] + n_people[i] for i in range(len(people))]
for c in range(max_count):
people = update(people)
map_key = "".join(str(i) for i in people)
if map_key in store:
mod = max_count % (c + 1)
for i in range(mod):
people = update(people)
break
store[map_key] = c
print(" ".join(str(i) for i in people))
|
Statement
Given is a string S consisting of `L` and `R`.
Let N be the length of S. There are N squares arranged from left to right, and
the i-th character of S from the left is written on the i-th square from the
left.
The character written on the leftmost square is always `R`, and the character
written on the rightmost square is always `L`.
Initially, one child is standing on each square.
Each child will perform the move below 10^{100} times:
* Move one square in the direction specified by the character written in the square on which the child is standing. `L` denotes left, and `R` denotes right.
Find the number of children standing on each square after the children
performed the moves.
|
[{"input": "RRLRL", "output": "0 1 2 1 1\n \n\n * After each child performed one move, the number of children standing on each square is 0, 2, 1, 1, 1 from left to right.\n * After each child performed two moves, the number of children standing on each square is 0, 1, 2, 1, 1 from left to right.\n * After each child performed 10^{100} moves, the number of children standing on each square is 0, 1, 2, 1, 1 from left to right.\n\n* * *"}, {"input": "RRLLLLRLRRLL", "output": "0 3 3 0 0 0 1 1 0 2 2 0\n \n\n* * *"}, {"input": "RRRLLRLLRRRLLLLL", "output": "0 0 3 2 0 2 1 0 0 0 4 4 0 0 0 0"}]
|
Print the number of children standing on each square after the children
performed the moves, in order from left to right.
* * *
|
s362805001
|
Accepted
|
p02954
|
Input is given from Standard Input in the following format:
S
|
# -*- coding: utf-8 -*-
import sys
def input():
return sys.stdin.readline().strip()
def list2d(a, b, c):
return [[c] * b for i in range(a)]
def list3d(a, b, c, d):
return [[[d] * c for j in range(b)] for i in range(a)]
def ceil(x, y=1):
return int(-(-x // y))
def INT():
return int(input())
def MAP():
return map(int, input().split())
def LIST():
return list(map(int, input().split()))
def Yes():
print("Yes")
def No():
print("No")
def YES():
print("YES")
def NO():
print("NO")
sys.setrecursionlimit(10**9)
INF = float("inf")
MOD = 10**9 + 7
S = input()
N = len(S)
# nxt[k][i] := 最初iにいた子が2^k回の移動後にいるマス
nxt = list2d(17, N, -1)
# 初期化
for i in range(N):
if S[i] == "L":
nxt[0][i] = i - 1
elif S[i] == "R":
nxt[0][i] = i + 1
# ダブリングのテーブル構築
for k in range(1, 17):
for i in range(N):
nxt[k][i] = nxt[k - 1][nxt[k - 1][i]]
ans = [0] * N
# 10万回移動後を求める(今回はこれで10**100と一致する)
K = 10**5
# 元々iにいた子
for i in range(N):
cur = i
for k in range(17):
# ビットが立っている所に合わせて、移動させていく
if K >> k & 1:
cur = nxt[k][cur]
ans[cur] += 1
print(*ans)
|
Statement
Given is a string S consisting of `L` and `R`.
Let N be the length of S. There are N squares arranged from left to right, and
the i-th character of S from the left is written on the i-th square from the
left.
The character written on the leftmost square is always `R`, and the character
written on the rightmost square is always `L`.
Initially, one child is standing on each square.
Each child will perform the move below 10^{100} times:
* Move one square in the direction specified by the character written in the square on which the child is standing. `L` denotes left, and `R` denotes right.
Find the number of children standing on each square after the children
performed the moves.
|
[{"input": "RRLRL", "output": "0 1 2 1 1\n \n\n * After each child performed one move, the number of children standing on each square is 0, 2, 1, 1, 1 from left to right.\n * After each child performed two moves, the number of children standing on each square is 0, 1, 2, 1, 1 from left to right.\n * After each child performed 10^{100} moves, the number of children standing on each square is 0, 1, 2, 1, 1 from left to right.\n\n* * *"}, {"input": "RRLLLLRLRRLL", "output": "0 3 3 0 0 0 1 1 0 2 2 0\n \n\n* * *"}, {"input": "RRRLLRLLRRRLLLLL", "output": "0 0 3 2 0 2 1 0 0 0 4 4 0 0 0 0"}]
|
Print the number of children standing on each square after the children
performed the moves, in order from left to right.
* * *
|
s940872925
|
Wrong Answer
|
p02954
|
Input is given from Standard Input in the following format:
S
|
s = list(input())
h = [1] * len(s)
hTemp = [0] * len(s)
history = []
for i in range(0, 10 * 100):
for i in range(0, len(s)):
if s[i] == "R" and h[i] != 0:
hTemp[i + 1] += h[i]
hTemp[i] -= h[i]
elif s[i] == "L" and h[i] != 0:
hTemp[i - 1] += h[i]
hTemp[i] -= h[i]
for j in range(0, len(s)):
h[j] += hTemp[j]
hTemp = [0] * len(s)
print(h)
|
Statement
Given is a string S consisting of `L` and `R`.
Let N be the length of S. There are N squares arranged from left to right, and
the i-th character of S from the left is written on the i-th square from the
left.
The character written on the leftmost square is always `R`, and the character
written on the rightmost square is always `L`.
Initially, one child is standing on each square.
Each child will perform the move below 10^{100} times:
* Move one square in the direction specified by the character written in the square on which the child is standing. `L` denotes left, and `R` denotes right.
Find the number of children standing on each square after the children
performed the moves.
|
[{"input": "RRLRL", "output": "0 1 2 1 1\n \n\n * After each child performed one move, the number of children standing on each square is 0, 2, 1, 1, 1 from left to right.\n * After each child performed two moves, the number of children standing on each square is 0, 1, 2, 1, 1 from left to right.\n * After each child performed 10^{100} moves, the number of children standing on each square is 0, 1, 2, 1, 1 from left to right.\n\n* * *"}, {"input": "RRLLLLRLRRLL", "output": "0 3 3 0 0 0 1 1 0 2 2 0\n \n\n* * *"}, {"input": "RRRLLRLLRRRLLLLL", "output": "0 0 3 2 0 2 1 0 0 0 4 4 0 0 0 0"}]
|
Print the number of children standing on each square after the children
performed the moves, in order from left to right.
* * *
|
s864088634
|
Wrong Answer
|
p02954
|
Input is given from Standard Input in the following format:
S
|
S = input()
Slen = len(S)
moves = [-1 if s == "L" else 1 for s in S]
counts = [1] * Slen
for x in range(10 ^ 100):
new_counts = [0] * Slen
for i in range(Slen):
new_counts[i + moves[i]] += counts[i]
counts = new_counts
print(" ".join(map(str, counts)))
|
Statement
Given is a string S consisting of `L` and `R`.
Let N be the length of S. There are N squares arranged from left to right, and
the i-th character of S from the left is written on the i-th square from the
left.
The character written on the leftmost square is always `R`, and the character
written on the rightmost square is always `L`.
Initially, one child is standing on each square.
Each child will perform the move below 10^{100} times:
* Move one square in the direction specified by the character written in the square on which the child is standing. `L` denotes left, and `R` denotes right.
Find the number of children standing on each square after the children
performed the moves.
|
[{"input": "RRLRL", "output": "0 1 2 1 1\n \n\n * After each child performed one move, the number of children standing on each square is 0, 2, 1, 1, 1 from left to right.\n * After each child performed two moves, the number of children standing on each square is 0, 1, 2, 1, 1 from left to right.\n * After each child performed 10^{100} moves, the number of children standing on each square is 0, 1, 2, 1, 1 from left to right.\n\n* * *"}, {"input": "RRLLLLRLRRLL", "output": "0 3 3 0 0 0 1 1 0 2 2 0\n \n\n* * *"}, {"input": "RRRLLRLLRRRLLLLL", "output": "0 0 3 2 0 2 1 0 0 0 4 4 0 0 0 0"}]
|
Print the number of children standing on each square after the children
performed the moves, in order from left to right.
* * *
|
s042822887
|
Wrong Answer
|
p02954
|
Input is given from Standard Input in the following format:
S
|
from operator import add
str_list = list(map(str, input().split()))[0]
num_list = [1] * len(str_list)
for _ in range(10):
tmp_list = [0] * len(str_list)
for i, (c, n) in enumerate(zip(str_list, num_list)):
# print(i, c, n)
if c == "R" and num_list[i] != 0:
tmp_list[i] -= n
tmp_list[i + 1] += n
else:
if num_list[i] != 0:
tmp_list[i] -= n
tmp_list[i - 1] += n
# print(num_list, tmp_list, list( map(add, num_list, tmp_list)))
num_list = list(map(add, num_list, tmp_list))
# print(num_list)
print(num_list)
|
Statement
Given is a string S consisting of `L` and `R`.
Let N be the length of S. There are N squares arranged from left to right, and
the i-th character of S from the left is written on the i-th square from the
left.
The character written on the leftmost square is always `R`, and the character
written on the rightmost square is always `L`.
Initially, one child is standing on each square.
Each child will perform the move below 10^{100} times:
* Move one square in the direction specified by the character written in the square on which the child is standing. `L` denotes left, and `R` denotes right.
Find the number of children standing on each square after the children
performed the moves.
|
[{"input": "RRLRL", "output": "0 1 2 1 1\n \n\n * After each child performed one move, the number of children standing on each square is 0, 2, 1, 1, 1 from left to right.\n * After each child performed two moves, the number of children standing on each square is 0, 1, 2, 1, 1 from left to right.\n * After each child performed 10^{100} moves, the number of children standing on each square is 0, 1, 2, 1, 1 from left to right.\n\n* * *"}, {"input": "RRLLLLRLRRLL", "output": "0 3 3 0 0 0 1 1 0 2 2 0\n \n\n* * *"}, {"input": "RRRLLRLLRRRLLLLL", "output": "0 0 3 2 0 2 1 0 0 0 4 4 0 0 0 0"}]
|
Print the number of children standing on each square after the children
performed the moves, in order from left to right.
* * *
|
s841004633
|
Runtime Error
|
p02954
|
Input is given from Standard Input in the following format:
S
|
cs = list(input())
ns = [1] * len(cs)
iter = len(cs) // 4 if len(cs) % 4 == 0 else (len(cs) + 3) // 2
for _ in range(iter):
prev = ns.copy()
ns[0] = prev[1] if cs[1] == "L" else 0
for i in range(1, len(cs) - 1):
ns[i] = (prev[i - 1] if cs[i - 1] == "R" else 0) + (
prev[i + 1] if cs[i + 1] == "L" else 0
)
ns[len(cs) - 1] = prev[len(cs) - 2] if cs[len(cs) - 2] == "R" else 0
print(" ".join(map(str, ns)))
|
Statement
Given is a string S consisting of `L` and `R`.
Let N be the length of S. There are N squares arranged from left to right, and
the i-th character of S from the left is written on the i-th square from the
left.
The character written on the leftmost square is always `R`, and the character
written on the rightmost square is always `L`.
Initially, one child is standing on each square.
Each child will perform the move below 10^{100} times:
* Move one square in the direction specified by the character written in the square on which the child is standing. `L` denotes left, and `R` denotes right.
Find the number of children standing on each square after the children
performed the moves.
|
[{"input": "RRLRL", "output": "0 1 2 1 1\n \n\n * After each child performed one move, the number of children standing on each square is 0, 2, 1, 1, 1 from left to right.\n * After each child performed two moves, the number of children standing on each square is 0, 1, 2, 1, 1 from left to right.\n * After each child performed 10^{100} moves, the number of children standing on each square is 0, 1, 2, 1, 1 from left to right.\n\n* * *"}, {"input": "RRLLLLRLRRLL", "output": "0 3 3 0 0 0 1 1 0 2 2 0\n \n\n* * *"}, {"input": "RRRLLRLLRRRLLLLL", "output": "0 0 3 2 0 2 1 0 0 0 4 4 0 0 0 0"}]
|
Print the number of children standing on each square after the children
performed the moves, in order from left to right.
* * *
|
s775087893
|
Runtime Error
|
p02954
|
Input is given from Standard Input in the following format:
S
|
s = list(map(input().split()))
ans = []
|
Statement
Given is a string S consisting of `L` and `R`.
Let N be the length of S. There are N squares arranged from left to right, and
the i-th character of S from the left is written on the i-th square from the
left.
The character written on the leftmost square is always `R`, and the character
written on the rightmost square is always `L`.
Initially, one child is standing on each square.
Each child will perform the move below 10^{100} times:
* Move one square in the direction specified by the character written in the square on which the child is standing. `L` denotes left, and `R` denotes right.
Find the number of children standing on each square after the children
performed the moves.
|
[{"input": "RRLRL", "output": "0 1 2 1 1\n \n\n * After each child performed one move, the number of children standing on each square is 0, 2, 1, 1, 1 from left to right.\n * After each child performed two moves, the number of children standing on each square is 0, 1, 2, 1, 1 from left to right.\n * After each child performed 10^{100} moves, the number of children standing on each square is 0, 1, 2, 1, 1 from left to right.\n\n* * *"}, {"input": "RRLLLLRLRRLL", "output": "0 3 3 0 0 0 1 1 0 2 2 0\n \n\n* * *"}, {"input": "RRRLLRLLRRRLLLLL", "output": "0 0 3 2 0 2 1 0 0 0 4 4 0 0 0 0"}]
|
Print the number of children standing on each square after the children
performed the moves, in order from left to right.
* * *
|
s546814233
|
Accepted
|
p02954
|
Input is given from Standard Input in the following format:
S
|
import sys
input = sys.stdin.readline
S = list(input())[:-1]
rtable = [1]
ltable = [0]
N = len(S)
for i in range(1, N):
if S[i - 1] == "L" and (S[i] == "R"):
rtable.append(1)
ltable.append(0)
elif S[i] == "R":
rtable[-1] += 1
else:
ltable[-1] += 1
lrtable = []
for i in range(N - 1):
if S[i] == "R" and (S[i + 1] == "L"):
lrtable.append(i)
# print(lrtable)
# print(ltable, rtable)
res = [0] * N
for i in range(len(lrtable)):
x = lrtable[i]
y = -(-ltable[i] // 2)
z = -(-rtable[i] // 2)
l = z + (ltable[i] - y)
r = y + (rtable[i] - z)
res[x] = l
res[x + 1] = r
print(*res)
|
Statement
Given is a string S consisting of `L` and `R`.
Let N be the length of S. There are N squares arranged from left to right, and
the i-th character of S from the left is written on the i-th square from the
left.
The character written on the leftmost square is always `R`, and the character
written on the rightmost square is always `L`.
Initially, one child is standing on each square.
Each child will perform the move below 10^{100} times:
* Move one square in the direction specified by the character written in the square on which the child is standing. `L` denotes left, and `R` denotes right.
Find the number of children standing on each square after the children
performed the moves.
|
[{"input": "RRLRL", "output": "0 1 2 1 1\n \n\n * After each child performed one move, the number of children standing on each square is 0, 2, 1, 1, 1 from left to right.\n * After each child performed two moves, the number of children standing on each square is 0, 1, 2, 1, 1 from left to right.\n * After each child performed 10^{100} moves, the number of children standing on each square is 0, 1, 2, 1, 1 from left to right.\n\n* * *"}, {"input": "RRLLLLRLRRLL", "output": "0 3 3 0 0 0 1 1 0 2 2 0\n \n\n* * *"}, {"input": "RRRLLRLLRRRLLLLL", "output": "0 0 3 2 0 2 1 0 0 0 4 4 0 0 0 0"}]
|
Print the number of children standing on each square after the children
performed the moves, in order from left to right.
* * *
|
s700847852
|
Accepted
|
p02954
|
Input is given from Standard Input in the following format:
S
|
S = input()
score = [0 for _ in range(len(S))]
# s
previous_l = 0
for index in range(len(S)):
if S[index] == "L":
if previous_l + 1 < index:
# L
score[index] += (index - previous_l) // 2
# R
score[index - 1] += (index - previous_l - 1) // 2
previous_l = index + 1
# print(score)
previous_r = len(S) - 1
for index in reversed(range(len(S))):
if S[index] == "R":
if previous_r - 1 > index:
score[index] += (previous_r - index) // 2
score[index + 1] += (previous_r - index - 1) // 2
previous_r = index - 1
# print(score)
# LR
for index in range(len(S)):
if S[index] == "R" and S[index + 1] == "L":
score[index] += 1
score[index + 1] += 1
print(" ".join(map(str, score)))
|
Statement
Given is a string S consisting of `L` and `R`.
Let N be the length of S. There are N squares arranged from left to right, and
the i-th character of S from the left is written on the i-th square from the
left.
The character written on the leftmost square is always `R`, and the character
written on the rightmost square is always `L`.
Initially, one child is standing on each square.
Each child will perform the move below 10^{100} times:
* Move one square in the direction specified by the character written in the square on which the child is standing. `L` denotes left, and `R` denotes right.
Find the number of children standing on each square after the children
performed the moves.
|
[{"input": "RRLRL", "output": "0 1 2 1 1\n \n\n * After each child performed one move, the number of children standing on each square is 0, 2, 1, 1, 1 from left to right.\n * After each child performed two moves, the number of children standing on each square is 0, 1, 2, 1, 1 from left to right.\n * After each child performed 10^{100} moves, the number of children standing on each square is 0, 1, 2, 1, 1 from left to right.\n\n* * *"}, {"input": "RRLLLLRLRRLL", "output": "0 3 3 0 0 0 1 1 0 2 2 0\n \n\n* * *"}, {"input": "RRRLLRLLRRRLLLLL", "output": "0 0 3 2 0 2 1 0 0 0 4 4 0 0 0 0"}]
|
Print the number of children standing on each square after the children
performed the moves, in order from left to right.
* * *
|
s796804270
|
Runtime Error
|
p02954
|
Input is given from Standard Input in the following format:
S
|
N, K = map(int, input().split())
A = list(map(int, input().split()))
def get_divisors(n):
from math import ceil
divisors = []
for num in range(ceil(n**0.5), n + 1):
if n % num == 0:
divisors.append(n // num)
if n // num != n:
divisors.append(num)
divisors.sort(reverse=True)
return divisors
total = sum(A)
divisors = get_divisors(total)
ans = -1
for d in divisors:
R = [a % d for a in A]
R.sort(reverse=True)
pr = 0
nr = -sum(R)
for i, r in enumerate(R):
pr += d - r
nr += r
if nr + pr >= 0:
if pr <= K and nr + pr == 0:
ans = d
break
if ans != -1:
print(ans)
break
else:
print(1)
|
Statement
Given is a string S consisting of `L` and `R`.
Let N be the length of S. There are N squares arranged from left to right, and
the i-th character of S from the left is written on the i-th square from the
left.
The character written on the leftmost square is always `R`, and the character
written on the rightmost square is always `L`.
Initially, one child is standing on each square.
Each child will perform the move below 10^{100} times:
* Move one square in the direction specified by the character written in the square on which the child is standing. `L` denotes left, and `R` denotes right.
Find the number of children standing on each square after the children
performed the moves.
|
[{"input": "RRLRL", "output": "0 1 2 1 1\n \n\n * After each child performed one move, the number of children standing on each square is 0, 2, 1, 1, 1 from left to right.\n * After each child performed two moves, the number of children standing on each square is 0, 1, 2, 1, 1 from left to right.\n * After each child performed 10^{100} moves, the number of children standing on each square is 0, 1, 2, 1, 1 from left to right.\n\n* * *"}, {"input": "RRLLLLRLRRLL", "output": "0 3 3 0 0 0 1 1 0 2 2 0\n \n\n* * *"}, {"input": "RRRLLRLLRRRLLLLL", "output": "0 0 3 2 0 2 1 0 0 0 4 4 0 0 0 0"}]
|
Print the number of children standing on each square after the children
performed the moves, in order from left to right.
* * *
|
s910673058
|
Accepted
|
p02954
|
Input is given from Standard Input in the following format:
S
|
S = input()
slist = S.split("LR")
res = [["0"] * len(s) for s in slist]
for i in range(len(slist)):
if i < len(slist) - 1:
slist[i] = slist[i] + "L"
res[i].append("0")
slist[i + 1] = "R" + slist[i + 1]
res[i + 1].append("0")
Rc = slist[i].count("R")
Lc = slist[i].count("L")
# print(slist[i], Rc, Lc)
res[i][Rc - 1] = str(Lc // 2 + (Rc - Rc // 2))
res[i][Rc] = str(Rc // 2 + (Lc - Lc // 2))
res2 = ""
# print(res)
for i in range(len(slist)):
# print(res[i])
res2 = res2 + " ".join(res[i])
if i < len(slist) - 1:
res2 = res2 + " "
print(res2)
|
Statement
Given is a string S consisting of `L` and `R`.
Let N be the length of S. There are N squares arranged from left to right, and
the i-th character of S from the left is written on the i-th square from the
left.
The character written on the leftmost square is always `R`, and the character
written on the rightmost square is always `L`.
Initially, one child is standing on each square.
Each child will perform the move below 10^{100} times:
* Move one square in the direction specified by the character written in the square on which the child is standing. `L` denotes left, and `R` denotes right.
Find the number of children standing on each square after the children
performed the moves.
|
[{"input": "RRLRL", "output": "0 1 2 1 1\n \n\n * After each child performed one move, the number of children standing on each square is 0, 2, 1, 1, 1 from left to right.\n * After each child performed two moves, the number of children standing on each square is 0, 1, 2, 1, 1 from left to right.\n * After each child performed 10^{100} moves, the number of children standing on each square is 0, 1, 2, 1, 1 from left to right.\n\n* * *"}, {"input": "RRLLLLRLRRLL", "output": "0 3 3 0 0 0 1 1 0 2 2 0\n \n\n* * *"}, {"input": "RRRLLRLLRRRLLLLL", "output": "0 0 3 2 0 2 1 0 0 0 4 4 0 0 0 0"}]
|
Print the number of children standing on each square after the children
performed the moves, in order from left to right.
* * *
|
s954721236
|
Accepted
|
p02954
|
Input is given from Standard Input in the following format:
S
|
# https://atcoder.jp/contests/abc136/tasks/abc136_d
s = list(str(input()))
n = len(s)
t = []
u = []
v = [0] * n
for i in range(n):
if i == 0:
for j in range(i, n):
if s[j] == "L":
t.append(j - 1)
u.append(j - i - 1)
break
else:
if s[i] == s[i - 1]:
t.append(t[i - 1])
u.append(u[i - 1] + 1)
elif s[i] == "R":
for j in range(i, n):
if s[j] == "L":
t.append(j - 1)
u.append(j - i - 1)
break
else:
for j in reversed(range(i)):
if s[j] == "R":
t.append(j)
u.append(i - j)
break
"""
t.append(i-1)
u.append(0)
"""
a = u[i] % 2
v[t[i] + a] += 1
print(" ".join(map(str, v)))
|
Statement
Given is a string S consisting of `L` and `R`.
Let N be the length of S. There are N squares arranged from left to right, and
the i-th character of S from the left is written on the i-th square from the
left.
The character written on the leftmost square is always `R`, and the character
written on the rightmost square is always `L`.
Initially, one child is standing on each square.
Each child will perform the move below 10^{100} times:
* Move one square in the direction specified by the character written in the square on which the child is standing. `L` denotes left, and `R` denotes right.
Find the number of children standing on each square after the children
performed the moves.
|
[{"input": "RRLRL", "output": "0 1 2 1 1\n \n\n * After each child performed one move, the number of children standing on each square is 0, 2, 1, 1, 1 from left to right.\n * After each child performed two moves, the number of children standing on each square is 0, 1, 2, 1, 1 from left to right.\n * After each child performed 10^{100} moves, the number of children standing on each square is 0, 1, 2, 1, 1 from left to right.\n\n* * *"}, {"input": "RRLLLLRLRRLL", "output": "0 3 3 0 0 0 1 1 0 2 2 0\n \n\n* * *"}, {"input": "RRRLLRLLRRRLLLLL", "output": "0 0 3 2 0 2 1 0 0 0 4 4 0 0 0 0"}]
|
Print the number of children standing on each square after the children
performed the moves, in order from left to right.
* * *
|
s009175266
|
Accepted
|
p02954
|
Input is given from Standard Input in the following format:
S
|
# -*- coding: utf-8 -*-
"""
Created on Sun Apr 12 18:08:28 2020
@author: Kanaru Sato
"""
s = list(input())
N = len(s)
rf = 0
lf = 0
lis = []
i = 0
for i in range(N):
if rf == 0 and s[i] == "R":
if lf == 1:
lf = 0
lis.append(i - 1)
lis.append(i)
rf = 1
elif rf == 1 and s[i] == "R":
if s[i + 1] == "L":
lis.append(i)
rf = 0
else:
continue
elif lf == 0 and s[i] == "L":
if rf == 1:
rf = 0
lis.append(i - 1)
lis.append(i)
lf = 1
elif lf == 1 and s[i] == "L":
if i == N - 1:
lis.append(i)
else:
if s[i + 1] == "R":
lis.append(i)
lf = 0
else:
continue
if len(lis) % 4 != 0:
lis.append(lis[-1])
##print(lis)
n = 0
anslist = []
for cell in range(N):
if cell > lis[4 * n + 3]:
n += 1
In = lis[4 * n + 0]
Jn = lis[4 * n + 1]
Kn = lis[4 * n + 2]
Ln = lis[4 * n + 3]
if cell < Jn:
ans = 0
elif cell == Jn:
ans = (Ln - Jn) // 2 + (Jn - In) // 2 + 1
elif cell == Kn:
ans = (Ln - Kn) // 2 + (Kn - In) // 2 + 1
else:
ans = 0
anslist.append(ans)
anslist = list(map(str, anslist))
print(" ".join(anslist))
|
Statement
Given is a string S consisting of `L` and `R`.
Let N be the length of S. There are N squares arranged from left to right, and
the i-th character of S from the left is written on the i-th square from the
left.
The character written on the leftmost square is always `R`, and the character
written on the rightmost square is always `L`.
Initially, one child is standing on each square.
Each child will perform the move below 10^{100} times:
* Move one square in the direction specified by the character written in the square on which the child is standing. `L` denotes left, and `R` denotes right.
Find the number of children standing on each square after the children
performed the moves.
|
[{"input": "RRLRL", "output": "0 1 2 1 1\n \n\n * After each child performed one move, the number of children standing on each square is 0, 2, 1, 1, 1 from left to right.\n * After each child performed two moves, the number of children standing on each square is 0, 1, 2, 1, 1 from left to right.\n * After each child performed 10^{100} moves, the number of children standing on each square is 0, 1, 2, 1, 1 from left to right.\n\n* * *"}, {"input": "RRLLLLRLRRLL", "output": "0 3 3 0 0 0 1 1 0 2 2 0\n \n\n* * *"}, {"input": "RRRLLRLLRRRLLLLL", "output": "0 0 3 2 0 2 1 0 0 0 4 4 0 0 0 0"}]
|
Print the number of children standing on each square after the children
performed the moves, in order from left to right.
* * *
|
s261941549
|
Accepted
|
p02954
|
Input is given from Standard Input in the following format:
S
|
import math
s = str(input())
def split(word):
return [char for char in word]
splice = split(s)
isrightcont = 0
isleftcont = 0
length = len(splice)
moke = list()
poke = list()
rightatsumaru = list()
leftatsumaru = list()
for i in range(0, length):
if i == length - 1:
if isleftcont == 0:
rightatsumaru.append(int(i))
leftatsumaru.append(int(i) + 1)
poke.append(isleftcont + 1)
moke.append(isrightcont)
else:
poke.append(isleftcont + 1)
moke.append(isrightcont)
elif splice[i] == "R":
if isleftcont > 0:
poke.append(isleftcont)
moke.append(isrightcont)
isleftcont = 0
isrightcont = 1
else:
isrightcont += 1
else:
if isleftcont == 0:
rightatsumaru.append(int(i))
leftatsumaru.append(int(i) + 1)
isleftcont += 1
else:
isleftcont += 1
tsumaranai = len(rightatsumaru)
gideon = [0] * length
for i in range(0, tsumaranai):
gideon[rightatsumaru[i] - 1] = math.ceil(moke[i] / 2) + math.floor(poke[i] / 2)
gideon[rightatsumaru[i]] = math.ceil(poke[i] / 2) + math.floor(moke[i] / 2)
print(*gideon)
|
Statement
Given is a string S consisting of `L` and `R`.
Let N be the length of S. There are N squares arranged from left to right, and
the i-th character of S from the left is written on the i-th square from the
left.
The character written on the leftmost square is always `R`, and the character
written on the rightmost square is always `L`.
Initially, one child is standing on each square.
Each child will perform the move below 10^{100} times:
* Move one square in the direction specified by the character written in the square on which the child is standing. `L` denotes left, and `R` denotes right.
Find the number of children standing on each square after the children
performed the moves.
|
[{"input": "RRLRL", "output": "0 1 2 1 1\n \n\n * After each child performed one move, the number of children standing on each square is 0, 2, 1, 1, 1 from left to right.\n * After each child performed two moves, the number of children standing on each square is 0, 1, 2, 1, 1 from left to right.\n * After each child performed 10^{100} moves, the number of children standing on each square is 0, 1, 2, 1, 1 from left to right.\n\n* * *"}, {"input": "RRLLLLRLRRLL", "output": "0 3 3 0 0 0 1 1 0 2 2 0\n \n\n* * *"}, {"input": "RRRLLRLLRRRLLLLL", "output": "0 0 3 2 0 2 1 0 0 0 4 4 0 0 0 0"}]
|
Print the number of children standing on each square after the children
performed the moves, in order from left to right.
* * *
|
s154964305
|
Accepted
|
p02954
|
Input is given from Standard Input in the following format:
S
|
d = [i + (c > "L" or -1) for i, c in enumerate(input())]
exec("d=[d[i]for i in d];" * 19)
a = [0] * len(d)
for i in d:
a[i] += 1
print(*a)
|
Statement
Given is a string S consisting of `L` and `R`.
Let N be the length of S. There are N squares arranged from left to right, and
the i-th character of S from the left is written on the i-th square from the
left.
The character written on the leftmost square is always `R`, and the character
written on the rightmost square is always `L`.
Initially, one child is standing on each square.
Each child will perform the move below 10^{100} times:
* Move one square in the direction specified by the character written in the square on which the child is standing. `L` denotes left, and `R` denotes right.
Find the number of children standing on each square after the children
performed the moves.
|
[{"input": "RRLRL", "output": "0 1 2 1 1\n \n\n * After each child performed one move, the number of children standing on each square is 0, 2, 1, 1, 1 from left to right.\n * After each child performed two moves, the number of children standing on each square is 0, 1, 2, 1, 1 from left to right.\n * After each child performed 10^{100} moves, the number of children standing on each square is 0, 1, 2, 1, 1 from left to right.\n\n* * *"}, {"input": "RRLLLLRLRRLL", "output": "0 3 3 0 0 0 1 1 0 2 2 0\n \n\n* * *"}, {"input": "RRRLLRLLRRRLLLLL", "output": "0 0 3 2 0 2 1 0 0 0 4 4 0 0 0 0"}]
|
Print the number of children standing on each square after the children
performed the moves, in order from left to right.
* * *
|
s343038168
|
Wrong Answer
|
p02954
|
Input is given from Standard Input in the following format:
S
|
a = input()
print(len(a))
s = []
k = a[0]
count = 1
for li in range(len(a) - 1):
i = li + 1
if k == "R" and a[i] == "R":
count = count + 1
if k == "L" and a[i] == "L":
count = count + 1
if k == "R" and a[i] == "L":
s.append(count)
count = 1
k = "L"
if k == "L" and a[i] == "R":
s.append(count)
count = 1
k = "R"
s.append(count)
print(s)
d = []
for i in range(len(s) // 2):
for k in range(s[i * 2] - 1):
d.append(0)
d.append((s[i * 2] + 1) // 2 + s[i * 2 + 1] // 2)
d.append(s[i * 2] // 2 + (s[i * 2 + 1] + 1) // 2)
for k in range(s[i * 2 + 1] - 1):
d.append(0)
print(*d)
|
Statement
Given is a string S consisting of `L` and `R`.
Let N be the length of S. There are N squares arranged from left to right, and
the i-th character of S from the left is written on the i-th square from the
left.
The character written on the leftmost square is always `R`, and the character
written on the rightmost square is always `L`.
Initially, one child is standing on each square.
Each child will perform the move below 10^{100} times:
* Move one square in the direction specified by the character written in the square on which the child is standing. `L` denotes left, and `R` denotes right.
Find the number of children standing on each square after the children
performed the moves.
|
[{"input": "RRLRL", "output": "0 1 2 1 1\n \n\n * After each child performed one move, the number of children standing on each square is 0, 2, 1, 1, 1 from left to right.\n * After each child performed two moves, the number of children standing on each square is 0, 1, 2, 1, 1 from left to right.\n * After each child performed 10^{100} moves, the number of children standing on each square is 0, 1, 2, 1, 1 from left to right.\n\n* * *"}, {"input": "RRLLLLRLRRLL", "output": "0 3 3 0 0 0 1 1 0 2 2 0\n \n\n* * *"}, {"input": "RRRLLRLLRRRLLLLL", "output": "0 0 3 2 0 2 1 0 0 0 4 4 0 0 0 0"}]
|
Print the number of children standing on each square after the children
performed the moves, in order from left to right.
* * *
|
s182589995
|
Accepted
|
p02954
|
Input is given from Standard Input in the following format:
S
|
S = input()
target = []
split = 0
for i in range(1, len(S)):
if S[i - 1] != S[i] and S[i] == "L":
continue
if S[i - 1] != S[i] and S[i] == "R":
target.append(S[split:i])
split = i
continue
target.append(S[split : len(S)])
# print(target)
result = []
for t in target:
ans = [0] * len(t)
# ans[t.count('R')-1] = (t.count('R')//2 if t.count('R')//2 !=0 else 1 ) + (t.count('L')//2 if t.count('L')//2 !=0 else 0)
# ans[t.count('R')] = (t.count('R')//2 if t.count('R') //2 !=0 else 0 )+ (t.count('L')//2 if t.count('L')//2 != 0 else 1)
# ans[t.count('R')-1] = (t.count('R')//2 ) + (t.count('L')//2 )
# print(t.count('R')//2)
# ans[t.count('R')] = (t.count('R')//2 )+ (t.count('L')//2 )
if t.count("R") == 1 and t.count("L") == 1:
ans[t.count("R") - 1] = 1
ans[t.count("R")] = 1
elif t.count("R") == 1 and t.count("L") != 1:
ans[t.count("R") - 1] = 1 + t.count("L") // 2
ans[t.count("R")] = -(-(t.count("L")) // 2)
elif t.count("R") != 1 and t.count("L") == 1:
ans[t.count("R") - 1] = -(-(t.count("R")) // 2)
ans[t.count("R")] = 1 + t.count("R") // 2
elif t.count("R") != 1 and t.count("L") != 1:
ans[t.count("R") - 1] = -(-(t.count("R")) // 2) + (t.count("L")) // 2
ans[t.count("R")] = t.count("R") // 2 + -(-(t.count("L")) // 2)
# print(ans)
result.extend(ans)
for r in result:
print(r, end=" ")
"""
for i,s in enumerate(S):
if pre == 'L':
pre = 'L'
if pre == 'R' and i !=0:
pre = 'R'
target.append(S[split:i-1])
split = i-1
print(target)
"""
|
Statement
Given is a string S consisting of `L` and `R`.
Let N be the length of S. There are N squares arranged from left to right, and
the i-th character of S from the left is written on the i-th square from the
left.
The character written on the leftmost square is always `R`, and the character
written on the rightmost square is always `L`.
Initially, one child is standing on each square.
Each child will perform the move below 10^{100} times:
* Move one square in the direction specified by the character written in the square on which the child is standing. `L` denotes left, and `R` denotes right.
Find the number of children standing on each square after the children
performed the moves.
|
[{"input": "RRLRL", "output": "0 1 2 1 1\n \n\n * After each child performed one move, the number of children standing on each square is 0, 2, 1, 1, 1 from left to right.\n * After each child performed two moves, the number of children standing on each square is 0, 1, 2, 1, 1 from left to right.\n * After each child performed 10^{100} moves, the number of children standing on each square is 0, 1, 2, 1, 1 from left to right.\n\n* * *"}, {"input": "RRLLLLRLRRLL", "output": "0 3 3 0 0 0 1 1 0 2 2 0\n \n\n* * *"}, {"input": "RRRLLRLLRRRLLLLL", "output": "0 0 3 2 0 2 1 0 0 0 4 4 0 0 0 0"}]
|
Print the number of children standing on each square after the children
performed the moves, in order from left to right.
* * *
|
s272778391
|
Accepted
|
p02954
|
Input is given from Standard Input in the following format:
S
|
S = str(input())
child_num = [1] * len(S)
for i in range(len(S) - 2):
if S[i] == "R":
if S[i + 1] == "R":
child_num[i + 2] += child_num[i]
child_num[i] = 0
for i in range(len(S) - 2):
if S[len(S) - i - 1] == "L":
if S[len(S) - i - 2] == "L":
child_num[len(S) - i - 3] += child_num[len(S) - i - 1]
child_num[len(S) - i - 1] = 0
print(*child_num)
|
Statement
Given is a string S consisting of `L` and `R`.
Let N be the length of S. There are N squares arranged from left to right, and
the i-th character of S from the left is written on the i-th square from the
left.
The character written on the leftmost square is always `R`, and the character
written on the rightmost square is always `L`.
Initially, one child is standing on each square.
Each child will perform the move below 10^{100} times:
* Move one square in the direction specified by the character written in the square on which the child is standing. `L` denotes left, and `R` denotes right.
Find the number of children standing on each square after the children
performed the moves.
|
[{"input": "RRLRL", "output": "0 1 2 1 1\n \n\n * After each child performed one move, the number of children standing on each square is 0, 2, 1, 1, 1 from left to right.\n * After each child performed two moves, the number of children standing on each square is 0, 1, 2, 1, 1 from left to right.\n * After each child performed 10^{100} moves, the number of children standing on each square is 0, 1, 2, 1, 1 from left to right.\n\n* * *"}, {"input": "RRLLLLRLRRLL", "output": "0 3 3 0 0 0 1 1 0 2 2 0\n \n\n* * *"}, {"input": "RRRLLRLLRRRLLLLL", "output": "0 0 3 2 0 2 1 0 0 0 4 4 0 0 0 0"}]
|
Print the number of children standing on each square after the children
performed the moves, in order from left to right.
* * *
|
s693399756
|
Runtime Error
|
p02954
|
Input is given from Standard Input in the following format:
S
|
# print('RRRLLRL'.index('LR'))
# print('RRRLLRLR'.index('LR'))
# =>4
# str.index(検索文字列,開始位置,終了位置)
# indexは見つからないとエラー
# findは見つからないと-1を出力
# s='RRLRLR'
# bubun=s[0:3]
# print(bubun)
# =>RRL
def stateRL(s):
state = [0] * len(s)
r = s.count("R")
l = s.count("L")
state[r - 1] = 1 + (r - 1) // 2 + l // 2
state[r] = 1 + r // 2 + (l - 1) // 2
return state
s = input()
n = len(s)
state = []
kireme = -1
nkireme = s.find("LR", 0)
while nkireme != -1:
bubun = s[kireme + 1 : nkireme + 1 :]
state += stateRL(bubun)
kireme = nkireme
nkireme = s.find("LR", kireme + 1)
bubun = s[kireme::]
state += stateRL(bubun)
for i in range(n):
print(state[i], end=" ")
|
Statement
Given is a string S consisting of `L` and `R`.
Let N be the length of S. There are N squares arranged from left to right, and
the i-th character of S from the left is written on the i-th square from the
left.
The character written on the leftmost square is always `R`, and the character
written on the rightmost square is always `L`.
Initially, one child is standing on each square.
Each child will perform the move below 10^{100} times:
* Move one square in the direction specified by the character written in the square on which the child is standing. `L` denotes left, and `R` denotes right.
Find the number of children standing on each square after the children
performed the moves.
|
[{"input": "RRLRL", "output": "0 1 2 1 1\n \n\n * After each child performed one move, the number of children standing on each square is 0, 2, 1, 1, 1 from left to right.\n * After each child performed two moves, the number of children standing on each square is 0, 1, 2, 1, 1 from left to right.\n * After each child performed 10^{100} moves, the number of children standing on each square is 0, 1, 2, 1, 1 from left to right.\n\n* * *"}, {"input": "RRLLLLRLRRLL", "output": "0 3 3 0 0 0 1 1 0 2 2 0\n \n\n* * *"}, {"input": "RRRLLRLLRRRLLLLL", "output": "0 0 3 2 0 2 1 0 0 0 4 4 0 0 0 0"}]
|
Print the number of children standing on each square after the children
performed the moves, in order from left to right.
* * *
|
s307039056
|
Wrong Answer
|
p02954
|
Input is given from Standard Input in the following format:
S
|
import glob
# 問題ごとのディレクトリのトップからの相対パス
REL_PATH = "ABC\\136\\D"
# テスト用ファイル置き場のトップ
TOP_PATH = "C:\\AtCoder"
class Common:
problem = []
index = 0
def __init__(self, rel_path):
self.rel_path = rel_path
def initialize(self, path):
file = open(path)
self.problem = file.readlines()
self.index = 0
return
def input_data(self):
try:
IS_TEST
self.index += 1
return self.problem[self.index - 1]
except NameError:
return input()
def resolve(self):
pass
def exec_resolve(self):
try:
IS_TEST
for path in glob.glob(TOP_PATH + "\\" + self.rel_path + "/*.txt"):
print("Test: " + path)
self.initialize(path)
self.resolve()
print("\n\n")
except NameError:
self.resolve()
class D(Common):
def resolve(self):
S = self.input_data()
result = [0 for i in range(len(S))]
# 左端から、スタート地点がRの人が到達する場所を探す。
# movingは探索中に右に移動している人の数。スタート地点が奇数番目なら1つ目の要素に、偶数番目なら2つ目の要素に入れる。
moving = [0, 0]
for i in range(len(S) - 1):
# 右移動が続く場合、現在の位置の人をmovingに追加。
if S[i] == "R" and S[i + 1] == "R":
if (i + 1) % 2 == 1:
moving[0] += 1
else:
moving[1] += 1
# はさまれる場所が見つかった場合はそこまでに見つかった右移動の人の数をresultに足す。
if S[i] == "R" and S[i + 1] == "L":
if (i + 1) % 2 == 1:
result[i] += moving[0] + 1
result[i + 1] += moving[1]
else:
result[i] += moving[0]
result[i + 1] += moving[1] + 1
# 見つかった右移動の人の数をクリア
moving = [0, 0]
# 逆向き。右端から、スタート地点がLの人が到達する場所を探す。
# movingは探索中に左に移動している人の数。スタート地点が奇数番目なら1つ目の要素に、偶数番目なら2つ目の要素に入れる。
moving = [0, 0]
for i in range(len(S) - 1, 0, -1):
# 左移動が続く場合、現在の位置の人をmovingに追加。
if S[i] == "L" and S[i - 1] == "L":
if i % 2 == 1:
moving[0] += 1
else:
moving[1] += 1
# はさまれる場所が見つかった場合はそこまでに見つかった左移動の人の数をresultに足す。
if S[i] == "L" and S[i - 1] == "R":
if i % 2 == 1:
result[i] += moving[0] + 1
result[i - 1] += moving[1]
else:
result[i] += moving[0]
result[i - 1] += moving[1] + 1
# 見つかった右移動の人の数をクリア
moving = [0, 0]
for i in range(len(S)):
print(str(result[i]), end=" ")
solver = D(REL_PATH)
solver.exec_resolve()
|
Statement
Given is a string S consisting of `L` and `R`.
Let N be the length of S. There are N squares arranged from left to right, and
the i-th character of S from the left is written on the i-th square from the
left.
The character written on the leftmost square is always `R`, and the character
written on the rightmost square is always `L`.
Initially, one child is standing on each square.
Each child will perform the move below 10^{100} times:
* Move one square in the direction specified by the character written in the square on which the child is standing. `L` denotes left, and `R` denotes right.
Find the number of children standing on each square after the children
performed the moves.
|
[{"input": "RRLRL", "output": "0 1 2 1 1\n \n\n * After each child performed one move, the number of children standing on each square is 0, 2, 1, 1, 1 from left to right.\n * After each child performed two moves, the number of children standing on each square is 0, 1, 2, 1, 1 from left to right.\n * After each child performed 10^{100} moves, the number of children standing on each square is 0, 1, 2, 1, 1 from left to right.\n\n* * *"}, {"input": "RRLLLLRLRRLL", "output": "0 3 3 0 0 0 1 1 0 2 2 0\n \n\n* * *"}, {"input": "RRRLLRLLRRRLLLLL", "output": "0 0 3 2 0 2 1 0 0 0 4 4 0 0 0 0"}]
|
Print the number of children standing on each square after the children
performed the moves, in order from left to right.
* * *
|
s853436615
|
Runtime Error
|
p02954
|
Input is given from Standard Input in the following format:
S
|
S = input()
list1 = list(S)
list2 = [0 for i in range(len(list1))]
t = 0 # 現在地
coutR = 0
coutL = 0
RLsindex = 0
def countLnum(t, coutL):
if t + 2 >= len(list1):
return coutL
elif list1[t + 2] == "R":
return int(coutL)
else:
coutL = countLnum(t + 1, coutL + 1)
return coutL
def RLstart(t, coutL):
list2[t] += 1
list2[t + 1] += 1 # RL部分の初期値はそのままループし続ける
if coutR % 2 == 0:
list2[t] += int(coutR / 2)
list2[t + 1] += int(coutR / 2)
else:
list2[t] += int(coutR / 2 - 0.5)
list2[t + 1] += int(coutR / 2 + 0.5)
if coutL % 2 == 0:
list2[t] += int(coutL / 2)
list2[t + 1] += int(coutL / 2)
else:
list2[t] += int(coutL / 2 + 0.5)
list2[t + 1] += int(coutL / 2 - 0.5)
while t < len(list1):
if list1[t] == "R":
if list1[t + 1] == "R":
coutR += 1
t += 1
elif list1[t + 1] == "L":
coutL = countLnum(t, 0)
RLstart(t, coutL)
t += 2 + coutL
coutR, coutL = 0, 0
s = ""
for i in range(len(list2)):
s += str(list2[i]) + " "
print(s)
|
Statement
Given is a string S consisting of `L` and `R`.
Let N be the length of S. There are N squares arranged from left to right, and
the i-th character of S from the left is written on the i-th square from the
left.
The character written on the leftmost square is always `R`, and the character
written on the rightmost square is always `L`.
Initially, one child is standing on each square.
Each child will perform the move below 10^{100} times:
* Move one square in the direction specified by the character written in the square on which the child is standing. `L` denotes left, and `R` denotes right.
Find the number of children standing on each square after the children
performed the moves.
|
[{"input": "RRLRL", "output": "0 1 2 1 1\n \n\n * After each child performed one move, the number of children standing on each square is 0, 2, 1, 1, 1 from left to right.\n * After each child performed two moves, the number of children standing on each square is 0, 1, 2, 1, 1 from left to right.\n * After each child performed 10^{100} moves, the number of children standing on each square is 0, 1, 2, 1, 1 from left to right.\n\n* * *"}, {"input": "RRLLLLRLRRLL", "output": "0 3 3 0 0 0 1 1 0 2 2 0\n \n\n* * *"}, {"input": "RRRLLRLLRRRLLLLL", "output": "0 0 3 2 0 2 1 0 0 0 4 4 0 0 0 0"}]
|
Print a solution in the following format:
N
a_1 a_2 ... a_N
Here, 2 ≤ N ≤ 50 and 0 ≤ a_i ≤ 10^{16} + 1000 must hold.
* * *
|
s696649679
|
Wrong Answer
|
p03646
|
Input is given from Standard Input in the following format:
K
|
import sys
import math
import collections
import itertools
import array
import inspect
# Set max recursion limit
sys.setrecursionlimit(1000000)
# Debug output
def chkprint(*args):
names = {id(v): k for k, v in inspect.currentframe().f_back.f_locals.items()}
print(", ".join(names.get(id(arg), "???") + " = " + repr(arg) for arg in args))
# Binary converter
def to_bin(x):
return bin(x)[2:]
def li_input():
return [int(_) for _ in input().split()]
def gcd(n, m):
if n % m == 0:
return m
else:
return gcd(m, n % m)
def gcd_list(L):
v = L[0]
for i in range(1, len(L)):
v = gcd(v, L[i])
return v
def lcm(n, m):
return (n * m) // gcd(n, m)
def lcm_list(L):
v = L[0]
for i in range(1, len(L)):
v = lcm(v, L[i])
return v
# Width First Search (+ Distance)
def wfs_d(D, N, K):
"""
D: 隣接行列(距離付き)
N: ノード数
K: 始点ノード
"""
dfk = [-1] * (N + 1)
dfk[K] = 0
cps = [(K, 0)]
r = [False] * (N + 1)
r[K] = True
while len(cps) != 0:
n_cps = []
for cp, cd in cps:
for i, dfcp in enumerate(D[cp]):
if dfcp != -1 and not r[i]:
dfk[i] = cd + dfcp
n_cps.append((i, cd + dfcp))
r[i] = True
cps = n_cps[:]
return dfk
# Depth First Search (+Distance)
def dfs_d(v, pre, dist):
"""
v: 現在のノード
pre: 1つ前のノード
dist: 現在の距離
以下は別途用意する
D: 隣接リスト(行列ではない)
D_dfs_d: dfs_d関数で用いる,始点ノードから見た距離リスト
"""
global D
global D_dfs_d
D_dfs_d[v] = dist
for next_v, d in D[v]:
if next_v != pre:
dfs_d(next_v, v, dist + d)
return
# --------------------------------------------
dp = None
def main():
e = 0.00001
K = int(input())
if K % 2 == 1:
print(2)
print(int((K * 0.5) + 2.5 + e), int((K * 0.5) - 0.5 + e))
else:
print(2)
print(int((K * 0.5) + 1 + e), int((K * 0.5) + 1 + e))
main()
|
Statement
We have a sequence of length N consisting of non-negative integers. Consider
performing the following operation on this sequence until the largest element
in this sequence becomes N-1 or smaller.
* Determine the largest element in the sequence (if there is more than one, choose one). Decrease the value of this element by N, and increase each of the other elements by 1.
It can be proved that the largest element in the sequence becomes N-1 or
smaller after a finite number of operations.
You are given an integer K. Find an integer sequence a_i such that the number
of times we will perform the above operation is exactly K. It can be shown
that there is always such a sequence under the constraints on input and output
in this problem.
|
[{"input": "0", "output": "4\n 3 3 3 3\n \n\n* * *"}, {"input": "1", "output": "3\n 1 0 3\n \n\n* * *"}, {"input": "2", "output": "2\n 2 2\n \n\nThe operation will be performed twice: [2, 2] -> [0, 3] -> [1, 1].\n\n* * *"}, {"input": "3", "output": "7\n 27 0 0 0 0 0 0\n \n\n* * *"}, {"input": "1234567894848", "output": "10\n 1000 193 256 777 0 1 1192 1234567891011 48 425"}]
|
Print a solution in the following format:
N
a_1 a_2 ... a_N
Here, 2 ≤ N ≤ 50 and 0 ≤ a_i ≤ 10^{16} + 1000 must hold.
* * *
|
s272827745
|
Wrong Answer
|
p03646
|
Input is given from Standard Input in the following format:
K
|
print("POSSIBLE")
|
Statement
We have a sequence of length N consisting of non-negative integers. Consider
performing the following operation on this sequence until the largest element
in this sequence becomes N-1 or smaller.
* Determine the largest element in the sequence (if there is more than one, choose one). Decrease the value of this element by N, and increase each of the other elements by 1.
It can be proved that the largest element in the sequence becomes N-1 or
smaller after a finite number of operations.
You are given an integer K. Find an integer sequence a_i such that the number
of times we will perform the above operation is exactly K. It can be shown
that there is always such a sequence under the constraints on input and output
in this problem.
|
[{"input": "0", "output": "4\n 3 3 3 3\n \n\n* * *"}, {"input": "1", "output": "3\n 1 0 3\n \n\n* * *"}, {"input": "2", "output": "2\n 2 2\n \n\nThe operation will be performed twice: [2, 2] -> [0, 3] -> [1, 1].\n\n* * *"}, {"input": "3", "output": "7\n 27 0 0 0 0 0 0\n \n\n* * *"}, {"input": "1234567894848", "output": "10\n 1000 193 256 777 0 1 1192 1234567891011 48 425"}]
|
Print a solution in the following format:
N
a_1 a_2 ... a_N
Here, 2 ≤ N ≤ 50 and 0 ≤ a_i ≤ 10^{16} + 1000 must hold.
* * *
|
s724626254
|
Wrong Answer
|
p03646
|
Input is given from Standard Input in the following format:
K
|
K = int(input())
N = 1000000
Q = K // N
R = K % N
print(N)
for i in range(R):
print(N - 1 + Q - R + N + 1, end=" ")
for i in range(N - R):
print(N - 1 + Q - R, end=" ")
|
Statement
We have a sequence of length N consisting of non-negative integers. Consider
performing the following operation on this sequence until the largest element
in this sequence becomes N-1 or smaller.
* Determine the largest element in the sequence (if there is more than one, choose one). Decrease the value of this element by N, and increase each of the other elements by 1.
It can be proved that the largest element in the sequence becomes N-1 or
smaller after a finite number of operations.
You are given an integer K. Find an integer sequence a_i such that the number
of times we will perform the above operation is exactly K. It can be shown
that there is always such a sequence under the constraints on input and output
in this problem.
|
[{"input": "0", "output": "4\n 3 3 3 3\n \n\n* * *"}, {"input": "1", "output": "3\n 1 0 3\n \n\n* * *"}, {"input": "2", "output": "2\n 2 2\n \n\nThe operation will be performed twice: [2, 2] -> [0, 3] -> [1, 1].\n\n* * *"}, {"input": "3", "output": "7\n 27 0 0 0 0 0 0\n \n\n* * *"}, {"input": "1234567894848", "output": "10\n 1000 193 256 777 0 1 1192 1234567891011 48 425"}]
|
Print a solution in the following format:
N
a_1 a_2 ... a_N
Here, 2 ≤ N ≤ 50 and 0 ≤ a_i ≤ 10^{16} + 1000 must hold.
* * *
|
s836046891
|
Wrong Answer
|
p03646
|
Input is given from Standard Input in the following format:
K
|
# -*- coding: utf-8 -*-
#############
# Libraries #
#############
import sys
input = sys.stdin.readline
import math
# from math import gcd
import bisect
import heapq
from collections import defaultdict
from collections import deque
from collections import Counter
from functools import lru_cache
#############
# Constants #
#############
MOD = 10**9 + 7
INF = float("inf")
AZ = "abcdefghijklmnopqrstuvwxyz"
#############
# Functions #
#############
######INPUT######
def I():
return int(input().strip())
def S():
return input().strip()
def IL():
return list(map(int, input().split()))
def SL():
return list(map(str, input().split()))
def ILs(n):
return list(int(input()) for _ in range(n))
def SLs(n):
return list(input().strip() for _ in range(n))
def ILL(n):
return [list(map(int, input().split())) for _ in range(n)]
def SLL(n):
return [list(map(str, input().split())) for _ in range(n)]
######OUTPUT######
def P(arg):
print(arg)
return
def Y():
print("Yes")
return
def N():
print("No")
return
def E():
exit()
def PE(arg):
print(arg)
exit()
def YE():
print("Yes")
exit()
def NE():
print("No")
exit()
#####Shorten#####
def DD(arg):
return defaultdict(arg)
#####Inverse#####
def inv(n):
return pow(n, MOD - 2, MOD)
######Combination######
kaijo_memo = []
def kaijo(n):
if len(kaijo_memo) > n:
return kaijo_memo[n]
if len(kaijo_memo) == 0:
kaijo_memo.append(1)
while len(kaijo_memo) <= n:
kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
return kaijo_memo[n]
gyaku_kaijo_memo = []
def gyaku_kaijo(n):
if len(gyaku_kaijo_memo) > n:
return gyaku_kaijo_memo[n]
if len(gyaku_kaijo_memo) == 0:
gyaku_kaijo_memo.append(1)
while len(gyaku_kaijo_memo) <= n:
gyaku_kaijo_memo.append(
gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo), MOD - 2, MOD) % MOD
)
return gyaku_kaijo_memo[n]
def nCr(n, r):
if n == r:
return 1
if n < r or r < 0:
return 0
ret = 1
ret = ret * kaijo(n) % MOD
ret = ret * gyaku_kaijo(r) % MOD
ret = ret * gyaku_kaijo(n - r) % MOD
return ret
######Factorization######
def factorization(n):
arr = []
temp = n
for i in range(2, int(-(-(n**0.5) // 1)) + 1):
if temp % i == 0:
cnt = 0
while temp % i == 0:
cnt += 1
temp //= i
arr.append([i, cnt])
if temp != 1:
arr.append([temp, 1])
if arr == []:
arr.append([n, 1])
return arr
#####MakeDivisors######
def make_divisors(n):
divisors = []
for i in range(1, int(n**0.5) + 1):
if n % i == 0:
divisors.append(i)
if i != n // i:
divisors.append(n // i)
return divisors
#####MakePrimes######
def make_primes(N):
max = int(math.sqrt(N))
seachList = [i for i in range(2, N + 1)]
primeNum = []
while seachList[0] <= max:
primeNum.append(seachList[0])
tmp = seachList[0]
seachList = [i for i in seachList if i % tmp != 0]
primeNum.extend(seachList)
return primeNum
#####GCD#####
def gcd(a, b):
while b:
a, b = b, a % b
return a
#####LCM#####
def lcm(a, b):
return a * b // gcd(a, b)
#####BitCount#####
def count_bit(n):
count = 0
while n:
n &= n - 1
count += 1
return count
#####ChangeBase#####
def base_10_to_n(X, n):
if X // n:
return base_10_to_n(X // n, n) + [X % n]
return [X % n]
def base_n_to_10(X, n):
return sum(int(str(X)[-i - 1]) * n**i for i in range(len(str(X))))
def base_10_to_n_without_0(X, n):
X -= 1
if X // n:
return base_10_to_n_without_0(X // n, n) + [X % n]
return [X % n]
#####IntLog#####
def int_log(n, a):
count = 0
while n >= a:
n //= a
count += 1
return count
#############
# Main Code #
#############
K = I()
if K % 2 == 0:
print(1 + K // 2, 1 + K // 2)
else:
print(1 + K // 2 - 1, 1 + K // 2 + 2)
|
Statement
We have a sequence of length N consisting of non-negative integers. Consider
performing the following operation on this sequence until the largest element
in this sequence becomes N-1 or smaller.
* Determine the largest element in the sequence (if there is more than one, choose one). Decrease the value of this element by N, and increase each of the other elements by 1.
It can be proved that the largest element in the sequence becomes N-1 or
smaller after a finite number of operations.
You are given an integer K. Find an integer sequence a_i such that the number
of times we will perform the above operation is exactly K. It can be shown
that there is always such a sequence under the constraints on input and output
in this problem.
|
[{"input": "0", "output": "4\n 3 3 3 3\n \n\n* * *"}, {"input": "1", "output": "3\n 1 0 3\n \n\n* * *"}, {"input": "2", "output": "2\n 2 2\n \n\nThe operation will be performed twice: [2, 2] -> [0, 3] -> [1, 1].\n\n* * *"}, {"input": "3", "output": "7\n 27 0 0 0 0 0 0\n \n\n* * *"}, {"input": "1234567894848", "output": "10\n 1000 193 256 777 0 1 1192 1234567891011 48 425"}]
|
Print a solution in the following format:
N
a_1 a_2 ... a_N
Here, 2 ≤ N ≤ 50 and 0 ≤ a_i ≤ 10^{16} + 1000 must hold.
* * *
|
s267187248
|
Accepted
|
p03646
|
Input is given from Standard Input in the following format:
K
|
k = int(input())
shou = k // 50
amari = k % 50
a = str(49 - k + shou * 51)
b = str(100 - k + shou * 51)
n = []
for i in range(amari):
n.append(b)
for i in range(50 - amari):
n.append(a)
print("50")
nstr = " ".join(n)
print(nstr)
|
Statement
We have a sequence of length N consisting of non-negative integers. Consider
performing the following operation on this sequence until the largest element
in this sequence becomes N-1 or smaller.
* Determine the largest element in the sequence (if there is more than one, choose one). Decrease the value of this element by N, and increase each of the other elements by 1.
It can be proved that the largest element in the sequence becomes N-1 or
smaller after a finite number of operations.
You are given an integer K. Find an integer sequence a_i such that the number
of times we will perform the above operation is exactly K. It can be shown
that there is always such a sequence under the constraints on input and output
in this problem.
|
[{"input": "0", "output": "4\n 3 3 3 3\n \n\n* * *"}, {"input": "1", "output": "3\n 1 0 3\n \n\n* * *"}, {"input": "2", "output": "2\n 2 2\n \n\nThe operation will be performed twice: [2, 2] -> [0, 3] -> [1, 1].\n\n* * *"}, {"input": "3", "output": "7\n 27 0 0 0 0 0 0\n \n\n* * *"}, {"input": "1234567894848", "output": "10\n 1000 193 256 777 0 1 1192 1234567891011 48 425"}]
|
Print a solution in the following format:
N
a_1 a_2 ... a_N
Here, 2 ≤ N ≤ 50 and 0 ≤ a_i ≤ 10^{16} + 1000 must hold.
* * *
|
s465226418
|
Runtime Error
|
p03646
|
Input is given from Standard Input in the following format:
K
|
K = int(input())
f1 = 1
for n in range(2, 51):
if K % n == 0:
f1 = n
f2 = K // f1
a = f1 + f2 - 1
ans = [a - i for i in range(f1)]
print (f1)
print (" ".join([str(v) for v in ans]) if K != 1 else [1, 0, 3])
|
Statement
We have a sequence of length N consisting of non-negative integers. Consider
performing the following operation on this sequence until the largest element
in this sequence becomes N-1 or smaller.
* Determine the largest element in the sequence (if there is more than one, choose one). Decrease the value of this element by N, and increase each of the other elements by 1.
It can be proved that the largest element in the sequence becomes N-1 or
smaller after a finite number of operations.
You are given an integer K. Find an integer sequence a_i such that the number
of times we will perform the above operation is exactly K. It can be shown
that there is always such a sequence under the constraints on input and output
in this problem.
|
[{"input": "0", "output": "4\n 3 3 3 3\n \n\n* * *"}, {"input": "1", "output": "3\n 1 0 3\n \n\n* * *"}, {"input": "2", "output": "2\n 2 2\n \n\nThe operation will be performed twice: [2, 2] -> [0, 3] -> [1, 1].\n\n* * *"}, {"input": "3", "output": "7\n 27 0 0 0 0 0 0\n \n\n* * *"}, {"input": "1234567894848", "output": "10\n 1000 193 256 777 0 1 1192 1234567891011 48 425"}]
|
Print a solution in the following format:
N
a_1 a_2 ... a_N
Here, 2 ≤ N ≤ 50 and 0 ≤ a_i ≤ 10^{16} + 1000 must hold.
* * *
|
s440712133
|
Runtime Error
|
p03646
|
Input is given from Standard Input in the following format:
K
|
import sys,bisect as bs
sys.setrecursionlimit(100000)
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
return list(map(int,input().split()))
def m(): #複数文字
return map(int,input().split())
def onem(): #Nとかの取得
return int(input())
def s(x): #圧縮
a = []
aa = x[0]
su = 1
for i in range(len(x)-1):
if aa != x[i+1]:
a.append([aa,su])
aa = x[i+1]
su = 1
else:
su += 1
a.append([aa,su])
return a
def jo(x): #listをスペースごとに分ける
return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
return max(map(max,x))
def In(x,a): #aがリスト(sorted)
k = bs.bisect_left(a,x)
if k != len(a) and a[k] == x:
return True
else:
return False
n = onem()
print(10**5)
a = [i + n//(10**5) for i in range(10**5)]
for i in range(10**5-1):
if i+1 <= n%(10**5):
a[i] += 10**5 - n%(10**5) + 1:
else:
a[i] -= n%(10**5)
print(jo(a))
|
Statement
We have a sequence of length N consisting of non-negative integers. Consider
performing the following operation on this sequence until the largest element
in this sequence becomes N-1 or smaller.
* Determine the largest element in the sequence (if there is more than one, choose one). Decrease the value of this element by N, and increase each of the other elements by 1.
It can be proved that the largest element in the sequence becomes N-1 or
smaller after a finite number of operations.
You are given an integer K. Find an integer sequence a_i such that the number
of times we will perform the above operation is exactly K. It can be shown
that there is always such a sequence under the constraints on input and output
in this problem.
|
[{"input": "0", "output": "4\n 3 3 3 3\n \n\n* * *"}, {"input": "1", "output": "3\n 1 0 3\n \n\n* * *"}, {"input": "2", "output": "2\n 2 2\n \n\nThe operation will be performed twice: [2, 2] -> [0, 3] -> [1, 1].\n\n* * *"}, {"input": "3", "output": "7\n 27 0 0 0 0 0 0\n \n\n* * *"}, {"input": "1234567894848", "output": "10\n 1000 193 256 777 0 1 1192 1234567891011 48 425"}]
|
Print a solution in the following format:
N
a_1 a_2 ... a_N
Here, 2 ≤ N ≤ 50 and 0 ≤ a_i ≤ 10^{16} + 1000 must hold.
* * *
|
s051327798
|
Runtime Error
|
p03646
|
Input is given from Standard Input in the following format:
K
|
import sys,bisect as bs
sys.setrecursionlimit(100000)
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
return list(map(int,input().split()))
def m(): #複数文字
return map(int,input().split())
def onem(): #Nとかの取得
return int(input())
def s(x): #圧縮
a = []
aa = x[0]
su = 1
for i in range(len(x)-1):
if aa != x[i+1]:
a.append([aa,su])
aa = x[i+1]
su = 1
else:
su += 1
a.append([aa,su])
return a
def jo(x): #listをスペースごとに分ける
return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
return max(map(max,x))
def In(x,a): #aがリスト(sorted)
k = bs.bisect_left(a,x)
if k != len(a) and a[k] == x:
return True
else:
return False
n = onem()
print(10**5)
a = [i + n//(10**5) for i in range(10**5)]
for i in range(10**5-1):
if i+1 <= n%(10**5):
a[i] += N - n%(10**5) + 1:
else:
a[i] -= n%(10**5)
print(jo(a))
|
Statement
We have a sequence of length N consisting of non-negative integers. Consider
performing the following operation on this sequence until the largest element
in this sequence becomes N-1 or smaller.
* Determine the largest element in the sequence (if there is more than one, choose one). Decrease the value of this element by N, and increase each of the other elements by 1.
It can be proved that the largest element in the sequence becomes N-1 or
smaller after a finite number of operations.
You are given an integer K. Find an integer sequence a_i such that the number
of times we will perform the above operation is exactly K. It can be shown
that there is always such a sequence under the constraints on input and output
in this problem.
|
[{"input": "0", "output": "4\n 3 3 3 3\n \n\n* * *"}, {"input": "1", "output": "3\n 1 0 3\n \n\n* * *"}, {"input": "2", "output": "2\n 2 2\n \n\nThe operation will be performed twice: [2, 2] -> [0, 3] -> [1, 1].\n\n* * *"}, {"input": "3", "output": "7\n 27 0 0 0 0 0 0\n \n\n* * *"}, {"input": "1234567894848", "output": "10\n 1000 193 256 777 0 1 1192 1234567891011 48 425"}]
|
Print Q lines. The i-th line should contain the k_i-DMC number of the string
S.
* * *
|
s026062911
|
Accepted
|
p03216
|
Input is given from Standard Input in the following format:
N
S
Q
k_{0} k_{1} ... k_{Q-1}
|
import sys
readline = sys.stdin.readline
MOD = 10**9 + 7
INF = float("INF")
sys.setrecursionlimit(10**5)
def main():
N = int(readline())
S = input()
Q = int(readline())
K = list(map(int, readline().split()))
for q in range(Q):
k = K[q]
res = 0
cnt = [0] * 3
for i in range(k):
cur = S[i]
if cur == "D":
cnt[0] += 1
elif cur == "M":
cnt[1] += 1
cnt[2] += cnt[0]
elif cur == "C":
res += cnt[2]
for i in range(k, N):
prev = S[i - k]
cur = S[i]
if prev == "D":
cnt[0] -= 1
cnt[2] -= cnt[1]
elif prev == "M":
cnt[1] -= 1
if cur == "D":
cnt[0] += 1
elif cur == "M":
cnt[1] += 1
cnt[2] += cnt[0]
elif cur == "C":
res += cnt[2]
print(res)
if __name__ == "__main__":
main()
|
Statement
In Dwango Co., Ltd., there is a content distribution system named 'Dwango
Media Cluster', and it is called 'DMC' for short.
The name 'DMC' sounds cool for Niwango-kun, so he starts to define DMC-ness of
a string.
Given a string S of length N and an integer k (k \geq 3), he defines the _k
-DMC number_ of S as the number of triples (a, b, c) of integers that satisfy
the following conditions:
* 0 \leq a < b < c \leq N - 1
* S[a] = `D`
* S[b] = `M`
* S[c] = `C`
* c-a < k
Here S[a] is the a-th character of the string S. Indexing is zero-based, that
is, 0 \leq a \leq N - 1 holds.
For a string S and Q integers k_0, k_1, ..., k_{Q-1}, calculate the k_i-DMC
number of S for each i (0 \leq i \leq Q-1).
|
[{"input": "18\n DWANGOMEDIACLUSTER\n 1\n 18", "output": "1\n \n\n(a,b,c) = (0, 6, 11) satisfies the conditions. \nStrangely, Dwango Media Cluster does not have so much DMC-ness by his\ndefinition.\n\n* * *"}, {"input": "18\n DDDDDDMMMMMCCCCCCC\n 1\n 18", "output": "210\n \n\nThe number of triples can be calculated as 6\\times 5\\times 7.\n\n* * *"}, {"input": "54\n DIALUPWIDEAREANETWORKGAMINGOPERATIONCORPORATIONLIMITED\n 3\n 20 30 40", "output": "0\n 1\n 2\n \n\n(a, b, c) = (0, 23, 36), (8, 23, 36) satisfy the conditions except the last\none, namely, c-a < k_i. \nBy the way, DWANGO is an acronym for \"Dial-up Wide Area Network Gaming\nOperation\".\n\n* * *"}]
|
Print Q lines. The i-th line should contain the k_i-DMC number of the string
S.
* * *
|
s460214262
|
Accepted
|
p03216
|
Input is given from Standard Input in the following format:
N
S
Q
k_{0} k_{1} ... k_{Q-1}
|
# from collections import deque,defaultdict
printn = lambda x: print(x, end="")
inn = lambda: int(input())
inl = lambda: list(map(int, input().split()))
inm = lambda: map(int, input().split())
ins = lambda: input().strip()
DBG = True # and False
BIG = 10**18
R = 10**9 + 7
def ddprint(x):
if DBG:
print(x)
n = inn()
s = ins()
q = inn()
kl = inl()
accd = [0] * (n + 1)
accm = [0] * (n + 1)
for i in range(n):
accd[i] = accd[i - 1] + (1 if s[i] == "D" else 0)
accm[i] = accm[i - 1] + (1 if s[i] == "M" else 0)
# ddprint(accd)
# ddprint(accm)
for k in kl:
# ddprint(k)
dm = 0
dmc = 0
for i in range(1, n):
if i >= k and s[i - k] == "D":
dm -= accm[i - 1] - accm[i - k]
if s[i] == "M":
dm += accd[i - 1] - accd[max(-1, i - k)]
if s[i] == "C":
dmc += dm
# ddprint(f"{i=} {dm=} {dmc=}")
print(dmc)
|
Statement
In Dwango Co., Ltd., there is a content distribution system named 'Dwango
Media Cluster', and it is called 'DMC' for short.
The name 'DMC' sounds cool for Niwango-kun, so he starts to define DMC-ness of
a string.
Given a string S of length N and an integer k (k \geq 3), he defines the _k
-DMC number_ of S as the number of triples (a, b, c) of integers that satisfy
the following conditions:
* 0 \leq a < b < c \leq N - 1
* S[a] = `D`
* S[b] = `M`
* S[c] = `C`
* c-a < k
Here S[a] is the a-th character of the string S. Indexing is zero-based, that
is, 0 \leq a \leq N - 1 holds.
For a string S and Q integers k_0, k_1, ..., k_{Q-1}, calculate the k_i-DMC
number of S for each i (0 \leq i \leq Q-1).
|
[{"input": "18\n DWANGOMEDIACLUSTER\n 1\n 18", "output": "1\n \n\n(a,b,c) = (0, 6, 11) satisfies the conditions. \nStrangely, Dwango Media Cluster does not have so much DMC-ness by his\ndefinition.\n\n* * *"}, {"input": "18\n DDDDDDMMMMMCCCCCCC\n 1\n 18", "output": "210\n \n\nThe number of triples can be calculated as 6\\times 5\\times 7.\n\n* * *"}, {"input": "54\n DIALUPWIDEAREANETWORKGAMINGOPERATIONCORPORATIONLIMITED\n 3\n 20 30 40", "output": "0\n 1\n 2\n \n\n(a, b, c) = (0, 23, 36), (8, 23, 36) satisfy the conditions except the last\none, namely, c-a < k_i. \nBy the way, DWANGO is an acronym for \"Dial-up Wide Area Network Gaming\nOperation\".\n\n* * *"}]
|
Print Q lines. The i-th line should contain the k_i-DMC number of the string
S.
* * *
|
s968592150
|
Accepted
|
p03216
|
Input is given from Standard Input in the following format:
N
S
Q
k_{0} k_{1} ... k_{Q-1}
|
n = int(input()) + 1
s = "?" + input()
q = int(input())
k = list(map(int, input().split()))
p_d = []
cnt_m = [0] * n
cnt_c = [0] * n
for i, si in enumerate(s[1:], 1):
cnt_m[i] = cnt_m[i - 1]
cnt_c[i] = cnt_c[i - 1]
if si == "D":
p_d.append(i)
elif si == "M":
cnt_m[i] += 1
elif si == "C":
cnt_c[i] += 1
left_c = [0] * n
for i in range(1, n):
left_c[i] = left_c[i - 1]
if s[i] == "M":
left_c[i] += cnt_c[i]
# print(cnt_m)
# print(cnt_c)
# print(left_c)
ans = []
for ki in k:
tmp = 0
for di in p_d:
x = cnt_m[min(di + ki - 1, n - 1)] - cnt_m[di - 1]
y = cnt_c[min(di + ki - 1, n - 1)]
tmp += x * y - left_c[min(di + ki - 1, n - 1)] + left_c[di - 1]
ans.append(tmp)
print("\n".join(map(str, ans)))
|
Statement
In Dwango Co., Ltd., there is a content distribution system named 'Dwango
Media Cluster', and it is called 'DMC' for short.
The name 'DMC' sounds cool for Niwango-kun, so he starts to define DMC-ness of
a string.
Given a string S of length N and an integer k (k \geq 3), he defines the _k
-DMC number_ of S as the number of triples (a, b, c) of integers that satisfy
the following conditions:
* 0 \leq a < b < c \leq N - 1
* S[a] = `D`
* S[b] = `M`
* S[c] = `C`
* c-a < k
Here S[a] is the a-th character of the string S. Indexing is zero-based, that
is, 0 \leq a \leq N - 1 holds.
For a string S and Q integers k_0, k_1, ..., k_{Q-1}, calculate the k_i-DMC
number of S for each i (0 \leq i \leq Q-1).
|
[{"input": "18\n DWANGOMEDIACLUSTER\n 1\n 18", "output": "1\n \n\n(a,b,c) = (0, 6, 11) satisfies the conditions. \nStrangely, Dwango Media Cluster does not have so much DMC-ness by his\ndefinition.\n\n* * *"}, {"input": "18\n DDDDDDMMMMMCCCCCCC\n 1\n 18", "output": "210\n \n\nThe number of triples can be calculated as 6\\times 5\\times 7.\n\n* * *"}, {"input": "54\n DIALUPWIDEAREANETWORKGAMINGOPERATIONCORPORATIONLIMITED\n 3\n 20 30 40", "output": "0\n 1\n 2\n \n\n(a, b, c) = (0, 23, 36), (8, 23, 36) satisfy the conditions except the last\none, namely, c-a < k_i. \nBy the way, DWANGO is an acronym for \"Dial-up Wide Area Network Gaming\nOperation\".\n\n* * *"}]
|
Print Q lines. The i-th line should contain the k_i-DMC number of the string
S.
* * *
|
s115280518
|
Runtime Error
|
p03216
|
Input is given from Standard Input in the following format:
N
S
Q
k_{0} k_{1} ... k_{Q-1}
|
N=int(input())
S=input()
Q=int(input())
K=[int(i) for i in input().split()
def f(k):
num=0
L=[0,0,0]
for i in range(N):
if i-k>=0:
if S[i-k]=='D':
L[0]-=1
L[2]-=L[1]
elif S[i-k]=='M':
L[1]-=1
if S[i]=='D':
L[0]+=1
elif S[i]=='M':
L[1]+=1
L[2]+=L[0]
elif S[i]=='C':
num+=L[2]
#print(i,':',L,':',num)
return num
for k in K:
print(f(k))
|
Statement
In Dwango Co., Ltd., there is a content distribution system named 'Dwango
Media Cluster', and it is called 'DMC' for short.
The name 'DMC' sounds cool for Niwango-kun, so he starts to define DMC-ness of
a string.
Given a string S of length N and an integer k (k \geq 3), he defines the _k
-DMC number_ of S as the number of triples (a, b, c) of integers that satisfy
the following conditions:
* 0 \leq a < b < c \leq N - 1
* S[a] = `D`
* S[b] = `M`
* S[c] = `C`
* c-a < k
Here S[a] is the a-th character of the string S. Indexing is zero-based, that
is, 0 \leq a \leq N - 1 holds.
For a string S and Q integers k_0, k_1, ..., k_{Q-1}, calculate the k_i-DMC
number of S for each i (0 \leq i \leq Q-1).
|
[{"input": "18\n DWANGOMEDIACLUSTER\n 1\n 18", "output": "1\n \n\n(a,b,c) = (0, 6, 11) satisfies the conditions. \nStrangely, Dwango Media Cluster does not have so much DMC-ness by his\ndefinition.\n\n* * *"}, {"input": "18\n DDDDDDMMMMMCCCCCCC\n 1\n 18", "output": "210\n \n\nThe number of triples can be calculated as 6\\times 5\\times 7.\n\n* * *"}, {"input": "54\n DIALUPWIDEAREANETWORKGAMINGOPERATIONCORPORATIONLIMITED\n 3\n 20 30 40", "output": "0\n 1\n 2\n \n\n(a, b, c) = (0, 23, 36), (8, 23, 36) satisfy the conditions except the last\none, namely, c-a < k_i. \nBy the way, DWANGO is an acronym for \"Dial-up Wide Area Network Gaming\nOperation\".\n\n* * *"}]
|
Print Q lines. The i-th line should contain the k_i-DMC number of the string
S.
* * *
|
s138097674
|
Wrong Answer
|
p03216
|
Input is given from Standard Input in the following format:
N
S
Q
k_{0} k_{1} ... k_{Q-1}
|
N = int(input())
S = input()
Q = int(input())
kL = list(map(int, input().split()))
ans = []
cnt = 0
for k in kL:
if cnt > 0:
break
Dcnt = 0
Mcnt = 0
DMcnt = 0
DMCcnt = 0
for i in range(len(S)):
if i - k >= 0 and S[i - k] == "D":
Dcnt -= 1
DMcnt -= Mcnt
elif i - k >= 0 and S[i - k] == "M":
Mcnt -= 1
if S[i] == "D":
Dcnt += 1
elif S[i] == "M":
Mcnt += 1
DMcnt += Dcnt
elif S[i] == "C":
DMCcnt += DMcnt
ans.append(DMCcnt)
cnt += 1
for a in ans:
print(a)
|
Statement
In Dwango Co., Ltd., there is a content distribution system named 'Dwango
Media Cluster', and it is called 'DMC' for short.
The name 'DMC' sounds cool for Niwango-kun, so he starts to define DMC-ness of
a string.
Given a string S of length N and an integer k (k \geq 3), he defines the _k
-DMC number_ of S as the number of triples (a, b, c) of integers that satisfy
the following conditions:
* 0 \leq a < b < c \leq N - 1
* S[a] = `D`
* S[b] = `M`
* S[c] = `C`
* c-a < k
Here S[a] is the a-th character of the string S. Indexing is zero-based, that
is, 0 \leq a \leq N - 1 holds.
For a string S and Q integers k_0, k_1, ..., k_{Q-1}, calculate the k_i-DMC
number of S for each i (0 \leq i \leq Q-1).
|
[{"input": "18\n DWANGOMEDIACLUSTER\n 1\n 18", "output": "1\n \n\n(a,b,c) = (0, 6, 11) satisfies the conditions. \nStrangely, Dwango Media Cluster does not have so much DMC-ness by his\ndefinition.\n\n* * *"}, {"input": "18\n DDDDDDMMMMMCCCCCCC\n 1\n 18", "output": "210\n \n\nThe number of triples can be calculated as 6\\times 5\\times 7.\n\n* * *"}, {"input": "54\n DIALUPWIDEAREANETWORKGAMINGOPERATIONCORPORATIONLIMITED\n 3\n 20 30 40", "output": "0\n 1\n 2\n \n\n(a, b, c) = (0, 23, 36), (8, 23, 36) satisfy the conditions except the last\none, namely, c-a < k_i. \nBy the way, DWANGO is an acronym for \"Dial-up Wide Area Network Gaming\nOperation\".\n\n* * *"}]
|
Print Q lines. The i-th line should contain the k_i-DMC number of the string
S.
* * *
|
s542069419
|
Wrong Answer
|
p03216
|
Input is given from Standard Input in the following format:
N
S
Q
k_{0} k_{1} ... k_{Q-1}
|
import re
n = int(input())
s = input()
q = int(input())
k = list(map(int, input().split()))
s = re.sub("[ABEFGHIJKLNOPQRSTUVWXYZ]", "", s)
|
Statement
In Dwango Co., Ltd., there is a content distribution system named 'Dwango
Media Cluster', and it is called 'DMC' for short.
The name 'DMC' sounds cool for Niwango-kun, so he starts to define DMC-ness of
a string.
Given a string S of length N and an integer k (k \geq 3), he defines the _k
-DMC number_ of S as the number of triples (a, b, c) of integers that satisfy
the following conditions:
* 0 \leq a < b < c \leq N - 1
* S[a] = `D`
* S[b] = `M`
* S[c] = `C`
* c-a < k
Here S[a] is the a-th character of the string S. Indexing is zero-based, that
is, 0 \leq a \leq N - 1 holds.
For a string S and Q integers k_0, k_1, ..., k_{Q-1}, calculate the k_i-DMC
number of S for each i (0 \leq i \leq Q-1).
|
[{"input": "18\n DWANGOMEDIACLUSTER\n 1\n 18", "output": "1\n \n\n(a,b,c) = (0, 6, 11) satisfies the conditions. \nStrangely, Dwango Media Cluster does not have so much DMC-ness by his\ndefinition.\n\n* * *"}, {"input": "18\n DDDDDDMMMMMCCCCCCC\n 1\n 18", "output": "210\n \n\nThe number of triples can be calculated as 6\\times 5\\times 7.\n\n* * *"}, {"input": "54\n DIALUPWIDEAREANETWORKGAMINGOPERATIONCORPORATIONLIMITED\n 3\n 20 30 40", "output": "0\n 1\n 2\n \n\n(a, b, c) = (0, 23, 36), (8, 23, 36) satisfy the conditions except the last\none, namely, c-a < k_i. \nBy the way, DWANGO is an acronym for \"Dial-up Wide Area Network Gaming\nOperation\".\n\n* * *"}]
|
Print Q lines. The i-th line should contain the k_i-DMC number of the string
S.
* * *
|
s021932498
|
Runtime Error
|
p03216
|
Input is given from Standard Input in the following format:
N
S
Q
k_{0} k_{1} ... k_{Q-1}
|
n, k = list(map(int, input().split(" ")))
a = list(map(int, input().split(" ")))
b = []
for i in range(n):
for j in range(i, n, 1):
b.append(sum(a[i : j + 1]))
b.sort(reverse=True)
ans = 0
for i in range(int(n * (n + 1) / 2) - k + 1):
tmp = b[i]
for j in b[i:k]:
tmp = tmp & j
if ans < tmp:
ans = tmp
print(ans)
|
Statement
In Dwango Co., Ltd., there is a content distribution system named 'Dwango
Media Cluster', and it is called 'DMC' for short.
The name 'DMC' sounds cool for Niwango-kun, so he starts to define DMC-ness of
a string.
Given a string S of length N and an integer k (k \geq 3), he defines the _k
-DMC number_ of S as the number of triples (a, b, c) of integers that satisfy
the following conditions:
* 0 \leq a < b < c \leq N - 1
* S[a] = `D`
* S[b] = `M`
* S[c] = `C`
* c-a < k
Here S[a] is the a-th character of the string S. Indexing is zero-based, that
is, 0 \leq a \leq N - 1 holds.
For a string S and Q integers k_0, k_1, ..., k_{Q-1}, calculate the k_i-DMC
number of S for each i (0 \leq i \leq Q-1).
|
[{"input": "18\n DWANGOMEDIACLUSTER\n 1\n 18", "output": "1\n \n\n(a,b,c) = (0, 6, 11) satisfies the conditions. \nStrangely, Dwango Media Cluster does not have so much DMC-ness by his\ndefinition.\n\n* * *"}, {"input": "18\n DDDDDDMMMMMCCCCCCC\n 1\n 18", "output": "210\n \n\nThe number of triples can be calculated as 6\\times 5\\times 7.\n\n* * *"}, {"input": "54\n DIALUPWIDEAREANETWORKGAMINGOPERATIONCORPORATIONLIMITED\n 3\n 20 30 40", "output": "0\n 1\n 2\n \n\n(a, b, c) = (0, 23, 36), (8, 23, 36) satisfy the conditions except the last\none, namely, c-a < k_i. \nBy the way, DWANGO is an acronym for \"Dial-up Wide Area Network Gaming\nOperation\".\n\n* * *"}]
|
Print Q lines. The i-th line should contain the k_i-DMC number of the string
S.
* * *
|
s571537202
|
Wrong Answer
|
p03216
|
Input is given from Standard Input in the following format:
N
S
Q
k_{0} k_{1} ... k_{Q-1}
|
n = int(input())
s = input()
q = int(input())
k = [int(m) for m in input().split()]
dmc = []
dc = 0
for i in range(n):
if s[i] == "D" or s[i] == "M" or s[i] == "C":
dmc.append([s[i], i])
if s[i] == "D":
dc += 1
d = []
m = []
rm = []
c = []
for h in range(dc):
m.append(0)
rm.append(0)
c.append(0)
for i in range(q):
for j in range(len(dmc)):
if dmc[j][0] == "D":
d.append(dmc[j][1])
if dmc[j][0] == "M":
for v in range(len(d)):
if dmc[j][1] - d[v] < k[i]:
rm[v] += 1
if dmc[j][0] == "C":
for v in range(len(d)):
if dmc[j][1] - d[v] < k[i]:
c[v] += 1
m[v] = rm[v]
combined1 = [x * y for (x, y) in zip(m, c)]
print(sum(combined1))
d = []
m = []
rm = []
c = []
for h in range(dc):
m.append(0)
rm.append(0)
c.append(0)
|
Statement
In Dwango Co., Ltd., there is a content distribution system named 'Dwango
Media Cluster', and it is called 'DMC' for short.
The name 'DMC' sounds cool for Niwango-kun, so he starts to define DMC-ness of
a string.
Given a string S of length N and an integer k (k \geq 3), he defines the _k
-DMC number_ of S as the number of triples (a, b, c) of integers that satisfy
the following conditions:
* 0 \leq a < b < c \leq N - 1
* S[a] = `D`
* S[b] = `M`
* S[c] = `C`
* c-a < k
Here S[a] is the a-th character of the string S. Indexing is zero-based, that
is, 0 \leq a \leq N - 1 holds.
For a string S and Q integers k_0, k_1, ..., k_{Q-1}, calculate the k_i-DMC
number of S for each i (0 \leq i \leq Q-1).
|
[{"input": "18\n DWANGOMEDIACLUSTER\n 1\n 18", "output": "1\n \n\n(a,b,c) = (0, 6, 11) satisfies the conditions. \nStrangely, Dwango Media Cluster does not have so much DMC-ness by his\ndefinition.\n\n* * *"}, {"input": "18\n DDDDDDMMMMMCCCCCCC\n 1\n 18", "output": "210\n \n\nThe number of triples can be calculated as 6\\times 5\\times 7.\n\n* * *"}, {"input": "54\n DIALUPWIDEAREANETWORKGAMINGOPERATIONCORPORATIONLIMITED\n 3\n 20 30 40", "output": "0\n 1\n 2\n \n\n(a, b, c) = (0, 23, 36), (8, 23, 36) satisfy the conditions except the last\none, namely, c-a < k_i. \nBy the way, DWANGO is an acronym for \"Dial-up Wide Area Network Gaming\nOperation\".\n\n* * *"}]
|
Print the necessary number of candies in total.
* * *
|
s817396442
|
Runtime Error
|
p04029
|
The input is given from Standard Input in the following format:
N
|
N = int(input())
ans = 0
for(i = 1; i <= N; i++):
ans +=1
print(i)
|
Statement
There are N children in AtCoder Kindergarten. Mr. Evi will arrange the
children in a line, then give 1 candy to the first child in the line, 2
candies to the second child, ..., N candies to the N-th child. How many
candies will be necessary in total?
|
[{"input": "3", "output": "6\n \n\nThe answer is 1+2+3=6.\n\n* * *"}, {"input": "10", "output": "55\n \n\nThe sum of the integers from 1 to 10 is 55.\n\n* * *"}, {"input": "1", "output": "1\n \n\nOnly one child. The answer is 1 in this case."}]
|
Print the necessary number of candies in total.
* * *
|
s020385401
|
Accepted
|
p04029
|
The input is given from Standard Input in the following format:
N
|
inp = int(input())
print(int(inp * (inp + 1) / 2))
|
Statement
There are N children in AtCoder Kindergarten. Mr. Evi will arrange the
children in a line, then give 1 candy to the first child in the line, 2
candies to the second child, ..., N candies to the N-th child. How many
candies will be necessary in total?
|
[{"input": "3", "output": "6\n \n\nThe answer is 1+2+3=6.\n\n* * *"}, {"input": "10", "output": "55\n \n\nThe sum of the integers from 1 to 10 is 55.\n\n* * *"}, {"input": "1", "output": "1\n \n\nOnly one child. The answer is 1 in this case."}]
|
Print the necessary number of candies in total.
* * *
|
s157988179
|
Runtime Error
|
p04029
|
The input is given from Standard Input in the following format:
N
|
val1=int(input())
print(val1*(val1+1)/)
|
Statement
There are N children in AtCoder Kindergarten. Mr. Evi will arrange the
children in a line, then give 1 candy to the first child in the line, 2
candies to the second child, ..., N candies to the N-th child. How many
candies will be necessary in total?
|
[{"input": "3", "output": "6\n \n\nThe answer is 1+2+3=6.\n\n* * *"}, {"input": "10", "output": "55\n \n\nThe sum of the integers from 1 to 10 is 55.\n\n* * *"}, {"input": "1", "output": "1\n \n\nOnly one child. The answer is 1 in this case."}]
|
Print the necessary number of candies in total.
* * *
|
s634333823
|
Accepted
|
p04029
|
The input is given from Standard Input in the following format:
N
|
import sys
import heapq, math
from itertools import (
zip_longest,
permutations,
combinations,
combinations_with_replacement,
)
from itertools import accumulate, dropwhile, takewhile, groupby
from functools import lru_cache
from copy import deepcopy
N = int(input())
print(N * (N + 1) // 2)
|
Statement
There are N children in AtCoder Kindergarten. Mr. Evi will arrange the
children in a line, then give 1 candy to the first child in the line, 2
candies to the second child, ..., N candies to the N-th child. How many
candies will be necessary in total?
|
[{"input": "3", "output": "6\n \n\nThe answer is 1+2+3=6.\n\n* * *"}, {"input": "10", "output": "55\n \n\nThe sum of the integers from 1 to 10 is 55.\n\n* * *"}, {"input": "1", "output": "1\n \n\nOnly one child. The answer is 1 in this case."}]
|
Print the necessary number of candies in total.
* * *
|
s080018525
|
Runtime Error
|
p04029
|
The input is given from Standard Input in the following format:
N
|
# 043A
# N人の時のキャンディーの合計数
# 入力値 子供の人数
# 入力
= int(input())
# 処理
answer = (n + 1) * n / 2
print(answer)
|
Statement
There are N children in AtCoder Kindergarten. Mr. Evi will arrange the
children in a line, then give 1 candy to the first child in the line, 2
candies to the second child, ..., N candies to the N-th child. How many
candies will be necessary in total?
|
[{"input": "3", "output": "6\n \n\nThe answer is 1+2+3=6.\n\n* * *"}, {"input": "10", "output": "55\n \n\nThe sum of the integers from 1 to 10 is 55.\n\n* * *"}, {"input": "1", "output": "1\n \n\nOnly one child. The answer is 1 in this case."}]
|
Print the necessary number of candies in total.
* * *
|
s640690000
|
Runtime Error
|
p04029
|
The input is given from Standard Input in the following format:
N
|
n = int(input())
sum = 0
for i in range(1:n+1):
sum +=i
print(sum)
|
Statement
There are N children in AtCoder Kindergarten. Mr. Evi will arrange the
children in a line, then give 1 candy to the first child in the line, 2
candies to the second child, ..., N candies to the N-th child. How many
candies will be necessary in total?
|
[{"input": "3", "output": "6\n \n\nThe answer is 1+2+3=6.\n\n* * *"}, {"input": "10", "output": "55\n \n\nThe sum of the integers from 1 to 10 is 55.\n\n* * *"}, {"input": "1", "output": "1\n \n\nOnly one child. The answer is 1 in this case."}]
|
Print the necessary number of candies in total.
* * *
|
s520296501
|
Runtime Error
|
p04029
|
The input is given from Standard Input in the following format:
N
|
n = input()
sum=0
for i in range(1,n+1):
sum+=i
print(sum)
|
Statement
There are N children in AtCoder Kindergarten. Mr. Evi will arrange the
children in a line, then give 1 candy to the first child in the line, 2
candies to the second child, ..., N candies to the N-th child. How many
candies will be necessary in total?
|
[{"input": "3", "output": "6\n \n\nThe answer is 1+2+3=6.\n\n* * *"}, {"input": "10", "output": "55\n \n\nThe sum of the integers from 1 to 10 is 55.\n\n* * *"}, {"input": "1", "output": "1\n \n\nOnly one child. The answer is 1 in this case."}]
|
Print the necessary number of candies in total.
* * *
|
s307321522
|
Runtime Error
|
p04029
|
The input is given from Standard Input in the following format:
N
|
print(sum(range(1,int(input())+1))
|
Statement
There are N children in AtCoder Kindergarten. Mr. Evi will arrange the
children in a line, then give 1 candy to the first child in the line, 2
candies to the second child, ..., N candies to the N-th child. How many
candies will be necessary in total?
|
[{"input": "3", "output": "6\n \n\nThe answer is 1+2+3=6.\n\n* * *"}, {"input": "10", "output": "55\n \n\nThe sum of the integers from 1 to 10 is 55.\n\n* * *"}, {"input": "1", "output": "1\n \n\nOnly one child. The answer is 1 in this case."}]
|
Print the necessary number of candies in total.
* * *
|
s342658621
|
Runtime Error
|
p04029
|
The input is given from Standard Input in the following format:
N
|
print(map(lambda x:x*(x+1)/2,input())
|
Statement
There are N children in AtCoder Kindergarten. Mr. Evi will arrange the
children in a line, then give 1 candy to the first child in the line, 2
candies to the second child, ..., N candies to the N-th child. How many
candies will be necessary in total?
|
[{"input": "3", "output": "6\n \n\nThe answer is 1+2+3=6.\n\n* * *"}, {"input": "10", "output": "55\n \n\nThe sum of the integers from 1 to 10 is 55.\n\n* * *"}, {"input": "1", "output": "1\n \n\nOnly one child. The answer is 1 in this case."}]
|
Print the necessary number of candies in total.
* * *
|
s735983999
|
Runtime Error
|
p04029
|
The input is given from Standard Input in the following format:
N
|
print(0.5(N + 1) ^ 2)
|
Statement
There are N children in AtCoder Kindergarten. Mr. Evi will arrange the
children in a line, then give 1 candy to the first child in the line, 2
candies to the second child, ..., N candies to the N-th child. How many
candies will be necessary in total?
|
[{"input": "3", "output": "6\n \n\nThe answer is 1+2+3=6.\n\n* * *"}, {"input": "10", "output": "55\n \n\nThe sum of the integers from 1 to 10 is 55.\n\n* * *"}, {"input": "1", "output": "1\n \n\nOnly one child. The answer is 1 in this case."}]
|
Print the necessary number of candies in total.
* * *
|
s724397670
|
Runtime Error
|
p04029
|
The input is given from Standard Input in the following format:
N
|
print(sum([x for x in range(1, int(input().split()) + 1)]))
|
Statement
There are N children in AtCoder Kindergarten. Mr. Evi will arrange the
children in a line, then give 1 candy to the first child in the line, 2
candies to the second child, ..., N candies to the N-th child. How many
candies will be necessary in total?
|
[{"input": "3", "output": "6\n \n\nThe answer is 1+2+3=6.\n\n* * *"}, {"input": "10", "output": "55\n \n\nThe sum of the integers from 1 to 10 is 55.\n\n* * *"}, {"input": "1", "output": "1\n \n\nOnly one child. The answer is 1 in this case."}]
|
Print the necessary number of candies in total.
* * *
|
s377970322
|
Wrong Answer
|
p04029
|
The input is given from Standard Input in the following format:
N
|
print((lambda x: x * (x + 1) / 2)(int(input())))
|
Statement
There are N children in AtCoder Kindergarten. Mr. Evi will arrange the
children in a line, then give 1 candy to the first child in the line, 2
candies to the second child, ..., N candies to the N-th child. How many
candies will be necessary in total?
|
[{"input": "3", "output": "6\n \n\nThe answer is 1+2+3=6.\n\n* * *"}, {"input": "10", "output": "55\n \n\nThe sum of the integers from 1 to 10 is 55.\n\n* * *"}, {"input": "1", "output": "1\n \n\nOnly one child. The answer is 1 in this case."}]
|
Print the necessary number of candies in total.
* * *
|
s776422377
|
Accepted
|
p04029
|
The input is given from Standard Input in the following format:
N
|
children_num = int(input())
total_candy = children_num * (children_num + 1) / 2
print(int(total_candy))
|
Statement
There are N children in AtCoder Kindergarten. Mr. Evi will arrange the
children in a line, then give 1 candy to the first child in the line, 2
candies to the second child, ..., N candies to the N-th child. How many
candies will be necessary in total?
|
[{"input": "3", "output": "6\n \n\nThe answer is 1+2+3=6.\n\n* * *"}, {"input": "10", "output": "55\n \n\nThe sum of the integers from 1 to 10 is 55.\n\n* * *"}, {"input": "1", "output": "1\n \n\nOnly one child. The answer is 1 in this case."}]
|
Print the necessary number of candies in total.
* * *
|
s878502426
|
Accepted
|
p04029
|
The input is given from Standard Input in the following format:
N
|
while True:
try:
n = int(input())
sum = int(0)
for i in range(1, n + 1):
sum += i
print(sum)
except:
break
|
Statement
There are N children in AtCoder Kindergarten. Mr. Evi will arrange the
children in a line, then give 1 candy to the first child in the line, 2
candies to the second child, ..., N candies to the N-th child. How many
candies will be necessary in total?
|
[{"input": "3", "output": "6\n \n\nThe answer is 1+2+3=6.\n\n* * *"}, {"input": "10", "output": "55\n \n\nThe sum of the integers from 1 to 10 is 55.\n\n* * *"}, {"input": "1", "output": "1\n \n\nOnly one child. The answer is 1 in this case."}]
|
Print the necessary number of candies in total.
* * *
|
s576253370
|
Wrong Answer
|
p04029
|
The input is given from Standard Input in the following format:
N
|
s = list(map(str, input().split()))
l = []
for i in s:
if i == "1":
l = s.pop(0)
elif i == "0":
l = s.pop(0)
elif i == "B":
l.pop()
print("".join(l))
|
Statement
There are N children in AtCoder Kindergarten. Mr. Evi will arrange the
children in a line, then give 1 candy to the first child in the line, 2
candies to the second child, ..., N candies to the N-th child. How many
candies will be necessary in total?
|
[{"input": "3", "output": "6\n \n\nThe answer is 1+2+3=6.\n\n* * *"}, {"input": "10", "output": "55\n \n\nThe sum of the integers from 1 to 10 is 55.\n\n* * *"}, {"input": "1", "output": "1\n \n\nOnly one child. The answer is 1 in this case."}]
|
Print the necessary number of candies in total.
* * *
|
s166491478
|
Wrong Answer
|
p04029
|
The input is given from Standard Input in the following format:
N
|
N = input()
X = ""
for i in range(1, (len(N) - 1)):
if (N[i] is not "B") and (N[i - 1] is not "B"):
X = X + N[i - 1]
if N[len(N) - 1] is not "B":
X = X + N[len(N) - 1]
print(X)
|
Statement
There are N children in AtCoder Kindergarten. Mr. Evi will arrange the
children in a line, then give 1 candy to the first child in the line, 2
candies to the second child, ..., N candies to the N-th child. How many
candies will be necessary in total?
|
[{"input": "3", "output": "6\n \n\nThe answer is 1+2+3=6.\n\n* * *"}, {"input": "10", "output": "55\n \n\nThe sum of the integers from 1 to 10 is 55.\n\n* * *"}, {"input": "1", "output": "1\n \n\nOnly one child. The answer is 1 in this case."}]
|
Print the necessary number of candies in total.
* * *
|
s866759514
|
Runtime Error
|
p04029
|
The input is given from Standard Input in the following format:
N
|
import sys
import math
def i():
return int(sys.stdin.readline().replace("\n", ""))
def i2():
return map(int, sys.stdin.readline().replace("\n", "").split())
def s():
return str(sys.stdin.readline().replace("\n", ""))
def l():
return list(sys.stdin.readline().replace("\n", ""))
def intl():
return [int(k) for k in sys.stdin.readline().replace("\n", "").split()]
def lx():
return list(
map(lambda x: int(x) * -1, sys.stdin.readline().replace("\n", "").split())
)
def t():
return tuple(map(int, sys.stdin.readline().replace("\n", "").split()))
if __name__ == "__main__":
pass
n = i()
a = intl()
if n == 1:
print(0)
else:
s = max(a) + min(a)
k1 = s // 2
k2 = s // 2 + s % 2
k3 = s // 2 - 1
c1 = 0
c2 = 0
c3 = 0
for i in range(n):
c3 += (a[i] - k3) ** 2
c2 += (a[i] - k2) ** 2
c1 += (a[i] - k1) ** 2
print(min(c1, c2, c3))
|
Statement
There are N children in AtCoder Kindergarten. Mr. Evi will arrange the
children in a line, then give 1 candy to the first child in the line, 2
candies to the second child, ..., N candies to the N-th child. How many
candies will be necessary in total?
|
[{"input": "3", "output": "6\n \n\nThe answer is 1+2+3=6.\n\n* * *"}, {"input": "10", "output": "55\n \n\nThe sum of the integers from 1 to 10 is 55.\n\n* * *"}, {"input": "1", "output": "1\n \n\nOnly one child. The answer is 1 in this case."}]
|
Print the necessary number of candies in total.
* * *
|
s525585893
|
Runtime Error
|
p04029
|
The input is given from Standard Input in the following format:
N
|
def candies():
n = int(input())
a = (n * (n + 1)) / 2
print(a)
candies()
|
Statement
There are N children in AtCoder Kindergarten. Mr. Evi will arrange the
children in a line, then give 1 candy to the first child in the line, 2
candies to the second child, ..., N candies to the N-th child. How many
candies will be necessary in total?
|
[{"input": "3", "output": "6\n \n\nThe answer is 1+2+3=6.\n\n* * *"}, {"input": "10", "output": "55\n \n\nThe sum of the integers from 1 to 10 is 55.\n\n* * *"}, {"input": "1", "output": "1\n \n\nOnly one child. The answer is 1 in this case."}]
|
Print the necessary number of candies in total.
* * *
|
s372068060
|
Runtime Error
|
p04029
|
The input is given from Standard Input in the following format:
N
|
lines = list(input())
answers = []
out = ""
for line in lines:
if line == "0" or line == "1":
answers.append(line)
else:
answers.pop()
for answer in answers:
out += answer
print(out)
|
Statement
There are N children in AtCoder Kindergarten. Mr. Evi will arrange the
children in a line, then give 1 candy to the first child in the line, 2
candies to the second child, ..., N candies to the N-th child. How many
candies will be necessary in total?
|
[{"input": "3", "output": "6\n \n\nThe answer is 1+2+3=6.\n\n* * *"}, {"input": "10", "output": "55\n \n\nThe sum of the integers from 1 to 10 is 55.\n\n* * *"}, {"input": "1", "output": "1\n \n\nOnly one child. The answer is 1 in this case."}]
|
Print the necessary number of candies in total.
* * *
|
s902670045
|
Wrong Answer
|
p04029
|
The input is given from Standard Input in the following format:
N
|
子供の数 = int(input())
答え = 0
for 飴の数 in range(1, 子供の数):
答え += 飴の数
print(答え)
|
Statement
There are N children in AtCoder Kindergarten. Mr. Evi will arrange the
children in a line, then give 1 candy to the first child in the line, 2
candies to the second child, ..., N candies to the N-th child. How many
candies will be necessary in total?
|
[{"input": "3", "output": "6\n \n\nThe answer is 1+2+3=6.\n\n* * *"}, {"input": "10", "output": "55\n \n\nThe sum of the integers from 1 to 10 is 55.\n\n* * *"}, {"input": "1", "output": "1\n \n\nOnly one child. The answer is 1 in this case."}]
|
Print the necessary number of candies in total.
* * *
|
s083290075
|
Wrong Answer
|
p04029
|
The input is given from Standard Input in the following format:
N
|
from itertools import combinations, product
def gcd(a, b):
if a < b:
a, b = b, a
while b != 0:
a, b = b, a % b
return a
def lcm(a, b):
return a * b // gcd(a, b)
def get(fmt):
ps = input().split()
r = []
for p, t in zip(ps, fmt):
if t == "i":
r.append(int(p))
if t == "f":
r.append(float(p))
if t == "s":
r.append(p)
if len(r) == 1:
r = r[0]
return r
def put(*args, **kwargs):
print(*args, **kwargs)
def rep(n, f, *args, **kwargs):
return [f(*args, **kwargs) for _ in range(n)]
def rep_im(n, v):
return rep(n, lambda: v)
YES_NO = ["NO", "YES"]
N = get("i")
put(N * (N - 1) // 2)
|
Statement
There are N children in AtCoder Kindergarten. Mr. Evi will arrange the
children in a line, then give 1 candy to the first child in the line, 2
candies to the second child, ..., N candies to the N-th child. How many
candies will be necessary in total?
|
[{"input": "3", "output": "6\n \n\nThe answer is 1+2+3=6.\n\n* * *"}, {"input": "10", "output": "55\n \n\nThe sum of the integers from 1 to 10 is 55.\n\n* * *"}, {"input": "1", "output": "1\n \n\nOnly one child. The answer is 1 in this case."}]
|
Print the necessary number of candies in total.
* * *
|
s206678610
|
Wrong Answer
|
p04029
|
The input is given from Standard Input in the following format:
N
|
number = int(input("人数を入力>"))
print(int(1 / 2 * number * (number + 1)))
|
Statement
There are N children in AtCoder Kindergarten. Mr. Evi will arrange the
children in a line, then give 1 candy to the first child in the line, 2
candies to the second child, ..., N candies to the N-th child. How many
candies will be necessary in total?
|
[{"input": "3", "output": "6\n \n\nThe answer is 1+2+3=6.\n\n* * *"}, {"input": "10", "output": "55\n \n\nThe sum of the integers from 1 to 10 is 55.\n\n* * *"}, {"input": "1", "output": "1\n \n\nOnly one child. The answer is 1 in this case."}]
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.