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 maximum possible value of the expected value of the sum of the
numbers shown.
Your output will be considered correct when its absolute or relative error
from our answer is at most 10^{-6}.
* * *
|
s351429283
|
Wrong Answer
|
p02780
|
Input is given from Standard Input in the following format:
N K
p_1 ... p_N
|
n = input().split()
N = int(n[0])
K = int(n[1])
a = input().split()
sum = 0
max = 0
for j in range(0, N):
sum += int(a[j])
if j > K - 1:
sum -= int(a[j - K])
if max < sum:
max = sum
print((max + K) / 2)
|
Statement
We have N dice arranged in a line from left to right. The i-th die from the
left shows p_i numbers from 1 to p_i with equal probability when thrown.
We will choose K adjacent dice, throw each of them independently, and compute
the sum of the numbers shown. Find the maximum possible value of the expected
value of this sum.
|
[{"input": "5 3\n 1 2 2 4 5", "output": "7.000000000000\n \n\nWhen we throw the third, fourth, and fifth dice from the left, the expected\nvalue of the sum of the numbers shown is 7. This is the maximum value we can\nachieve.\n\n* * *"}, {"input": "4 1\n 6 6 6 6", "output": "3.500000000000\n \n\nRegardless of which die we choose, the expected value of the number shown is\n3.5.\n\n* * *"}, {"input": "10 4\n 17 13 13 12 15 20 10 13 17 11", "output": "32.000000000000"}]
|
Print the maximum possible value of the expected value of the sum of the
numbers shown.
Your output will be considered correct when its absolute or relative error
from our answer is at most 10^{-6}.
* * *
|
s742473436
|
Accepted
|
p02780
|
Input is given from Standard Input in the following format:
N K
p_1 ... p_N
|
N, K = map(int, input().split(" "))
p_list = list(map(int, input().split(" ")))
expect_val = []
for i in p_list:
expect_val.append((i + 1) / 2)
max_val = 0
val = 0
for i in range(K):
max_val += expect_val[i]
val = max_val
for i in range(N - K):
val = val - expect_val[i] + expect_val[i + K]
max_val = max(max_val, val)
print(max_val)
|
Statement
We have N dice arranged in a line from left to right. The i-th die from the
left shows p_i numbers from 1 to p_i with equal probability when thrown.
We will choose K adjacent dice, throw each of them independently, and compute
the sum of the numbers shown. Find the maximum possible value of the expected
value of this sum.
|
[{"input": "5 3\n 1 2 2 4 5", "output": "7.000000000000\n \n\nWhen we throw the third, fourth, and fifth dice from the left, the expected\nvalue of the sum of the numbers shown is 7. This is the maximum value we can\nachieve.\n\n* * *"}, {"input": "4 1\n 6 6 6 6", "output": "3.500000000000\n \n\nRegardless of which die we choose, the expected value of the number shown is\n3.5.\n\n* * *"}, {"input": "10 4\n 17 13 13 12 15 20 10 13 17 11", "output": "32.000000000000"}]
|
Print the maximum possible value of the expected value of the sum of the
numbers shown.
Your output will be considered correct when its absolute or relative error
from our answer is at most 10^{-6}.
* * *
|
s981637192
|
Accepted
|
p02780
|
Input is given from Standard Input in the following format:
N K
p_1 ... p_N
|
n, m = map(int, input().split())
li = list(map(int, input().split()))
val = sum(li[:m])
ans = val
for i in range(m, n):
val = val - li[i - m] + li[i]
ans = max(ans, val)
print((ans + m) / 2)
|
Statement
We have N dice arranged in a line from left to right. The i-th die from the
left shows p_i numbers from 1 to p_i with equal probability when thrown.
We will choose K adjacent dice, throw each of them independently, and compute
the sum of the numbers shown. Find the maximum possible value of the expected
value of this sum.
|
[{"input": "5 3\n 1 2 2 4 5", "output": "7.000000000000\n \n\nWhen we throw the third, fourth, and fifth dice from the left, the expected\nvalue of the sum of the numbers shown is 7. This is the maximum value we can\nachieve.\n\n* * *"}, {"input": "4 1\n 6 6 6 6", "output": "3.500000000000\n \n\nRegardless of which die we choose, the expected value of the number shown is\n3.5.\n\n* * *"}, {"input": "10 4\n 17 13 13 12 15 20 10 13 17 11", "output": "32.000000000000"}]
|
Print the maximum possible value of the expected value of the sum of the
numbers shown.
Your output will be considered correct when its absolute or relative error
from our answer is at most 10^{-6}.
* * *
|
s654100681
|
Wrong Answer
|
p02780
|
Input is given from Standard Input in the following format:
N K
p_1 ... p_N
|
x = list(map(int, input().split()))
y = list(map(int, input().split()))
y = [i / 2 + 0.5 for i in y]
max_value = 0
value = sum(y[: x[1]])
for i in range(x[1] + 1, x[0]):
max_value = max(max_value, value)
value += y[i]
value -= y[i - x[1] - 1]
print(max_value)
|
Statement
We have N dice arranged in a line from left to right. The i-th die from the
left shows p_i numbers from 1 to p_i with equal probability when thrown.
We will choose K adjacent dice, throw each of them independently, and compute
the sum of the numbers shown. Find the maximum possible value of the expected
value of this sum.
|
[{"input": "5 3\n 1 2 2 4 5", "output": "7.000000000000\n \n\nWhen we throw the third, fourth, and fifth dice from the left, the expected\nvalue of the sum of the numbers shown is 7. This is the maximum value we can\nachieve.\n\n* * *"}, {"input": "4 1\n 6 6 6 6", "output": "3.500000000000\n \n\nRegardless of which die we choose, the expected value of the number shown is\n3.5.\n\n* * *"}, {"input": "10 4\n 17 13 13 12 15 20 10 13 17 11", "output": "32.000000000000"}]
|
Print the maximum possible value of the expected value of the sum of the
numbers shown.
Your output will be considered correct when its absolute or relative error
from our answer is at most 10^{-6}.
* * *
|
s292753630
|
Accepted
|
p02780
|
Input is given from Standard Input in the following format:
N K
p_1 ... p_N
|
N, K = map(int, input().split())
dices = list(map(int, input().split()))
# 期待値は(1+P)/2 https://rikeilabo.com/sum-formula-of-numerical-sequence
# 累積和を求めておく.隣接するK個の和はS_{j+K} - S_j
# 期待値の前計算→累積和の計算→隣接するK項の和の計算 (1乗オーダー)
E_list = []
for dice in dices:
E_list.append((1 + dice) * 0.5)
S_list = [] # i番目までのサイコロの期待値の累積和
for i in range(len(dices)):
# S_list.append(sum(E_list[:i + 1])) # アホ
S_list.append(E_list[0] if i == 0 else S_list[i - 1] + E_list[i])
print(
max(list(S_list[j + K] - S_list[j] for j in range(len(dices) - K)))
if len(dices) != K
else S_list[-1]
)
|
Statement
We have N dice arranged in a line from left to right. The i-th die from the
left shows p_i numbers from 1 to p_i with equal probability when thrown.
We will choose K adjacent dice, throw each of them independently, and compute
the sum of the numbers shown. Find the maximum possible value of the expected
value of this sum.
|
[{"input": "5 3\n 1 2 2 4 5", "output": "7.000000000000\n \n\nWhen we throw the third, fourth, and fifth dice from the left, the expected\nvalue of the sum of the numbers shown is 7. This is the maximum value we can\nachieve.\n\n* * *"}, {"input": "4 1\n 6 6 6 6", "output": "3.500000000000\n \n\nRegardless of which die we choose, the expected value of the number shown is\n3.5.\n\n* * *"}, {"input": "10 4\n 17 13 13 12 15 20 10 13 17 11", "output": "32.000000000000"}]
|
Print the maximum possible value of the expected value of the sum of the
numbers shown.
Your output will be considered correct when its absolute or relative error
from our answer is at most 10^{-6}.
* * *
|
s735677771
|
Wrong Answer
|
p02780
|
Input is given from Standard Input in the following format:
N K
p_1 ... p_N
|
N, K = list(map(int, input().split()))
p = list(map(int, input().split()))
ans = 0
A = []
B = 0
for i in range(len(p) - K + 1):
P = p[i : i + 3]
if ans < sum(P):
ans2 = P
ans = max(ans, sum(P))
for j in range(len(P)):
for k in range(1, P[j] + 1):
A.append(k)
B += sum(A) / P[j]
A.clear()
print(B)
|
Statement
We have N dice arranged in a line from left to right. The i-th die from the
left shows p_i numbers from 1 to p_i with equal probability when thrown.
We will choose K adjacent dice, throw each of them independently, and compute
the sum of the numbers shown. Find the maximum possible value of the expected
value of this sum.
|
[{"input": "5 3\n 1 2 2 4 5", "output": "7.000000000000\n \n\nWhen we throw the third, fourth, and fifth dice from the left, the expected\nvalue of the sum of the numbers shown is 7. This is the maximum value we can\nachieve.\n\n* * *"}, {"input": "4 1\n 6 6 6 6", "output": "3.500000000000\n \n\nRegardless of which die we choose, the expected value of the number shown is\n3.5.\n\n* * *"}, {"input": "10 4\n 17 13 13 12 15 20 10 13 17 11", "output": "32.000000000000"}]
|
Print the number of different sequences that B_1, B_2, ..., B_N can be, modulo
10^9 + 7.
* * *
|
s225967492
|
Runtime Error
|
p03191
|
Input is given from Standard Input in the following format:
N
A_1 A_2 ... A_{2N}
|
n = int(input())
a = [int(i) for i in input().split()]
b = []
d = []
for i in range(len(a)):
b.append(a[2 * i] - a[2 * i + 1])
c = [i for i in a.split() if i != "-1"]
c = list(set(range(1, len(a) + 1) ^ set(c)))
for i in range(len(b)):
if b[i] - 1 == a[2 * i]:
d.append([i for i in c if i < a[2 * i]] + [a[2 * i]])
elif b[i] + a[2 * i] == -1:
d.append([i for i in c if i < a[2 * i + 1]] + [a[2 * i] + 1])
elif b[i] == 0:
d.append([i for i in c if i != max(c)])
f = 1
for i in d:
f *= len(i)
for i in range(len(c)):
if [e for i in d for e in i].count(c[i]) >= 2:
g = 1
for j in d:
g *= len(j) - j.count(c[i])
f -= g
print(f)
|
Statement
There is a sequence of length 2N: A_1, A_2, ..., A_{2N}. Each A_i is either -1
or an integer between 1 and 2N (inclusive). Any integer other than -1 appears
at most once in {A_i}.
For each i such that A_i = -1, Snuke replaces A_i with an integer between 1
and 2N (inclusive), so that {A_i} will be a permutation of 1, 2, ..., 2N.
Then, he finds a sequence of length N, B_1, B_2, ..., B_N, as B_i =
min(A_{2i-1}, A_{2i}).
Find the number of different sequences that B_1, B_2, ..., B_N can be, modulo
10^9 + 7.
|
[{"input": "3\n 1 -1 -1 3 6 -1", "output": "5\n \n\nThere are six ways to make {A_i} a permutation of 1, 2, ..., 2N; for each of\nthem, {B_i} would be as follows:\n\n * (A_1, A_2, A_3, A_4, A_5, A_6) = (1, 2, 4, 3, 6, 5): (B_1, B_2, B_3) = (1, 3, 5)\n * (A_1, A_2, A_3, A_4, A_5, A_6) = (1, 2, 5, 3, 6, 4): (B_1, B_2, B_3) = (1, 3, 4)\n * (A_1, A_2, A_3, A_4, A_5, A_6) = (1, 4, 2, 3, 6, 5): (B_1, B_2, B_3) = (1, 2, 5)\n * (A_1, A_2, A_3, A_4, A_5, A_6) = (1, 4, 5, 3, 6, 2): (B_1, B_2, B_3) = (1, 3, 2)\n * (A_1, A_2, A_3, A_4, A_5, A_6) = (1, 5, 2, 3, 6, 4): (B_1, B_2, B_3) = (1, 2, 4)\n * (A_1, A_2, A_3, A_4, A_5, A_6) = (1, 5, 4, 3, 6, 2): (B_1, B_2, B_3) = (1, 3, 2)\n\nThus, there are five different sequences that B_1, B_2, B_3 can be.\n\n* * *"}, {"input": "4\n 7 1 8 3 5 2 6 4", "output": "1\n \n\n* * *"}, {"input": "10\n 7 -1 -1 -1 -1 -1 -1 6 14 12 13 -1 15 -1 -1 -1 -1 20 -1 -1", "output": "9540576\n \n\n* * *"}, {"input": "20\n -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 6 -1 -1 -1 -1 -1 7 -1 -1 -1 -1 -1 -1 -1 -1 -1 34 -1 -1 -1 -1 31 -1 -1 -1 -1 -1 -1 -1 -1", "output": "374984201"}]
|
Print the number of different sequences that B_1, B_2, ..., B_N can be, modulo
10^9 + 7.
* * *
|
s679088784
|
Runtime Error
|
p03191
|
Input is given from Standard Input in the following format:
N
A_1 A_2 ... A_{2N}
|
n = int(input())
a = [int(i) for i in input().split()]
b = []
d = []
for i in range(len(a)):
b.append(a[2i]-a[2i+1])
c = [i for i in a.split() if i != '-1']
c = list(set(range(1,len(a)+1) ^ set(c))
for i in range(len(b)):
if b[i]-1 == a[2*i]:
d.append([i for i in c if i < a[2*i]] + [a[2*i]])
elif b[i]+a[2*i] == -1:
d.append([i for i in c if i < a[2*i+1]] + [a[2*i]+1])
elif b[i] == 0:
d.append([i for i in c if i != max(c)])
f = 1
for i in d:
f *= len(i)
for i in range(len(c)):
if [e for i in d for e in i].count(c[i]) >= 2:
g = 1
for j in d:
g *= len(j)-j.count(c[i])
f -= g
print(f)
|
Statement
There is a sequence of length 2N: A_1, A_2, ..., A_{2N}. Each A_i is either -1
or an integer between 1 and 2N (inclusive). Any integer other than -1 appears
at most once in {A_i}.
For each i such that A_i = -1, Snuke replaces A_i with an integer between 1
and 2N (inclusive), so that {A_i} will be a permutation of 1, 2, ..., 2N.
Then, he finds a sequence of length N, B_1, B_2, ..., B_N, as B_i =
min(A_{2i-1}, A_{2i}).
Find the number of different sequences that B_1, B_2, ..., B_N can be, modulo
10^9 + 7.
|
[{"input": "3\n 1 -1 -1 3 6 -1", "output": "5\n \n\nThere are six ways to make {A_i} a permutation of 1, 2, ..., 2N; for each of\nthem, {B_i} would be as follows:\n\n * (A_1, A_2, A_3, A_4, A_5, A_6) = (1, 2, 4, 3, 6, 5): (B_1, B_2, B_3) = (1, 3, 5)\n * (A_1, A_2, A_3, A_4, A_5, A_6) = (1, 2, 5, 3, 6, 4): (B_1, B_2, B_3) = (1, 3, 4)\n * (A_1, A_2, A_3, A_4, A_5, A_6) = (1, 4, 2, 3, 6, 5): (B_1, B_2, B_3) = (1, 2, 5)\n * (A_1, A_2, A_3, A_4, A_5, A_6) = (1, 4, 5, 3, 6, 2): (B_1, B_2, B_3) = (1, 3, 2)\n * (A_1, A_2, A_3, A_4, A_5, A_6) = (1, 5, 2, 3, 6, 4): (B_1, B_2, B_3) = (1, 2, 4)\n * (A_1, A_2, A_3, A_4, A_5, A_6) = (1, 5, 4, 3, 6, 2): (B_1, B_2, B_3) = (1, 3, 2)\n\nThus, there are five different sequences that B_1, B_2, B_3 can be.\n\n* * *"}, {"input": "4\n 7 1 8 3 5 2 6 4", "output": "1\n \n\n* * *"}, {"input": "10\n 7 -1 -1 -1 -1 -1 -1 6 14 12 13 -1 15 -1 -1 -1 -1 20 -1 -1", "output": "9540576\n \n\n* * *"}, {"input": "20\n -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 6 -1 -1 -1 -1 -1 7 -1 -1 -1 -1 -1 -1 -1 -1 -1 34 -1 -1 -1 -1 31 -1 -1 -1 -1 -1 -1 -1 -1", "output": "374984201"}]
|
For the lexicographically smallest (A,B), print A and B with a space in
between.
* * *
|
s991906265
|
Wrong Answer
|
p03484
|
Input is given from Standard Input in the following format:
N
a_1 b_1
:
a_{N-1} b_{N-1}
|
import sys, heapq
input = sys.stdin.readline
sys.setrecursionlimit(2 * 10**5)
N = int(input())
edge = [[] for i in range(N)]
for _ in range(N - 1):
a, b = map(int, input().split())
edge[a - 1].append(b - 1)
edge[b - 1].append(a - 1)
temp = [[0 for j in range(len(edge[i]) - 1)] for i in range(N)]
temp[0].append(0)
for i in range(1, N):
if len(temp[i]) % 2 == 0:
temp[i].append(0)
if len(temp[0]) % 2 == 1:
temp[0].append(0)
def clear():
for i in range(N):
temp[i].sort()
for j in range(len(temp[i])):
temp[i][j] = 0
start = 0
end = N - 1
while end - start > 1:
t = (end + start) // 2
clear()
end = t
print(end)
|
Statement
Takahashi has decided to make a _Christmas Tree_ for the Christmas party in
AtCoder, Inc.
A Christmas Tree is a tree with N vertices numbered 1 through N and N-1 edges,
whose i-th edge (1\leq i\leq N-1) connects Vertex a_i and b_i.
He would like to make one as follows:
* Specify two non-negative integers A and B.
* Prepare A _Christmas Paths_ whose lengths are at most B. Here, a Christmas Path of length X is a graph with X+1 vertices and X edges such that, if we properly number the vertices 1 through X+1, the i-th edge (1\leq i\leq X) will connect Vertex i and i+1.
* Repeat the following operation until he has one connected tree:
* Select two vertices x and y that belong to different connected components. Combine x and y into one vertex. More precisely, for each edge (p,y) incident to the vertex y, add the edge (p,x). Then, delete the vertex y and all the edges incident to y.
* Properly number the vertices in the tree.
Takahashi would like to find the lexicographically smallest pair (A,B) such
that he can make a Christmas Tree, that is, find the smallest A, and find the
smallest B under the condition that A is minimized.
Solve this problem for him.
|
[{"input": "7\n 1 2\n 2 3\n 2 4\n 4 5\n 4 6\n 6 7", "output": "3 2\n \n\nWe can make a Christmas Tree as shown in the figure below:\n\n\n\n* * *"}, {"input": "8\n 1 2\n 2 3\n 3 4\n 4 5\n 5 6\n 5 7\n 5 8", "output": "2 5\n \n\n* * *"}, {"input": "10\n 1 2\n 2 3\n 3 4\n 2 5\n 6 5\n 6 7\n 7 8\n 5 9\n 10 5", "output": "3 4"}]
|
For the lexicographically smallest (A,B), print A and B with a space in
between.
* * *
|
s970688993
|
Runtime Error
|
p03484
|
Input is given from Standard Input in the following format:
N
a_1 b_1
:
a_{N-1} b_{N-1}
|
import sys,heapq
input=sys.stdin.readline
sys.setrecursionlimit(2*10**5)
N=int(input())
edge=[[] for i in range(N)]
for _ in range(N-1):
a,b=map(int,input().split())
edge[a-1].append(b-1)
edge[b-1].append(a-1)
def dfs(v,pv,n):
#print(v,pv,len(edge[v]))
if v!=0:
if len(edge[v])==1:
return 1
temp=[]
for nv in edge[v]:
if nv!=pv:
r=dfs(nv,v,n)
if r==-1:
return -1
temp.append(r)
if len(temp)%2==0:
temp.append(0)
elif len(temp)==1:
return temp[0]+1
temp.sort()
que=[]
#ban=set([])
k=len(temp)//2
for i in range(k):
heapq.heappush(que,(-temp[i+1]-temp[-i-1],i+1,N-1-i))
for i in range(k):
val,id1,id2=heapq.heappop(que)
while id1+id2==N and id1=<i:
val,id1,id2=heapq.heappop(que)
if val>=-n:
return temp[i]+1
heapq.heappush(que,(-temp[i]-temp[-i-1],i,N-1-i))
#ban.add((i+1,N-1-i))
for i in range(k):
val,id1,id2=heapq.heappop(que)
while (id1+id2==N) or (id1+id2==N-1 and id2<i+k):
val,id1,id2=heapq.heappop(que)
if val>=-n:
return temp[i+k]+1
heapq.heappush(que,(-temp[k-1-i]-temp[i+k],k-1-i,i+k))
#ban.add((N-1-i-k,i+k))
val,id1,id2=heapq.heappop(que)
while id1+id2!=2*k-1:
val,id1,id2=heapq.heappop(que)
if val>=-n:
return temp[-1]+1
return -1
else:
temp=[]
for nv in edge[v]:
if nv!=pv:
r=dfs(nv,v,n)
if r==-1:
return False
temp.append(r)
if len(temp)%2==1:
temp.append(0)
temp.sort()
k=len(temp)//2
for i in range(k):
test=temp[i]+temp[-i-1]
if test>n:
return False
return True
A=(len(edge[0])+1)//2
for i in range(1,N):
A+=(len(edge[i])-1)//2
start=0
end=N-1
while end-start>1:
t=(end+start)//2
if dfs(0,-1,t):
end=t
else:
start=t
print(A,end)
|
Statement
Takahashi has decided to make a _Christmas Tree_ for the Christmas party in
AtCoder, Inc.
A Christmas Tree is a tree with N vertices numbered 1 through N and N-1 edges,
whose i-th edge (1\leq i\leq N-1) connects Vertex a_i and b_i.
He would like to make one as follows:
* Specify two non-negative integers A and B.
* Prepare A _Christmas Paths_ whose lengths are at most B. Here, a Christmas Path of length X is a graph with X+1 vertices and X edges such that, if we properly number the vertices 1 through X+1, the i-th edge (1\leq i\leq X) will connect Vertex i and i+1.
* Repeat the following operation until he has one connected tree:
* Select two vertices x and y that belong to different connected components. Combine x and y into one vertex. More precisely, for each edge (p,y) incident to the vertex y, add the edge (p,x). Then, delete the vertex y and all the edges incident to y.
* Properly number the vertices in the tree.
Takahashi would like to find the lexicographically smallest pair (A,B) such
that he can make a Christmas Tree, that is, find the smallest A, and find the
smallest B under the condition that A is minimized.
Solve this problem for him.
|
[{"input": "7\n 1 2\n 2 3\n 2 4\n 4 5\n 4 6\n 6 7", "output": "3 2\n \n\nWe can make a Christmas Tree as shown in the figure below:\n\n\n\n* * *"}, {"input": "8\n 1 2\n 2 3\n 3 4\n 4 5\n 5 6\n 5 7\n 5 8", "output": "2 5\n \n\n* * *"}, {"input": "10\n 1 2\n 2 3\n 3 4\n 2 5\n 6 5\n 6 7\n 7 8\n 5 9\n 10 5", "output": "3 4"}]
|
For the lexicographically smallest (A,B), print A and B with a space in
between.
* * *
|
s905869430
|
Runtime Error
|
p03484
|
Input is given from Standard Input in the following format:
N
a_1 b_1
:
a_{N-1} b_{N-1}
|
from collections import defaultdict
import sys
from math import log2
sys.setrecursionlimit(10**6)
input = sys.stdin.readline
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def main():
def init(i, oi=-1, dpt=0):
depth[i] = dpt
parent_2k[0][i] = oi
for ki in to[i]:
if ki == oi:
continue
init(ki, i, dpt + 1)
return
def make_parent(level):
parent_2kk1 = parent_2k[0]
for k in range(1, level):
parent_2kk = parent_2k[k]
for i in range(n):
parent1 = parent_2kk1[i]
if parent1 != -1:
parent_2kk[i] = parent_2kk1[parent1]
parent_2kk1 = parent_2kk
return
def lca(u, v):
dist_uv = depth[u] - depth[v]
if dist_uv < 0:
u, v = v, u
dist_uv *= -1
k = 0
while dist_uv:
if dist_uv & 1:
u = parent_2k[k][u]
dist_uv >>= 1
k += 1
if u == v:
return u
for k in range(int(log2(depth[u])) + 1, -1, -1):
pu = parent_2k[k][u]
pv = parent_2k[k][v]
if pu != pv:
u = pu
v = pv
return parent_2k[0][u]
def dfs(i, mx, len_odd):
if i == len_odd:
return mx
if fin[i]:
return dfs(i + 1, mx, len_odd)
res = inf
fin[i] = True
for j in range(i + 1, len_odd):
if fin[j]:
continue
fin[j] = True
res = min(res, dfs(i + 1, max(mx, dist[i][j]), len_odd))
fin[j] = False
fin[i] = False
return res
inf = 10**6
n = int(input())
to = defaultdict(list)
for _ in range(n - 1):
a, b = map(int1, input().split())
to[a].append(b)
to[b].append(a)
depth = [0] * n
level = int(log2(n)) + 1
parent_2k = [[-1] * n for _ in range(level)]
init(0)
make_parent(level)
odd_degree_nodes = []
for u in range(n):
if len(to[u]) % 2:
odd_degree_nodes.append(u)
# print(odd_degree_nodes)
len_odd = len(odd_degree_nodes)
ans_a = len_odd // 2
dist = [[-1] * len_odd for _ in range(len_odd)]
for j in range(len_odd):
v = odd_degree_nodes[j]
for i in range(j):
u = odd_degree_nodes[i]
lca_uv = lca(u, v)
dist[i][j] = dist[j][i] = depth[u] + depth[v] - 2 * depth[lca_uv]
# p2D(dist)
fin = [False] * len_odd
ans_b = dfs(0, 0, len_odd)
print(ans_a, ans_b)
main()
|
Statement
Takahashi has decided to make a _Christmas Tree_ for the Christmas party in
AtCoder, Inc.
A Christmas Tree is a tree with N vertices numbered 1 through N and N-1 edges,
whose i-th edge (1\leq i\leq N-1) connects Vertex a_i and b_i.
He would like to make one as follows:
* Specify two non-negative integers A and B.
* Prepare A _Christmas Paths_ whose lengths are at most B. Here, a Christmas Path of length X is a graph with X+1 vertices and X edges such that, if we properly number the vertices 1 through X+1, the i-th edge (1\leq i\leq X) will connect Vertex i and i+1.
* Repeat the following operation until he has one connected tree:
* Select two vertices x and y that belong to different connected components. Combine x and y into one vertex. More precisely, for each edge (p,y) incident to the vertex y, add the edge (p,x). Then, delete the vertex y and all the edges incident to y.
* Properly number the vertices in the tree.
Takahashi would like to find the lexicographically smallest pair (A,B) such
that he can make a Christmas Tree, that is, find the smallest A, and find the
smallest B under the condition that A is minimized.
Solve this problem for him.
|
[{"input": "7\n 1 2\n 2 3\n 2 4\n 4 5\n 4 6\n 6 7", "output": "3 2\n \n\nWe can make a Christmas Tree as shown in the figure below:\n\n\n\n* * *"}, {"input": "8\n 1 2\n 2 3\n 3 4\n 4 5\n 5 6\n 5 7\n 5 8", "output": "2 5\n \n\n* * *"}, {"input": "10\n 1 2\n 2 3\n 3 4\n 2 5\n 6 5\n 6 7\n 7 8\n 5 9\n 10 5", "output": "3 4"}]
|
For each query, print the coordinate of the cross point. The output values
should be in a decimal fraction with an error less than 0.00000001.
|
s404358127
|
Wrong Answer
|
p02295
|
The entire input looks like:
q (the number of queries)
1st query
2nd query
...
qth query
Each query consists of integer coordinates of end points of s1 and s2 in the
following format:
xp0 yp0 xp1 yp1 xp2 yp2 xp3 yp3
|
# -*- coding: utf-8 -*-
import collections
import math
class Vector2(collections.namedtuple("Vector2", ["x", "y"])):
def __add__(self, other):
return Vector2(self.x + other.x, self.y + other.y)
def __sub__(self, other):
return Vector2(self.x - other.x, self.y - other.y)
def __mul__(self, scalar):
return Vector2(self.x * scalar, self.y * scalar)
def __neg__(self):
return Vector2(-self.x, -self.y)
def __pos__(self):
return Vector2(+self.x, +self.y)
def __abs__(self): # norm
return math.sqrt(float(self.x * self.x + self.y * self.y))
def dot(self, other): # dot product
return self.x * other.x + self.y * other.y
def cross(self, other): # cross product
return self.x * other.y - self.y * other.x
def getDistanceSP(segment, point):
p = point
p1, p2 = segment
if (p2 - p1).dot(p - p1) < 0:
return abs(p - p1)
if (p1 - p2).dot(p - p2) < 0:
return abs(p - p2)
return abs((p2 - p1).cross(p - p1)) / abs(p2 - p1)
def getDistance(s1, s2):
a, b = s1
c, d = s2
if intersect(s1, s2): # intersect
return 0
return min(
getDistanceSP(s1, c),
getDistanceSP(s1, d),
getDistanceSP(s2, a),
getDistanceSP(s2, b),
)
def ccw(p0, p1, p2):
a = p1 - p0
b = p2 - p0
if a.cross(b) > 0:
return 1 # COUNTER_CLOCKWISE
elif a.cross(b) < 0:
return -1 # CLOCKWISE
elif a.dot(b) < 0:
return 2 # ONLINE_BACK
elif abs(a) < abs(b):
return -2 # ONLINE_FRONT
else:
return 0 # ON_SEGMENT
def intersect(s1, s2):
a, b = s1
c, d = s2
return ccw(a, b, c) * ccw(a, b, d) <= 0 and ccw(c, d, a) * ccw(c, d, b) <= 0
def getCrossPoint(s1, s2):
a, b = s1
c, d = s2
base = d - c
d1 = abs(base.cross(b - c))
d2 = abs(base.cross(a - c))
t = d1 / (d1 + d2)
return a + (b - a) * t
if __name__ == "__main__":
n = int(input())
for _ in range(n):
l = list(map(int, input().split()))
s1 = [Vector2(l[0], l[1]), Vector2(l[2], l[3])]
s2 = [Vector2(l[4], l[5]), Vector2(l[6], l[7])]
x = getCrossPoint(s1, s2)
print(x.x, x.y)
|
Cross Point
For given two segments s1 and s2, print the coordinate of the cross point of
them.
s1 is formed by end points p0 and p1, and s2 is formed by end points p2 and
p3.
|
[{"input": "0 0 2 0 1 1 1 -1\n 0 0 1 1 0 1 1 0\n 0 0 1 1 1 0 0 1", "output": ".0000000000 0.0000000000\n 0.5000000000 0.5000000000\n 0.5000000000 0.5000000000"}]
|
For each query, print the coordinate of the cross point. The output values
should be in a decimal fraction with an error less than 0.00000001.
|
s619491158
|
Accepted
|
p02295
|
The entire input looks like:
q (the number of queries)
1st query
2nd query
...
qth query
Each query consists of integer coordinates of end points of s1 and s2 in the
following format:
xp0 yp0 xp1 yp1 xp2 yp2 xp3 yp3
|
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
def input():
return sys.stdin.readline().strip()
def INT():
return int(input())
def MAP():
return map(int, input().split())
def LIST():
return list(map(int, input().split()))
INF = float("inf")
class Geometry:
EPS = 10**-9
def add(self, a, b):
x1, y1 = a
x2, y2 = b
return (x1 + x2, y1 + y2)
def sub(self, a, b):
x1, y1 = a
x2, y2 = b
return (x1 - x2, y1 - y2)
def mul(self, a, b):
x1, y1 = a
if not isinstance(b, tuple):
return (x1 * b, y1 * b)
x2, y2 = b
return (x1 * x2, y1 * y2)
def abs(self, a):
from math import hypot
x1, y1 = a
return hypot(x1, y1)
def norm(self, a):
x, y = a
return x**2 + y**2
def dot(self, a, b):
x1, y1 = a
x2, y2 = b
return x1 * x2 + y1 * y2
def cross(self, a, b):
x1, y1 = a
x2, y2 = b
return x1 * y2 - y1 * x2
def project(self, seg, p):
"""線分segに対する点pの射影"""
p1, p2 = seg
base = self.sub(p2, p1)
r = self.dot(self.sub(p, p1), base) / self.norm(base)
return self.add(p1, self.mul(base, r))
def reflect(self, seg, p):
"""線分segを対称軸とした点pの線対称の点"""
return self.add(p, self.mul(self.sub(self.project(seg, p), p), 2))
def ccw(self, p0, p1, p2):
"""線分p0,p1から線分p0,p2への回転方向"""
a = self.sub(p1, p0)
b = self.sub(p2, p0)
# 反時計回り
if self.cross(a, b) > self.EPS:
return 1
# 時計回り
if self.cross(a, b) < -self.EPS:
return -1
# 直線上(p2 => p0 => p1)
if self.dot(a, b) < -self.EPS:
return 2
# 直線上(p0 => p1 => p2)
if self.norm(a) < self.norm(b):
return -2
# 直線上(p0 => p2 => p1)
return 0
def intersect(self, seg1, seg2):
"""線分seg1と線分seg2の交差判定"""
p1, p2 = seg1
p3, p4 = seg2
return (
self.ccw(p1, p2, p3) * self.ccw(p1, p2, p4) <= 0
and self.ccw(p3, p4, p1) * self.ccw(p3, p4, p2) <= 0
)
def get_distance_LP(self, line, p):
"""直線lineと点pの距離"""
p1, p2 = line
return abs(
self.cross(self.sub(p2, p1), self.sub(p, p1)) / self.abs(self.sub(p2, p1))
)
def get_distance_SP(self, seg, p):
"""線分segと点pの距離"""
p1, p2 = seg
if self.dot(self.sub(p2, p1), self.sub(p, p1)) < 0:
return self.abs(self.sub(p, p1))
if self.dot(self.sub(p1, p2), self.sub(p, p2)) < 0:
return self.abs(self.sub(p, p2))
return self.get_distance_LP(seg, p)
def get_distance_SS(self, seg1, seg2):
"""線分seg1と線分seg2の距離"""
p1, p2 = seg1
p3, p4 = seg2
if self.intersect(seg1, seg2):
return 0
return min(
self.get_distance_SP(seg1, p3),
self.get_distance_SP(seg1, p4),
self.get_distance_SP(seg2, p1),
self.get_distance_SP(seg2, p2),
)
def get_cross_point(self, seg1, seg2):
"""線分seg1と線分seg2の交点"""
p1, p2 = seg1
p3, p4 = seg2
base = self.sub(p4, p3)
dist1 = abs(self.cross(base, self.sub(p1, p3)))
dist2 = abs(self.cross(base, self.sub(p2, p3)))
t = dist1 / (dist1 + dist2)
return self.add(p1, self.mul(self.sub(p2, p1), t))
gm = Geometry()
for _ in range(INT()):
x1, y1, x2, y2, x3, y3, x4, y4 = MAP()
seg1 = ((x1, y1), (x2, y2))
seg2 = ((x3, y3), (x4, y4))
res = gm.get_cross_point(seg1, seg2)
print(*res)
|
Cross Point
For given two segments s1 and s2, print the coordinate of the cross point of
them.
s1 is formed by end points p0 and p1, and s2 is formed by end points p2 and
p3.
|
[{"input": "0 0 2 0 1 1 1 -1\n 0 0 1 1 0 1 1 0\n 0 0 1 1 1 0 0 1", "output": ".0000000000 0.0000000000\n 0.5000000000 0.5000000000\n 0.5000000000 0.5000000000"}]
|
For each query, print the coordinate of the cross point. The output values
should be in a decimal fraction with an error less than 0.00000001.
|
s153342921
|
Accepted
|
p02295
|
The entire input looks like:
q (the number of queries)
1st query
2nd query
...
qth query
Each query consists of integer coordinates of end points of s1 and s2 in the
following format:
xp0 yp0 xp1 yp1 xp2 yp2 xp3 yp3
|
q = int(input())
for i in range(q):
a, b, c, d, e, f, g, h = [int(i) for i in input().split()]
A = d - b
B = c - a
C = f - h
D = e - g
E = a * d - b * c
F = e * h - f * g
G = A * D - B * C
print((E * D + F * B) / G, (E * C + F * A) / G)
|
Cross Point
For given two segments s1 and s2, print the coordinate of the cross point of
them.
s1 is formed by end points p0 and p1, and s2 is formed by end points p2 and
p3.
|
[{"input": "0 0 2 0 1 1 1 -1\n 0 0 1 1 0 1 1 0\n 0 0 1 1 1 0 0 1", "output": ".0000000000 0.0000000000\n 0.5000000000 0.5000000000\n 0.5000000000 0.5000000000"}]
|
For each query, print the coordinate of the cross point. The output values
should be in a decimal fraction with an error less than 0.00000001.
|
s528542531
|
Wrong Answer
|
p02295
|
The entire input looks like:
q (the number of queries)
1st query
2nd query
...
qth query
Each query consists of integer coordinates of end points of s1 and s2 in the
following format:
xp0 yp0 xp1 yp1 xp2 yp2 xp3 yp3
|
q = int(input())
for i in range(q):
a, b, c, d, e, f, g, h = [int(i) for i in input().split()]
A = a * d - b * c
B = e * h - f * g
C = d - b
D = c - a
E = f - h
F = e - g
det = C * F - D * E
print((A * D + B * E) / det, (A * F + B * C) / det)
|
Cross Point
For given two segments s1 and s2, print the coordinate of the cross point of
them.
s1 is formed by end points p0 and p1, and s2 is formed by end points p2 and
p3.
|
[{"input": "0 0 2 0 1 1 1 -1\n 0 0 1 1 0 1 1 0\n 0 0 1 1 1 0 0 1", "output": ".0000000000 0.0000000000\n 0.5000000000 0.5000000000\n 0.5000000000 0.5000000000"}]
|
For each query, print the coordinate of the cross point. The output values
should be in a decimal fraction with an error less than 0.00000001.
|
s228363380
|
Accepted
|
p02295
|
The entire input looks like:
q (the number of queries)
1st query
2nd query
...
qth query
Each query consists of integer coordinates of end points of s1 and s2 in the
following format:
xp0 yp0 xp1 yp1 xp2 yp2 xp3 yp3
|
# 交点、非平行の保証付
def vc(p, q):
return [p[0] - q[0], p[1] - q[1]]
def cross(u, v):
return u[0] * v[1] - u[1] * v[0]
n = int(input())
for _ in range(n):
x0, y0, x1, y1, x2, y2, x3, y3 = map(int, input().split())
p0, p1, p2, p3 = [x0, y0], [x1, y1], [x2, y2], [x3, y3]
v01 = vc(p1, p0)
v02 = vc(p2, p0)
v03 = vc(p3, p0)
d1 = cross(v01, v02)
d2 = cross(v01, v03)
# print(v01,v02,v03,d1,d2)
if d1 == 0:
# print("p2")
print(*p2)
elif d2 == 0:
# print("p3")
print(*p3)
else:
mu = abs(d1) / (abs(d1) + abs(d2))
# print(mu)
v23 = vc(p3, p2)
ans = [p2[0] + mu * v23[0], p2[1] + mu * v23[1]]
print(*ans)
|
Cross Point
For given two segments s1 and s2, print the coordinate of the cross point of
them.
s1 is formed by end points p0 and p1, and s2 is formed by end points p2 and
p3.
|
[{"input": "0 0 2 0 1 1 1 -1\n 0 0 1 1 0 1 1 0\n 0 0 1 1 1 0 0 1", "output": ".0000000000 0.0000000000\n 0.5000000000 0.5000000000\n 0.5000000000 0.5000000000"}]
|
Print how many numbers will be written on the sheet at the end of the game.
* * *
|
s621556140
|
Runtime Error
|
p03607
|
Input is given from Standard Input in the following format:
N
A_1
:
A_N
|
n = int(input())
x = [0 for i in range(10**5 + 1)]
for i in range(n):
t = int(input())
x[t] += 1
if x[t] == 2:
x[t] = 0
print(x.count(1))
|
Statement
You are playing the following game with Joisino.
* Initially, you have a blank sheet of paper.
* Joisino announces a number. If that number is written on the sheet, erase the number from the sheet; if not, write the number on the sheet. This process is repeated N times.
* Then, you are asked a question: How many numbers are written on the sheet now?
The numbers announced by Joisino are given as A_1, ... ,A_N in the order she
announces them. How many numbers will be written on the sheet at the end of
the game?
|
[{"input": "3\n 6\n 2\n 6", "output": "1\n \n\nThe game proceeds as follows:\n\n * 6 is not written on the sheet, so write 6.\n\n * 2 is not written on the sheet, so write 2.\n\n * 6 is written on the sheet, so erase 6.\n\nThus, the sheet contains only 2 in the end. The answer is 1.\n\n* * *"}, {"input": "4\n 2\n 5\n 5\n 2", "output": "0\n \n\nIt is possible that no number is written on the sheet in the end.\n\n* * *"}, {"input": "6\n 12\n 22\n 16\n 22\n 18\n 12", "output": "2"}]
|
Print how many numbers will be written on the sheet at the end of the game.
* * *
|
s787843084
|
Accepted
|
p03607
|
Input is given from Standard Input in the following format:
N
A_1
:
A_N
|
def ai():
return input() # s
def a():
return int(input()) # a,n or k
def ma():
return map(int, input().split()) # a,b,c,d or n,k
def ms():
return map(str, input().split()) # ,a,b,c,d
def lma():
return list(map(int, input().split())) # x or y
def lms():
return list(map(str, input().split())) # x or y
k = []
l = []
f = 0
def say(i):
return print("Yes" if i == 0 else "No")
def Say(i):
return print("YES" if i == 0 else "NO")
a = int(input())
c = set()
for i in range(a):
t = int(input())
if t in c:
c.remove(t)
else:
c.add(t)
print(len(c))
|
Statement
You are playing the following game with Joisino.
* Initially, you have a blank sheet of paper.
* Joisino announces a number. If that number is written on the sheet, erase the number from the sheet; if not, write the number on the sheet. This process is repeated N times.
* Then, you are asked a question: How many numbers are written on the sheet now?
The numbers announced by Joisino are given as A_1, ... ,A_N in the order she
announces them. How many numbers will be written on the sheet at the end of
the game?
|
[{"input": "3\n 6\n 2\n 6", "output": "1\n \n\nThe game proceeds as follows:\n\n * 6 is not written on the sheet, so write 6.\n\n * 2 is not written on the sheet, so write 2.\n\n * 6 is written on the sheet, so erase 6.\n\nThus, the sheet contains only 2 in the end. The answer is 1.\n\n* * *"}, {"input": "4\n 2\n 5\n 5\n 2", "output": "0\n \n\nIt is possible that no number is written on the sheet in the end.\n\n* * *"}, {"input": "6\n 12\n 22\n 16\n 22\n 18\n 12", "output": "2"}]
|
Print how many numbers will be written on the sheet at the end of the game.
* * *
|
s725213203
|
Runtime Error
|
p03607
|
Input is given from Standard Input in the following format:
N
A_1
:
A_N
|
n=int(input())
A=set()
for i in range(n):
a=input()
if a in A:
A.remove(a)
else:
A.add(a)
print(len(A)
|
Statement
You are playing the following game with Joisino.
* Initially, you have a blank sheet of paper.
* Joisino announces a number. If that number is written on the sheet, erase the number from the sheet; if not, write the number on the sheet. This process is repeated N times.
* Then, you are asked a question: How many numbers are written on the sheet now?
The numbers announced by Joisino are given as A_1, ... ,A_N in the order she
announces them. How many numbers will be written on the sheet at the end of
the game?
|
[{"input": "3\n 6\n 2\n 6", "output": "1\n \n\nThe game proceeds as follows:\n\n * 6 is not written on the sheet, so write 6.\n\n * 2 is not written on the sheet, so write 2.\n\n * 6 is written on the sheet, so erase 6.\n\nThus, the sheet contains only 2 in the end. The answer is 1.\n\n* * *"}, {"input": "4\n 2\n 5\n 5\n 2", "output": "0\n \n\nIt is possible that no number is written on the sheet in the end.\n\n* * *"}, {"input": "6\n 12\n 22\n 16\n 22\n 18\n 12", "output": "2"}]
|
Print how many numbers will be written on the sheet at the end of the game.
* * *
|
s553505060
|
Runtime Error
|
p03607
|
Input is given from Standard Input in the following format:
N
A_1
:
A_N
|
print(len({int(input()) for i in int(input())}))
|
Statement
You are playing the following game with Joisino.
* Initially, you have a blank sheet of paper.
* Joisino announces a number. If that number is written on the sheet, erase the number from the sheet; if not, write the number on the sheet. This process is repeated N times.
* Then, you are asked a question: How many numbers are written on the sheet now?
The numbers announced by Joisino are given as A_1, ... ,A_N in the order she
announces them. How many numbers will be written on the sheet at the end of
the game?
|
[{"input": "3\n 6\n 2\n 6", "output": "1\n \n\nThe game proceeds as follows:\n\n * 6 is not written on the sheet, so write 6.\n\n * 2 is not written on the sheet, so write 2.\n\n * 6 is written on the sheet, so erase 6.\n\nThus, the sheet contains only 2 in the end. The answer is 1.\n\n* * *"}, {"input": "4\n 2\n 5\n 5\n 2", "output": "0\n \n\nIt is possible that no number is written on the sheet in the end.\n\n* * *"}, {"input": "6\n 12\n 22\n 16\n 22\n 18\n 12", "output": "2"}]
|
Print how many numbers will be written on the sheet at the end of the game.
* * *
|
s618580951
|
Accepted
|
p03607
|
Input is given from Standard Input in the following format:
N
A_1
:
A_N
|
# https://atcoder.jp/contests/abc073/tasks/abc073_c
# 偶数個を抜くだけ
import sys
sys.setrecursionlimit(1 << 25)
read = sys.stdin.readline
ra = range
enu = enumerate
def exit(*argv, **kwarg):
print(*argv, **kwarg)
sys.exit()
def mina(*argv, sub=1):
return list(map(lambda x: x - sub, argv))
# 受け渡されたすべての要素からsubだけ引く.リストを*をつけて展開しておくこと
def a_int():
return int(read())
def read_col(H):
"""H is number of rows
A列、B列が与えられるようなとき
ex1)A,B=read_col(H) ex2) A,=read_col(H) #一列の場合"""
ret = []
for _ in range(H):
ret.append(list(map(int, read().split())))
return tuple(map(list, zip(*ret)))
from collections import Counter
N = a_int()
(A,) = read_col(N)
ans = 0
for v in Counter(A).values():
ans += v & 1
print(ans)
|
Statement
You are playing the following game with Joisino.
* Initially, you have a blank sheet of paper.
* Joisino announces a number. If that number is written on the sheet, erase the number from the sheet; if not, write the number on the sheet. This process is repeated N times.
* Then, you are asked a question: How many numbers are written on the sheet now?
The numbers announced by Joisino are given as A_1, ... ,A_N in the order she
announces them. How many numbers will be written on the sheet at the end of
the game?
|
[{"input": "3\n 6\n 2\n 6", "output": "1\n \n\nThe game proceeds as follows:\n\n * 6 is not written on the sheet, so write 6.\n\n * 2 is not written on the sheet, so write 2.\n\n * 6 is written on the sheet, so erase 6.\n\nThus, the sheet contains only 2 in the end. The answer is 1.\n\n* * *"}, {"input": "4\n 2\n 5\n 5\n 2", "output": "0\n \n\nIt is possible that no number is written on the sheet in the end.\n\n* * *"}, {"input": "6\n 12\n 22\n 16\n 22\n 18\n 12", "output": "2"}]
|
Print how many numbers will be written on the sheet at the end of the game.
* * *
|
s749045408
|
Runtime Error
|
p03607
|
Input is given from Standard Input in the following format:
N
A_1
:
A_N
|
n=int(input())
a=sorted[int(input()) for _ in range(n)]
ans=0
k=1
for i in range(n):
if a[i]==a[i-1]:
k+=1
else:
ans+=k%2
k=1
if a[n-2]==a[n-1]:
ans+=k%2
print(ans)
|
Statement
You are playing the following game with Joisino.
* Initially, you have a blank sheet of paper.
* Joisino announces a number. If that number is written on the sheet, erase the number from the sheet; if not, write the number on the sheet. This process is repeated N times.
* Then, you are asked a question: How many numbers are written on the sheet now?
The numbers announced by Joisino are given as A_1, ... ,A_N in the order she
announces them. How many numbers will be written on the sheet at the end of
the game?
|
[{"input": "3\n 6\n 2\n 6", "output": "1\n \n\nThe game proceeds as follows:\n\n * 6 is not written on the sheet, so write 6.\n\n * 2 is not written on the sheet, so write 2.\n\n * 6 is written on the sheet, so erase 6.\n\nThus, the sheet contains only 2 in the end. The answer is 1.\n\n* * *"}, {"input": "4\n 2\n 5\n 5\n 2", "output": "0\n \n\nIt is possible that no number is written on the sheet in the end.\n\n* * *"}, {"input": "6\n 12\n 22\n 16\n 22\n 18\n 12", "output": "2"}]
|
Print how many numbers will be written on the sheet at the end of the game.
* * *
|
s765433272
|
Runtime Error
|
p03607
|
Input is given from Standard Input in the following format:
N
A_1
:
A_N
|
n=int(input())
a=sorted[int(input()) for _ in range(n)]
ans=0
k=1
for i in range(1,n):
if a[i]==a[i-1]:
k+=1
else:
ans+=k%2
k=1
if a[n-2]==a[n-1]:
ans+=k%2
print(ans)
|
Statement
You are playing the following game with Joisino.
* Initially, you have a blank sheet of paper.
* Joisino announces a number. If that number is written on the sheet, erase the number from the sheet; if not, write the number on the sheet. This process is repeated N times.
* Then, you are asked a question: How many numbers are written on the sheet now?
The numbers announced by Joisino are given as A_1, ... ,A_N in the order she
announces them. How many numbers will be written on the sheet at the end of
the game?
|
[{"input": "3\n 6\n 2\n 6", "output": "1\n \n\nThe game proceeds as follows:\n\n * 6 is not written on the sheet, so write 6.\n\n * 2 is not written on the sheet, so write 2.\n\n * 6 is written on the sheet, so erase 6.\n\nThus, the sheet contains only 2 in the end. The answer is 1.\n\n* * *"}, {"input": "4\n 2\n 5\n 5\n 2", "output": "0\n \n\nIt is possible that no number is written on the sheet in the end.\n\n* * *"}, {"input": "6\n 12\n 22\n 16\n 22\n 18\n 12", "output": "2"}]
|
Print how many numbers will be written on the sheet at the end of the game.
* * *
|
s167220604
|
Runtime Error
|
p03607
|
Input is given from Standard Input in the following format:
N
A_1
:
A_N
|
d = set()
for i in [0] * int(input()):
d ^= {input()}
print(len(p))
|
Statement
You are playing the following game with Joisino.
* Initially, you have a blank sheet of paper.
* Joisino announces a number. If that number is written on the sheet, erase the number from the sheet; if not, write the number on the sheet. This process is repeated N times.
* Then, you are asked a question: How many numbers are written on the sheet now?
The numbers announced by Joisino are given as A_1, ... ,A_N in the order she
announces them. How many numbers will be written on the sheet at the end of
the game?
|
[{"input": "3\n 6\n 2\n 6", "output": "1\n \n\nThe game proceeds as follows:\n\n * 6 is not written on the sheet, so write 6.\n\n * 2 is not written on the sheet, so write 2.\n\n * 6 is written on the sheet, so erase 6.\n\nThus, the sheet contains only 2 in the end. The answer is 1.\n\n* * *"}, {"input": "4\n 2\n 5\n 5\n 2", "output": "0\n \n\nIt is possible that no number is written on the sheet in the end.\n\n* * *"}, {"input": "6\n 12\n 22\n 16\n 22\n 18\n 12", "output": "2"}]
|
Print how many numbers will be written on the sheet at the end of the game.
* * *
|
s870590475
|
Runtime Error
|
p03607
|
Input is given from Standard Input in the following format:
N
A_1
:
A_N
|
print(len(set(list(lambda x: not x % 2, set([input() for i in range(int(input()))])))))
|
Statement
You are playing the following game with Joisino.
* Initially, you have a blank sheet of paper.
* Joisino announces a number. If that number is written on the sheet, erase the number from the sheet; if not, write the number on the sheet. This process is repeated N times.
* Then, you are asked a question: How many numbers are written on the sheet now?
The numbers announced by Joisino are given as A_1, ... ,A_N in the order she
announces them. How many numbers will be written on the sheet at the end of
the game?
|
[{"input": "3\n 6\n 2\n 6", "output": "1\n \n\nThe game proceeds as follows:\n\n * 6 is not written on the sheet, so write 6.\n\n * 2 is not written on the sheet, so write 2.\n\n * 6 is written on the sheet, so erase 6.\n\nThus, the sheet contains only 2 in the end. The answer is 1.\n\n* * *"}, {"input": "4\n 2\n 5\n 5\n 2", "output": "0\n \n\nIt is possible that no number is written on the sheet in the end.\n\n* * *"}, {"input": "6\n 12\n 22\n 16\n 22\n 18\n 12", "output": "2"}]
|
Print how many numbers will be written on the sheet at the end of the game.
* * *
|
s340975452
|
Wrong Answer
|
p03607
|
Input is given from Standard Input in the following format:
N
A_1
:
A_N
|
value_list = []
number_of_test = int(input())
while True:
try:
value = int(input())
value_list.append(value)
# if value_list.count(value) == 2:
# value_list.remove(value)
# value_list.pop()
except EOFError:
break
print(len(value_list))
|
Statement
You are playing the following game with Joisino.
* Initially, you have a blank sheet of paper.
* Joisino announces a number. If that number is written on the sheet, erase the number from the sheet; if not, write the number on the sheet. This process is repeated N times.
* Then, you are asked a question: How many numbers are written on the sheet now?
The numbers announced by Joisino are given as A_1, ... ,A_N in the order she
announces them. How many numbers will be written on the sheet at the end of
the game?
|
[{"input": "3\n 6\n 2\n 6", "output": "1\n \n\nThe game proceeds as follows:\n\n * 6 is not written on the sheet, so write 6.\n\n * 2 is not written on the sheet, so write 2.\n\n * 6 is written on the sheet, so erase 6.\n\nThus, the sheet contains only 2 in the end. The answer is 1.\n\n* * *"}, {"input": "4\n 2\n 5\n 5\n 2", "output": "0\n \n\nIt is possible that no number is written on the sheet in the end.\n\n* * *"}, {"input": "6\n 12\n 22\n 16\n 22\n 18\n 12", "output": "2"}]
|
Print how many numbers will be written on the sheet at the end of the game.
* * *
|
s312733675
|
Runtime Error
|
p03607
|
Input is given from Standard Input in the following format:
N
A_1
:
A_N
|
n = int(input())
a = [int(input()) for _ in range(n)]
a = sorted(a):
tmp = 0
ans = 0
for i in a:
if i == tmp:
ans -= 1
tmp = 0
else:
ans += 1
tmp = i
print(ans)
|
Statement
You are playing the following game with Joisino.
* Initially, you have a blank sheet of paper.
* Joisino announces a number. If that number is written on the sheet, erase the number from the sheet; if not, write the number on the sheet. This process is repeated N times.
* Then, you are asked a question: How many numbers are written on the sheet now?
The numbers announced by Joisino are given as A_1, ... ,A_N in the order she
announces them. How many numbers will be written on the sheet at the end of
the game?
|
[{"input": "3\n 6\n 2\n 6", "output": "1\n \n\nThe game proceeds as follows:\n\n * 6 is not written on the sheet, so write 6.\n\n * 2 is not written on the sheet, so write 2.\n\n * 6 is written on the sheet, so erase 6.\n\nThus, the sheet contains only 2 in the end. The answer is 1.\n\n* * *"}, {"input": "4\n 2\n 5\n 5\n 2", "output": "0\n \n\nIt is possible that no number is written on the sheet in the end.\n\n* * *"}, {"input": "6\n 12\n 22\n 16\n 22\n 18\n 12", "output": "2"}]
|
Print how many numbers will be written on the sheet at the end of the game.
* * *
|
s559782279
|
Runtime Error
|
p03607
|
Input is given from Standard Input in the following format:
N
A_1
:
A_N
|
n = int(input())
a = []
for i in range(n):
a.append(int(input()))
b = list(set(a))
for i in b:
if a.count(i) % 2 == 0:
b.remove(i)
else:
None
print(len(list(b))
|
Statement
You are playing the following game with Joisino.
* Initially, you have a blank sheet of paper.
* Joisino announces a number. If that number is written on the sheet, erase the number from the sheet; if not, write the number on the sheet. This process is repeated N times.
* Then, you are asked a question: How many numbers are written on the sheet now?
The numbers announced by Joisino are given as A_1, ... ,A_N in the order she
announces them. How many numbers will be written on the sheet at the end of
the game?
|
[{"input": "3\n 6\n 2\n 6", "output": "1\n \n\nThe game proceeds as follows:\n\n * 6 is not written on the sheet, so write 6.\n\n * 2 is not written on the sheet, so write 2.\n\n * 6 is written on the sheet, so erase 6.\n\nThus, the sheet contains only 2 in the end. The answer is 1.\n\n* * *"}, {"input": "4\n 2\n 5\n 5\n 2", "output": "0\n \n\nIt is possible that no number is written on the sheet in the end.\n\n* * *"}, {"input": "6\n 12\n 22\n 16\n 22\n 18\n 12", "output": "2"}]
|
Print how many numbers will be written on the sheet at the end of the game.
* * *
|
s305146975
|
Runtime Error
|
p03607
|
Input is given from Standard Input in the following format:
N
A_1
:
A_N
|
import collections
n = int(input())
L = [int(input()) for _ in range(n)]
l = collections.Counter(L)
l_count = l.values()
ans = 0
for i in range(len(l_count)):
if l_cpunt[i] % 2 = 1:
ans += 1
print(ans)
|
Statement
You are playing the following game with Joisino.
* Initially, you have a blank sheet of paper.
* Joisino announces a number. If that number is written on the sheet, erase the number from the sheet; if not, write the number on the sheet. This process is repeated N times.
* Then, you are asked a question: How many numbers are written on the sheet now?
The numbers announced by Joisino are given as A_1, ... ,A_N in the order she
announces them. How many numbers will be written on the sheet at the end of
the game?
|
[{"input": "3\n 6\n 2\n 6", "output": "1\n \n\nThe game proceeds as follows:\n\n * 6 is not written on the sheet, so write 6.\n\n * 2 is not written on the sheet, so write 2.\n\n * 6 is written on the sheet, so erase 6.\n\nThus, the sheet contains only 2 in the end. The answer is 1.\n\n* * *"}, {"input": "4\n 2\n 5\n 5\n 2", "output": "0\n \n\nIt is possible that no number is written on the sheet in the end.\n\n* * *"}, {"input": "6\n 12\n 22\n 16\n 22\n 18\n 12", "output": "2"}]
|
Print how many numbers will be written on the sheet at the end of the game.
* * *
|
s135336958
|
Runtime Error
|
p03607
|
Input is given from Standard Input in the following format:
N
A_1
:
A_N
|
list = []
number = int(input())
for n in range(0,number):
if number in list:
list.remove(number)
else :
list.append(number)
pass
print(Len(list))
|
Statement
You are playing the following game with Joisino.
* Initially, you have a blank sheet of paper.
* Joisino announces a number. If that number is written on the sheet, erase the number from the sheet; if not, write the number on the sheet. This process is repeated N times.
* Then, you are asked a question: How many numbers are written on the sheet now?
The numbers announced by Joisino are given as A_1, ... ,A_N in the order she
announces them. How many numbers will be written on the sheet at the end of
the game?
|
[{"input": "3\n 6\n 2\n 6", "output": "1\n \n\nThe game proceeds as follows:\n\n * 6 is not written on the sheet, so write 6.\n\n * 2 is not written on the sheet, so write 2.\n\n * 6 is written on the sheet, so erase 6.\n\nThus, the sheet contains only 2 in the end. The answer is 1.\n\n* * *"}, {"input": "4\n 2\n 5\n 5\n 2", "output": "0\n \n\nIt is possible that no number is written on the sheet in the end.\n\n* * *"}, {"input": "6\n 12\n 22\n 16\n 22\n 18\n 12", "output": "2"}]
|
Print how many numbers will be written on the sheet at the end of the game.
* * *
|
s290437908
|
Runtime Error
|
p03607
|
Input is given from Standard Input in the following format:
N
A_1
:
A_N
|
N=int(input())
s=set()
for i in range(N):
s^={input()}
print(len(s))
|
Statement
You are playing the following game with Joisino.
* Initially, you have a blank sheet of paper.
* Joisino announces a number. If that number is written on the sheet, erase the number from the sheet; if not, write the number on the sheet. This process is repeated N times.
* Then, you are asked a question: How many numbers are written on the sheet now?
The numbers announced by Joisino are given as A_1, ... ,A_N in the order she
announces them. How many numbers will be written on the sheet at the end of
the game?
|
[{"input": "3\n 6\n 2\n 6", "output": "1\n \n\nThe game proceeds as follows:\n\n * 6 is not written on the sheet, so write 6.\n\n * 2 is not written on the sheet, so write 2.\n\n * 6 is written on the sheet, so erase 6.\n\nThus, the sheet contains only 2 in the end. The answer is 1.\n\n* * *"}, {"input": "4\n 2\n 5\n 5\n 2", "output": "0\n \n\nIt is possible that no number is written on the sheet in the end.\n\n* * *"}, {"input": "6\n 12\n 22\n 16\n 22\n 18\n 12", "output": "2"}]
|
Print how many numbers will be written on the sheet at the end of the game.
* * *
|
s994323094
|
Runtime Error
|
p03607
|
Input is given from Standard Input in the following format:
N
A_1
:
A_N
|
list = []
n = input()
for i range n:
add = input()
if(add in list):
del list(add)
else:
list.append(add)
print(len(list))
|
Statement
You are playing the following game with Joisino.
* Initially, you have a blank sheet of paper.
* Joisino announces a number. If that number is written on the sheet, erase the number from the sheet; if not, write the number on the sheet. This process is repeated N times.
* Then, you are asked a question: How many numbers are written on the sheet now?
The numbers announced by Joisino are given as A_1, ... ,A_N in the order she
announces them. How many numbers will be written on the sheet at the end of
the game?
|
[{"input": "3\n 6\n 2\n 6", "output": "1\n \n\nThe game proceeds as follows:\n\n * 6 is not written on the sheet, so write 6.\n\n * 2 is not written on the sheet, so write 2.\n\n * 6 is written on the sheet, so erase 6.\n\nThus, the sheet contains only 2 in the end. The answer is 1.\n\n* * *"}, {"input": "4\n 2\n 5\n 5\n 2", "output": "0\n \n\nIt is possible that no number is written on the sheet in the end.\n\n* * *"}, {"input": "6\n 12\n 22\n 16\n 22\n 18\n 12", "output": "2"}]
|
Print how many numbers will be written on the sheet at the end of the game.
* * *
|
s558252802
|
Runtime Error
|
p03607
|
Input is given from Standard Input in the following format:
N
A_1
:
A_N
|
list = []
number = int(input())
for n in range(0,number):
if number in list:
list.append(number)
else :
list.remove(number)
pass
print(Len(list))
|
Statement
You are playing the following game with Joisino.
* Initially, you have a blank sheet of paper.
* Joisino announces a number. If that number is written on the sheet, erase the number from the sheet; if not, write the number on the sheet. This process is repeated N times.
* Then, you are asked a question: How many numbers are written on the sheet now?
The numbers announced by Joisino are given as A_1, ... ,A_N in the order she
announces them. How many numbers will be written on the sheet at the end of
the game?
|
[{"input": "3\n 6\n 2\n 6", "output": "1\n \n\nThe game proceeds as follows:\n\n * 6 is not written on the sheet, so write 6.\n\n * 2 is not written on the sheet, so write 2.\n\n * 6 is written on the sheet, so erase 6.\n\nThus, the sheet contains only 2 in the end. The answer is 1.\n\n* * *"}, {"input": "4\n 2\n 5\n 5\n 2", "output": "0\n \n\nIt is possible that no number is written on the sheet in the end.\n\n* * *"}, {"input": "6\n 12\n 22\n 16\n 22\n 18\n 12", "output": "2"}]
|
Print how many numbers will be written on the sheet at the end of the game.
* * *
|
s176957087
|
Runtime Error
|
p03607
|
Input is given from Standard Input in the following format:
N
A_1
:
A_N
|
#!/usr/bin/env python3
import sys
from bisect import bisect_left, bisect_right
from collections.abc import Collection
from typing import Any, Callable, Iterable, Iterator, List, Sequence
ItemGetter = Callable[[Sequence], Any]
class SortedCollection(Collection):
def __init__(self, items: Iterable, key: ItemGetter) -> None:
self._key = key
self._items = sorted(items, key=key)
self._keys = [key(item) for item in self._items]
@property
def key(self) -> ItemGetter:
return self._key
@key.setter
def key(self, key: ItemGetter) -> None:
if key != self.key:
self._key = key
self._items = sorted(self.items, key=key)
self._keys = [key(item) for item in self._items]
@property
def items(self) -> List:
return self._items
@property
def keys(self) -> List:
return self._keys
def clear(self) -> None:
self._key = self.key
self._items = []
def copy(self) -> "SortedCollection":
return self.__class__(self, self.key)
def __len__(self) -> int:
return len(self.items)
def __getitem__(self, i: int) -> Any:
return self.items[i]
def __iter__(self) -> Iterator:
return iter(self.items)
def __reversed__(self) -> Iterator:
return reversed(self.items)
def __repr__(self) -> str:
return "%s(%r, key=%s)" % (
self.__class__.__name__,
self.items,
getattr(self.key, "__name__", repr(self.key)),
)
def __contains__(self, item: Any) -> bool:
k = self.key(item)
i = bisect_left(self.keys, k)
j = bisect_right(self.keys, k)
return item in self.items[i:j]
def index(self, k: int) -> int:
"Find the position of an item. Raise ValueError if not found."
i = bisect_left(self.keys, k)
j = bisect_right(self.keys, k)
return self.keys[i:j].index(k) + i
def count(self, k: int) -> int:
"Return number of occurrences of item"
i = bisect_left(self.keys, k)
j = bisect_right(self.keys, k)
return self.keys[i:j].count(k)
def insert(self, item: Any) -> None:
"Insert a new item. If equal keys are found, add to the left"
k = self.key(item)
i = bisect_left(self.keys, k)
self.keys.insert(i, k)
self.items.insert(i, item)
def insert_right(self, item: Any) -> None:
"Insert a new item. If equal keys are found, add to the right"
k = self.key(item)
i = bisect_right(self.keys, k)
self.keys.insert(i, k)
self.items.insert(i, item)
def remove(self, k: int) -> None:
"Remove first occurence of item. Raise ValueError if not found"
i = self.index(k)
del self.keys[i]
del self.items[i]
def find(self, relation_op: str, k: int) -> Any:
find_func_dict = {
"==": self._find_eq,
">": self._find_gt,
">=": self._find_ge,
"<": self._find_lt,
"<=": self._find_le,
}
return find_func_dict[relation_op](k)
def _find_eq(self, k: int) -> Any:
"Return first item with a key == k. Raise ValueError if not found."
i = bisect_left(self.keys, k)
if i != len(self) and self.keys[i] == k:
return self.items[i]
raise ValueError("No item found with key equal to: %r" % (k,))
def _find_le(self, k: int) -> Any:
"Return last item with a key <= k. Raise ValueError if not found."
i = bisect_right(self.keys, k)
if i:
return self._items[i - 1]
raise ValueError("No item found with key at or below: %r" % (k,))
def _find_lt(self, k: int) -> Any:
"Return last item with a key < k. Raise ValueError if not found."
i = bisect_left(self.keys, k)
if i:
return self._items[i - 1]
raise ValueError("No item found with key below: %r" % (k,))
def _find_ge(self, k: int) -> Any:
"Return first item with a key >= equal to k. Raise ValueError if not found"
i = bisect_left(self.keys, k)
if i != len(self):
return self._items[i]
raise ValueError("No item found with key at or above: %r" % (k,))
def _find_gt(self, k: int) -> Any:
"Return first item with a key > k. Raise ValueError if not found"
i = bisect_right(self.keys, k)
if i != len(self):
return self._items[i]
raise ValueError("No item found with key above: %r" % (k,))
def solve(N: int, A: "List[int]"):
ans = 0
seta = sorted(list(set(A)))
sa = SortedCollection(A, key=lambda x: x)
for a in seta:
if sa.count(a) % 2 != 0:
ans += 1
print(ans)
return
# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools (tips: You use the default template now. You can remove this line by using your custom template)
def main():
def iterate_tokens():
for line in sys.stdin:
for word in line.split():
yield word
tokens = iterate_tokens()
N = int(next(tokens)) # type: int
A = [int(next(tokens)) for _ in range(N)] # type: "List[int]"
solve(N, A)
if __name__ == "__main__":
main()
|
Statement
You are playing the following game with Joisino.
* Initially, you have a blank sheet of paper.
* Joisino announces a number. If that number is written on the sheet, erase the number from the sheet; if not, write the number on the sheet. This process is repeated N times.
* Then, you are asked a question: How many numbers are written on the sheet now?
The numbers announced by Joisino are given as A_1, ... ,A_N in the order she
announces them. How many numbers will be written on the sheet at the end of
the game?
|
[{"input": "3\n 6\n 2\n 6", "output": "1\n \n\nThe game proceeds as follows:\n\n * 6 is not written on the sheet, so write 6.\n\n * 2 is not written on the sheet, so write 2.\n\n * 6 is written on the sheet, so erase 6.\n\nThus, the sheet contains only 2 in the end. The answer is 1.\n\n* * *"}, {"input": "4\n 2\n 5\n 5\n 2", "output": "0\n \n\nIt is possible that no number is written on the sheet in the end.\n\n* * *"}, {"input": "6\n 12\n 22\n 16\n 22\n 18\n 12", "output": "2"}]
|
Print how many numbers will be written on the sheet at the end of the game.
* * *
|
s304386134
|
Runtime Error
|
p03607
|
Input is given from Standard Input in the following format:
N
A_1
:
A_N
|
def duplicate_check(value, value_list):
if value_list.count(value) == 2:
while value in value_list: value_list.remove(value)
return ()value_list
value_list = []
result_list = []
while True:
try:
number_of_test = int(input())
value = int(input()
value_list.append(value)
result_list = duplicate_check(value, value_list)
except EOFError:
break
print(len(result_list))
|
Statement
You are playing the following game with Joisino.
* Initially, you have a blank sheet of paper.
* Joisino announces a number. If that number is written on the sheet, erase the number from the sheet; if not, write the number on the sheet. This process is repeated N times.
* Then, you are asked a question: How many numbers are written on the sheet now?
The numbers announced by Joisino are given as A_1, ... ,A_N in the order she
announces them. How many numbers will be written on the sheet at the end of
the game?
|
[{"input": "3\n 6\n 2\n 6", "output": "1\n \n\nThe game proceeds as follows:\n\n * 6 is not written on the sheet, so write 6.\n\n * 2 is not written on the sheet, so write 2.\n\n * 6 is written on the sheet, so erase 6.\n\nThus, the sheet contains only 2 in the end. The answer is 1.\n\n* * *"}, {"input": "4\n 2\n 5\n 5\n 2", "output": "0\n \n\nIt is possible that no number is written on the sheet in the end.\n\n* * *"}, {"input": "6\n 12\n 22\n 16\n 22\n 18\n 12", "output": "2"}]
|
Print how many numbers will be written on the sheet at the end of the game.
* * *
|
s951949134
|
Runtime Error
|
p03607
|
Input is given from Standard Input in the following format:
N
A_1
:
A_N
|
n = int(input())
paper = []
for _ in range(n):
p = input()
if p not in paper:
paper.append(p)
else:
paper.remove(p)]
print(len(paper) - 1)
|
Statement
You are playing the following game with Joisino.
* Initially, you have a blank sheet of paper.
* Joisino announces a number. If that number is written on the sheet, erase the number from the sheet; if not, write the number on the sheet. This process is repeated N times.
* Then, you are asked a question: How many numbers are written on the sheet now?
The numbers announced by Joisino are given as A_1, ... ,A_N in the order she
announces them. How many numbers will be written on the sheet at the end of
the game?
|
[{"input": "3\n 6\n 2\n 6", "output": "1\n \n\nThe game proceeds as follows:\n\n * 6 is not written on the sheet, so write 6.\n\n * 2 is not written on the sheet, so write 2.\n\n * 6 is written on the sheet, so erase 6.\n\nThus, the sheet contains only 2 in the end. The answer is 1.\n\n* * *"}, {"input": "4\n 2\n 5\n 5\n 2", "output": "0\n \n\nIt is possible that no number is written on the sheet in the end.\n\n* * *"}, {"input": "6\n 12\n 22\n 16\n 22\n 18\n 12", "output": "2"}]
|
Print how many numbers will be written on the sheet at the end of the game.
* * *
|
s724569840
|
Runtime Error
|
p03607
|
Input is given from Standard Input in the following format:
N
A_1
:
A_N
|
n = int(input())
l = [int(input()) _ for in range(n)]
l.sort()
c = 1
t = l[0]
for i in l[1:]:
if t == i:
c += 1
else:
ans += c%2
c = 1
t = i
print(ans)
|
Statement
You are playing the following game with Joisino.
* Initially, you have a blank sheet of paper.
* Joisino announces a number. If that number is written on the sheet, erase the number from the sheet; if not, write the number on the sheet. This process is repeated N times.
* Then, you are asked a question: How many numbers are written on the sheet now?
The numbers announced by Joisino are given as A_1, ... ,A_N in the order she
announces them. How many numbers will be written on the sheet at the end of
the game?
|
[{"input": "3\n 6\n 2\n 6", "output": "1\n \n\nThe game proceeds as follows:\n\n * 6 is not written on the sheet, so write 6.\n\n * 2 is not written on the sheet, so write 2.\n\n * 6 is written on the sheet, so erase 6.\n\nThus, the sheet contains only 2 in the end. The answer is 1.\n\n* * *"}, {"input": "4\n 2\n 5\n 5\n 2", "output": "0\n \n\nIt is possible that no number is written on the sheet in the end.\n\n* * *"}, {"input": "6\n 12\n 22\n 16\n 22\n 18\n 12", "output": "2"}]
|
Print how many numbers will be written on the sheet at the end of the game.
* * *
|
s098472326
|
Runtime Error
|
p03607
|
Input is given from Standard Input in the following format:
N
A_1
:
A_N
|
n=int(input())
buff=set()
for i in range(n):
a=int(input())
if a in buff:
buff.remove(a)
else:
buff.add(a)
print(len(buff))
|
Statement
You are playing the following game with Joisino.
* Initially, you have a blank sheet of paper.
* Joisino announces a number. If that number is written on the sheet, erase the number from the sheet; if not, write the number on the sheet. This process is repeated N times.
* Then, you are asked a question: How many numbers are written on the sheet now?
The numbers announced by Joisino are given as A_1, ... ,A_N in the order she
announces them. How many numbers will be written on the sheet at the end of
the game?
|
[{"input": "3\n 6\n 2\n 6", "output": "1\n \n\nThe game proceeds as follows:\n\n * 6 is not written on the sheet, so write 6.\n\n * 2 is not written on the sheet, so write 2.\n\n * 6 is written on the sheet, so erase 6.\n\nThus, the sheet contains only 2 in the end. The answer is 1.\n\n* * *"}, {"input": "4\n 2\n 5\n 5\n 2", "output": "0\n \n\nIt is possible that no number is written on the sheet in the end.\n\n* * *"}, {"input": "6\n 12\n 22\n 16\n 22\n 18\n 12", "output": "2"}]
|
Print how many numbers will be written on the sheet at the end of the game.
* * *
|
s709533013
|
Wrong Answer
|
p03607
|
Input is given from Standard Input in the following format:
N
A_1
:
A_N
|
print(len({int(input()) for i in range(int(input()))}))
|
Statement
You are playing the following game with Joisino.
* Initially, you have a blank sheet of paper.
* Joisino announces a number. If that number is written on the sheet, erase the number from the sheet; if not, write the number on the sheet. This process is repeated N times.
* Then, you are asked a question: How many numbers are written on the sheet now?
The numbers announced by Joisino are given as A_1, ... ,A_N in the order she
announces them. How many numbers will be written on the sheet at the end of
the game?
|
[{"input": "3\n 6\n 2\n 6", "output": "1\n \n\nThe game proceeds as follows:\n\n * 6 is not written on the sheet, so write 6.\n\n * 2 is not written on the sheet, so write 2.\n\n * 6 is written on the sheet, so erase 6.\n\nThus, the sheet contains only 2 in the end. The answer is 1.\n\n* * *"}, {"input": "4\n 2\n 5\n 5\n 2", "output": "0\n \n\nIt is possible that no number is written on the sheet in the end.\n\n* * *"}, {"input": "6\n 12\n 22\n 16\n 22\n 18\n 12", "output": "2"}]
|
Print how many numbers will be written on the sheet at the end of the game.
* * *
|
s849050350
|
Wrong Answer
|
p03607
|
Input is given from Standard Input in the following format:
N
A_1
:
A_N
|
j = [int(input()) for i in range(int(input()))]
print(len(set(filter(lambda x: j.count(x) % 2 == 0, j))))
|
Statement
You are playing the following game with Joisino.
* Initially, you have a blank sheet of paper.
* Joisino announces a number. If that number is written on the sheet, erase the number from the sheet; if not, write the number on the sheet. This process is repeated N times.
* Then, you are asked a question: How many numbers are written on the sheet now?
The numbers announced by Joisino are given as A_1, ... ,A_N in the order she
announces them. How many numbers will be written on the sheet at the end of
the game?
|
[{"input": "3\n 6\n 2\n 6", "output": "1\n \n\nThe game proceeds as follows:\n\n * 6 is not written on the sheet, so write 6.\n\n * 2 is not written on the sheet, so write 2.\n\n * 6 is written on the sheet, so erase 6.\n\nThus, the sheet contains only 2 in the end. The answer is 1.\n\n* * *"}, {"input": "4\n 2\n 5\n 5\n 2", "output": "0\n \n\nIt is possible that no number is written on the sheet in the end.\n\n* * *"}, {"input": "6\n 12\n 22\n 16\n 22\n 18\n 12", "output": "2"}]
|
Print how many numbers will be written on the sheet at the end of the game.
* * *
|
s365099981
|
Accepted
|
p03607
|
Input is given from Standard Input in the following format:
N
A_1
:
A_N
|
import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
from math import *
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
# sys.setrecursionlimit(int(pow(10, 2)))
# sys.stdin = open("input.txt", "r")
# sys.stdout = open("output.txt", "w")
mod = int(pow(10, 9) + 7)
mod2 = 998244353
def data():
return sys.stdin.readline().strip()
def out(*var, end="\n"):
sys.stdout.write(" ".join(map(str, var)) + end)
def l():
return list(sp())
def sl():
return list(ssp())
def sp():
return map(int, data().split())
def ssp():
return map(str, data().split())
def l1d(n, val=0):
return [val for i in range(n)]
def l2d(n, m, val=0):
return [l1d(n, val) for j in range(m)]
# @lru_cache(None)
N = l()[0]
s = set()
for i in range(N):
a = l()[0]
if a in s:
s.discard(a)
else:
s.add(a)
print(len(s))
|
Statement
You are playing the following game with Joisino.
* Initially, you have a blank sheet of paper.
* Joisino announces a number. If that number is written on the sheet, erase the number from the sheet; if not, write the number on the sheet. This process is repeated N times.
* Then, you are asked a question: How many numbers are written on the sheet now?
The numbers announced by Joisino are given as A_1, ... ,A_N in the order she
announces them. How many numbers will be written on the sheet at the end of
the game?
|
[{"input": "3\n 6\n 2\n 6", "output": "1\n \n\nThe game proceeds as follows:\n\n * 6 is not written on the sheet, so write 6.\n\n * 2 is not written on the sheet, so write 2.\n\n * 6 is written on the sheet, so erase 6.\n\nThus, the sheet contains only 2 in the end. The answer is 1.\n\n* * *"}, {"input": "4\n 2\n 5\n 5\n 2", "output": "0\n \n\nIt is possible that no number is written on the sheet in the end.\n\n* * *"}, {"input": "6\n 12\n 22\n 16\n 22\n 18\n 12", "output": "2"}]
|
Print the number of possible passwords.
* * *
|
s509503794
|
Runtime Error
|
p02915
|
Input is given from Standard Input in the following format:
N
|
print = input() ** 3
|
Statement
Takahashi is going to set a 3-character password.
How many possible passwords are there if each of its characters must be a
digit between 1 and N (inclusive)?
|
[{"input": "2", "output": "8\n \n\nThere are eight possible passwords: `111`, `112`, `121`, `122`, `211`, `212`,\n`221`, and `222`.\n\n* * *"}, {"input": "1", "output": "1\n \n\nThere is only one possible password if you can only use one kind of character."}]
|
Print the number of possible passwords.
* * *
|
s026166395
|
Runtime Error
|
p02915
|
Input is given from Standard Input in the following format:
N
|
print(2 ** int(input))
|
Statement
Takahashi is going to set a 3-character password.
How many possible passwords are there if each of its characters must be a
digit between 1 and N (inclusive)?
|
[{"input": "2", "output": "8\n \n\nThere are eight possible passwords: `111`, `112`, `121`, `122`, `211`, `212`,\n`221`, and `222`.\n\n* * *"}, {"input": "1", "output": "1\n \n\nThere is only one possible password if you can only use one kind of character."}]
|
Print the number of possible passwords.
* * *
|
s300895730
|
Runtime Error
|
p02915
|
Input is given from Standard Input in the following format:
N
|
print((input()) ^ 3)
|
Statement
Takahashi is going to set a 3-character password.
How many possible passwords are there if each of its characters must be a
digit between 1 and N (inclusive)?
|
[{"input": "2", "output": "8\n \n\nThere are eight possible passwords: `111`, `112`, `121`, `122`, `211`, `212`,\n`221`, and `222`.\n\n* * *"}, {"input": "1", "output": "1\n \n\nThere is only one possible password if you can only use one kind of character."}]
|
Print the number of possible passwords.
* * *
|
s000345723
|
Accepted
|
p02915
|
Input is given from Standard Input in the following format:
N
|
m = int(input())
print(m**3)
|
Statement
Takahashi is going to set a 3-character password.
How many possible passwords are there if each of its characters must be a
digit between 1 and N (inclusive)?
|
[{"input": "2", "output": "8\n \n\nThere are eight possible passwords: `111`, `112`, `121`, `122`, `211`, `212`,\n`221`, and `222`.\n\n* * *"}, {"input": "1", "output": "1\n \n\nThere is only one possible password if you can only use one kind of character."}]
|
Print the number of possible passwords.
* * *
|
s005712232
|
Runtime Error
|
p02915
|
Input is given from Standard Input in the following format:
N
|
n, k = map(int, input().split())
s = list(input())
RL = 0
LR = 0
fo = 0
if n < 3:
if n == 1:
print(0)
else:
print(1)
else:
for i in range(n):
if s[i] == "R" and i < n - 1:
if s[i + 1] == "R":
fo += 1
if s[i] == "L" and 0 < i:
if s[i - 1] == "L":
fo += 1
if i < n - 1:
if s[i] == "R" and s[i + 1] == "L":
RL += 1
elif s[i] == "L" and s[i + 1] == "R":
LR += 1
si = min(k, RL, LR)
no = k - si
LR_rest = LR - si
RL_rest = RL - si
if no == 0:
ans = fo + si * 2
else:
ans = fo + si * 2
if s[0] == "L":
if LR_rest > 0:
ans += 1
LR_rest -= 1
no -= 1
if no > 0:
if s[-1] == "R":
if LR_rest > 0:
ans += 1
print(ans)
|
Statement
Takahashi is going to set a 3-character password.
How many possible passwords are there if each of its characters must be a
digit between 1 and N (inclusive)?
|
[{"input": "2", "output": "8\n \n\nThere are eight possible passwords: `111`, `112`, `121`, `122`, `211`, `212`,\n`221`, and `222`.\n\n* * *"}, {"input": "1", "output": "1\n \n\nThere is only one possible password if you can only use one kind of character."}]
|
Print the number of possible passwords.
* * *
|
s080015648
|
Wrong Answer
|
p02915
|
Input is given from Standard Input in the following format:
N
|
inp = int(input(">"))
print(inp**3)
|
Statement
Takahashi is going to set a 3-character password.
How many possible passwords are there if each of its characters must be a
digit between 1 and N (inclusive)?
|
[{"input": "2", "output": "8\n \n\nThere are eight possible passwords: `111`, `112`, `121`, `122`, `211`, `212`,\n`221`, and `222`.\n\n* * *"}, {"input": "1", "output": "1\n \n\nThere is only one possible password if you can only use one kind of character."}]
|
Print the number of possible passwords.
* * *
|
s445773585
|
Runtime Error
|
p02915
|
Input is given from Standard Input in the following format:
N
|
class WeightBalancedTree:
def __init__(self, q):
self.left = [0] * (q + 1)
self.right = [0] * (q + 1)
self.weight = [1] * (q + 1)
self.key = [None] * (q + 1)
self.last_index = 0
self.root = 0
# key 未満の最大値
def search_lower(self, key):
if key == None:
return None
ret = None
idx = self.root
while idx != 0:
if self.key[idx] < key:
ret = self.key[idx]
idx = self.right[idx]
else:
idx = self.left[idx]
return ret
# key 超過の最小値
def search_higher(self, key):
if key == None:
return None
ret = None
idx = self.root
while idx != 0:
if self.key[idx] > key:
ret = self.key[idx]
idx = self.left[idx]
else:
idx = self.right[idx]
return ret
# 要素の挿入
# 重複を考慮しない
# ToDo: 考慮するものも実装する
def insert(self, key):
self.last_index += 1
self.key[self.last_index] = key
self.weight[self.last_index] = 2
self.root = self.__recursive_insert(self.root)
# insert の再帰実装に用いる
def __recursive_insert(self, idx):
if idx == 0:
return self.last_index
elif self.key[self.last_index] < self.key[idx]:
self.left[idx] = self.__recursive_insert(self.left[idx])
self.__fix(idx)
return self.__fix_left_bias(idx)
else:
self.right[idx] = self.__recursive_insert(self.right[idx])
self.__fix(idx)
return self.__fix_right_bias(idx)
# ノードの weight を補正する
def __fix(self, idx):
self.weight[idx] = self.weight[self.left[idx]] + self.weight[self.right[idx]]
# 左回転
def __rotate_left(self, idx):
right = self.right[idx]
self.right[idx] = self.left[right]
self.__fix(idx)
self.left[right] = idx
self.__fix(right)
return right
# 右回転
def __rotate_right(self, idx):
left = self.left[idx]
self.left[idx] = self.right[left]
self.__fix(idx)
self.right[left] = idx
self.__fix(left)
return left
# 左偏状態の補正
def __fix_left_bias(self, idx):
if self.weight[self.right[idx]] << 2 < self.weight[idx]:
left = self.left[idx]
if self.weight[self.left[left]] << 2 < self.weight[left]:
self.left[idx] = self.__rotate_left(left)
idx = self.__rotate_right(idx)
return idx
# 右偏状態の補正
def __fix_right_bias(self, idx):
if self.weight[self.left[idx]] << 2 < self.weight[idx]:
right = self.right[idx]
if self.weight[self.right[right]] << 2 < self.weight[right]:
self.right[idx] = self.__rotate_right(right)
idx = self.__rotate_left(idx)
return idx
# 要素数
def size(self):
return self.weight[self.root] - 1
# デバッグ用
def dump(self):
self.__dump(self.root, 0)
def __dump(self, idx, dep):
if idx != 0:
self.__dump(self.right[idx], dep + 1)
for _ in range(0, dep):
print(" ", end="")
print(
"i:{0},k:{1},l:{2},r:{3},w:{4}".format(
idx,
self.key[idx],
self.left[idx],
self.right[idx],
self.weight[idx],
)
)
self.__dump(self.left[idx], dep + 1)
def main():
n = int(input())
p = list(map(int, input().split()))
idx = [0] * n
for i in range(0, n):
idx[i] = i
idx.sort(key=lambda i: -p[i])
t = WeightBalancedTree(n + 2)
t.insert(-1)
t.insert(n)
ans = 0
for i in idx:
nex = t.search_higher(i)
nexnex = t.search_higher(nex)
pre = t.search_lower(i)
prepre = t.search_lower(pre)
if prepre != None:
ans += p[i] * (pre - prepre) * (nex - i)
if nexnex != None:
ans += p[i] * (i - pre) * (nexnex - nex)
t.insert(i)
print(ans)
main()
|
Statement
Takahashi is going to set a 3-character password.
How many possible passwords are there if each of its characters must be a
digit between 1 and N (inclusive)?
|
[{"input": "2", "output": "8\n \n\nThere are eight possible passwords: `111`, `112`, `121`, `122`, `211`, `212`,\n`221`, and `222`.\n\n* * *"}, {"input": "1", "output": "1\n \n\nThere is only one possible password if you can only use one kind of character."}]
|
Print the number of possible passwords.
* * *
|
s175691259
|
Runtime Error
|
p02915
|
Input is given from Standard Input in the following format:
N
|
N = int(input())
P = [None] + list(map(int, input().split()))
p_to_index = [None] * (N + 1)
for index, x in enumerate(P[1:], 1):
p_to_index[x] = index
def BIT_add(i):
while i <= N:
tree[i] += 1
i += i & (-i)
def BIT_sum(i):
s = 0
while i:
s += tree[i]
i -= i & (-i)
return s
def BIT_search(x):
i = 0
s = 0
step = 1 << (len(bin(N)[2:]) - 1)
while step:
if i + step <= N and s + tree[i + step] < x:
i += step
s += tree[i]
step >>= 1
return i + 1
tree = [0] * (N + 1)
ans = 0
for x in range(N, 0, -1):
c = p_to_index[x]
L = BIT_sum(c)
R = N - x - L
a = BIT_search(L - 1) if L >= 2 else 0
b = BIT_search(L) if L >= 1 else 0
d = BIT_search(L + 1) if R >= 1 else N + 1
e = BIT_search(L + 2) if R >= 2 else N + 1
BIT_add(c)
ans += x * ((b - a) * (d - c) + (e - d) * (c - b))
print(ans)
|
Statement
Takahashi is going to set a 3-character password.
How many possible passwords are there if each of its characters must be a
digit between 1 and N (inclusive)?
|
[{"input": "2", "output": "8\n \n\nThere are eight possible passwords: `111`, `112`, `121`, `122`, `211`, `212`,\n`221`, and `222`.\n\n* * *"}, {"input": "1", "output": "1\n \n\nThere is only one possible password if you can only use one kind of character."}]
|
Print the number of possible passwords.
* * *
|
s805878973
|
Wrong Answer
|
p02915
|
Input is given from Standard Input in the following format:
N
|
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
from operator import itemgetter
from bisect import bisect, insort
def solve(n, ppp):
q = sorted(enumerate(ppp), key=itemgetter(1), reverse=True)
le = [-1, -1, n - 1, n, n]
ans = 0
for i, p in q[1:]:
l_i = bisect(le, i)
LL = le[l_i - 2]
LR = le[l_i - 1]
RL = le[l_i]
RR = le[l_i + 1]
ans += p * ((LR - LL) * (RL - i) + (RR - RL) * (i - LR))
insort(le, i)
return ans
n = int(readline())
ppp = list(map(int, readline().split()))
print(solve(n, ppp))
|
Statement
Takahashi is going to set a 3-character password.
How many possible passwords are there if each of its characters must be a
digit between 1 and N (inclusive)?
|
[{"input": "2", "output": "8\n \n\nThere are eight possible passwords: `111`, `112`, `121`, `122`, `211`, `212`,\n`221`, and `222`.\n\n* * *"}, {"input": "1", "output": "1\n \n\nThere is only one possible password if you can only use one kind of character."}]
|
Print the number of possible passwords.
* * *
|
s858243607
|
Runtime Error
|
p02915
|
Input is given from Standard Input in the following format:
N
|
import sys
def input():
return sys.stdin.readline()[:-1]
class SegmentTree:
def __init__(self, L, op, ide):
self.op = op
self.ide = ide
self.sz = len(L)
self.n = 1
self.s = 1
for i in range(1000):
self.n *= 2
self.s += 1
if self.n >= self.sz:
break
self.node = [self.ide] * (2 * self.n - 1)
for i in range(self.sz):
self.node[i + self.n - 1] = L[i]
for i in range(self.n - 2, -1, -1):
self.node[i] = self.op(self.node[i * 2 + 1], self.node[i * 2 + 2])
def add(self, a, x):
k = a + self.n - 1
self.node[k] += x
for i in range(1000):
k = (k - 1) // 2
self.node[k] = self.op(self.node[2 * k + 1], self.node[2 * k + 2])
if k <= 0:
break
def substitute(self, a, x):
k = a + self.n - 1
self.node[k] = x
for i in range(1000):
k = (k - 1) // 2
self.node[k] = self.op(self.node[2 * k + 1], self.node[2 * k + 2])
if k <= 0:
break
def get_one(self, a):
k = a + self.n - 1
return self.node[k]
def get(self, l, r):
res = self.ide
n = self.n
if self.sz <= r or 0 > l:
print("ERROR: the indice are wrong.")
return False
for i in range(self.s):
count = 2**i - 1
a = (r + 1) // n
b = (l - 1) // n
if a - b == 3:
res = self.op(self.node[count + b + 1], res)
res = self.op(self.node[count + b + 2], res)
right = a * n
left = (b + 1) * n - 1
break
if a - b == 2:
res = self.op(self.node[count + b + 1], res)
right = a * n
left = (b + 1) * n - 1
break
n = n // 2
# left
n1 = n // 2
for j in range(i + 1, self.s):
count = 2**j - 1
a = (left + 1) // n1
b = (l - 1) // n1
if a - b == 2:
res = self.op(self.node[count + b + 1], res)
left = (b + 1) * n1 - 1
n1 = n1 // 2
# right
n1 = n // 2
for j in range(i + 1, self.s):
count = 2**j - 1
a = (r + 1) // n1
b = (right - 1) // n1
if a - b == 2:
res = self.op(self.node[count + b + 1], res)
right = a * n1
n1 = n1 // 2
return res
def main():
N = int(input())
P = list(map(int, input().split()))
ST = SegmentTree(P, max, -(10**27))
def bisect(i, j, ST, num, index, P, Smin, Smin_rev, left_flag):
if left_flag:
if i == j:
if P[i] > num:
return i
else:
return i - 1
if Smin[j + 1] == num:
return -1
if P[j] > num:
return j
else:
if i == j:
if P[i] > num:
return i
else:
return i + 1
if Smin_rev[i - 1] == num:
return N
if P[i] > num:
return i
if not left_flag:
while j - i > 1:
if ST.get(index + 1, (i + j) // 2) < num:
i = (i + j) // 2
else:
j = (i + j) // 2
return j
else:
while j - i > 1:
if ST.get((i + j) // 2, index - 1) < num:
j = (i + j) // 2
else:
i = (i + j) // 2
return i
Smin = []
smin = -(10**27)
for i in range(N):
smin = max(smin, P[i])
Smin.append(smin)
Smin_rev = []
smin = -(10**27)
for i in range(N):
smin = max(smin, P[N - i - 1])
Smin_rev.append(smin)
Smin_rev = Smin_rev[::-1]
score = 0
for i in range(N):
if i == 0:
right1 = bisect(i + 1, N - 1, ST, P[i], i, P, Smin, Smin_rev, False)
if right1 >= N - 1:
right2 = N
else:
right2 = bisect(
right1 + 1, N - 1, ST, P[i], right1, P, Smin, Smin_rev, False
)
right1, right2 = right1 - i, right2 - i
left1 = 1
left2 = 1
elif i == N - 1:
left1 = bisect(0, i - 1, ST, P[i], i, P, Smin, Smin_rev, True)
if left1 <= 0:
left2 = -1
else:
left2 = bisect(0, left1 - 1, ST, P[i], left1, P, Smin, Smin_rev, True)
left1, left2 = i - left1, i - left2
right1 = 1
right2 = 1
else:
right1 = bisect(i + 1, N - 1, ST, P[i], i, P, Smin, Smin_rev, False)
if right1 >= N - 1:
right2 = N
else:
right2 = bisect(
right1 + 1, N - 1, ST, P[i], right1, P, Smin, Smin_rev, False
)
right1, right2 = right1 - i, right2 - i
left1 = bisect(0, i - 1, ST, P[i], i, P, Smin, Smin_rev, True)
if left1 <= 0:
left2 = -1
else:
left2 = bisect(0, left1 - 1, ST, P[i], left1, P, Smin, Smin_rev, True)
left1, left2 = i - left1, i - left2
score += (left1 * (right2 - right1) + (left2 - left1) * right1) * P[i]
print(score)
main()
|
Statement
Takahashi is going to set a 3-character password.
How many possible passwords are there if each of its characters must be a
digit between 1 and N (inclusive)?
|
[{"input": "2", "output": "8\n \n\nThere are eight possible passwords: `111`, `112`, `121`, `122`, `211`, `212`,\n`221`, and `222`.\n\n* * *"}, {"input": "1", "output": "1\n \n\nThere is only one possible password if you can only use one kind of character."}]
|
Print the number of possible passwords.
* * *
|
s003341653
|
Accepted
|
p02915
|
Input is given from Standard Input in the following format:
N
|
x = int(input())
print(x**3)
|
Statement
Takahashi is going to set a 3-character password.
How many possible passwords are there if each of its characters must be a
digit between 1 and N (inclusive)?
|
[{"input": "2", "output": "8\n \n\nThere are eight possible passwords: `111`, `112`, `121`, `122`, `211`, `212`,\n`221`, and `222`.\n\n* * *"}, {"input": "1", "output": "1\n \n\nThere is only one possible password if you can only use one kind of character."}]
|
Print the number of possible passwords.
* * *
|
s804426405
|
Accepted
|
p02915
|
Input is given from Standard Input in the following format:
N
|
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(n**3)
|
Statement
Takahashi is going to set a 3-character password.
How many possible passwords are there if each of its characters must be a
digit between 1 and N (inclusive)?
|
[{"input": "2", "output": "8\n \n\nThere are eight possible passwords: `111`, `112`, `121`, `122`, `211`, `212`,\n`221`, and `222`.\n\n* * *"}, {"input": "1", "output": "1\n \n\nThere is only one possible password if you can only use one kind of character."}]
|
Print the number of possible passwords.
* * *
|
s123473170
|
Runtime Error
|
p02915
|
Input is given from Standard Input in the following format:
N
|
N, K = map(int, input().split())
S = list(input())
p = 0
while K > 0 and p < len(S):
now = S[p]
p += 1
if p >= len(S):
break
while now == S[p]:
p += 1
if p >= len(S):
break
q = p + 1
if q >= len(S):
"""
if S[p] == "R":
S[p] = "L"
else:
S[p] = "R"
"""
break
while S[p] == S[q]:
q += 1
if q >= len(S):
break
while p < q:
if S[p] == "R":
S[p] = "L"
else:
S[p] = "R"
p += 1
if p >= len(S):
break
K -= 1
ret = 0
print(len(S))
for x in range(len(S) - 1):
print(x)
if S[x] == S[x + 1]:
ret += 1
print(ret)
|
Statement
Takahashi is going to set a 3-character password.
How many possible passwords are there if each of its characters must be a
digit between 1 and N (inclusive)?
|
[{"input": "2", "output": "8\n \n\nThere are eight possible passwords: `111`, `112`, `121`, `122`, `211`, `212`,\n`221`, and `222`.\n\n* * *"}, {"input": "1", "output": "1\n \n\nThere is only one possible password if you can only use one kind of character."}]
|
Print the number of possible passwords.
* * *
|
s516725166
|
Runtime Error
|
p02915
|
Input is given from Standard Input in the following format:
N
|
class SegTree:
def __init__(self, init_val, n, ide_ele, seg_func):
self.segfunc = seg_func
self.num = 2 ** (n - 1).bit_length()
self.ide_ele = ide_ele
self.seg = [self.ide_ele] * 2 * self.num
for i in range(n):
self.seg[i + self.num - 1] = init_val[i]
for i in range(self.num - 2, -1, -1):
self.seg[i] = self.segfunc(self.seg[2 * i + 1], self.seg[2 * i + 2])
def update(self, k, x):
k += self.num - 1
self.seg[k] = x
while k + 1:
k = (k - 1) // 2
self.seg[k] = self.segfunc(self.seg[k * 2 + 1], self.seg[k * 2 + 2])
def query(self, p, q):
if q <= p:
return self.ide_ele
p += self.num - 1
q += self.num - 2
res = self.ide_ele
while q - p > 1:
if p & 1 == 0:
res = self.segfunc(res, self.seg[p])
if q & 1 == 1:
res = self.segfunc(res, self.seg[q])
q -= 1
p = p // 2
q = (q - 1) // 2
if p == q:
res = self.segfunc(res, self.seg[p])
else:
res = self.segfunc(self.segfunc(res, self.seg[p]), self.seg[q])
return res
n = int(input())
xs = list(map(int, input().split()))
x2i = {}
for i, x in enumerate(xs):
x2i[x] = i
ss1 = SegTree([n] * n, n, n, min)
ss2 = SegTree([-1] * n, n, -1, max)
r = 0
for x in range(n):
x = n - x
rmi2 = ss1.query(x2i[x] + 1, n)
if rmi2 != n:
ss1.update(rmi2, n)
rmi = ss1.query(x2i[x] + 1, n)
if rmi2 != n:
ss1.update(rmi2, rmi2)
lmi = ss2.query(0, x2i[x])
if lmi != -1:
ss2.update(lmi, -1)
lmi2 = ss2.query(0, x2i[x])
if lmi != -1:
ss2.update(lmi, lmi)
a, b, c, d = (x2i[x] - lmi), (lmi - lmi2), (rmi - rmi2), (rmi2 - x2i[x])
r += (a * c + b * d) * x
# print(x, r)
# print(rmi, rmi2, lmi, lmi2)
ss1.update(x2i[x], x2i[x])
ss2.update(x2i[x], x2i[x])
print(r)
|
Statement
Takahashi is going to set a 3-character password.
How many possible passwords are there if each of its characters must be a
digit between 1 and N (inclusive)?
|
[{"input": "2", "output": "8\n \n\nThere are eight possible passwords: `111`, `112`, `121`, `122`, `211`, `212`,\n`221`, and `222`.\n\n* * *"}, {"input": "1", "output": "1\n \n\nThere is only one possible password if you can only use one kind of character."}]
|
Print the number of possible passwords.
* * *
|
s607938992
|
Accepted
|
p02915
|
Input is given from Standard Input in the following format:
N
|
print(pow(int(input()), 3))
|
Statement
Takahashi is going to set a 3-character password.
How many possible passwords are there if each of its characters must be a
digit between 1 and N (inclusive)?
|
[{"input": "2", "output": "8\n \n\nThere are eight possible passwords: `111`, `112`, `121`, `122`, `211`, `212`,\n`221`, and `222`.\n\n* * *"}, {"input": "1", "output": "1\n \n\nThere is only one possible password if you can only use one kind of character."}]
|
Print the number of possible passwords.
* * *
|
s299592114
|
Wrong Answer
|
p02915
|
Input is given from Standard Input in the following format:
N
|
print((int(input())) * 3)
|
Statement
Takahashi is going to set a 3-character password.
How many possible passwords are there if each of its characters must be a
digit between 1 and N (inclusive)?
|
[{"input": "2", "output": "8\n \n\nThere are eight possible passwords: `111`, `112`, `121`, `122`, `211`, `212`,\n`221`, and `222`.\n\n* * *"}, {"input": "1", "output": "1\n \n\nThere is only one possible password if you can only use one kind of character."}]
|
Print the number of possible passwords.
* * *
|
s138743059
|
Accepted
|
p02915
|
Input is given from Standard Input in the following format:
N
|
t = int(input())
print(int(t**3))
|
Statement
Takahashi is going to set a 3-character password.
How many possible passwords are there if each of its characters must be a
digit between 1 and N (inclusive)?
|
[{"input": "2", "output": "8\n \n\nThere are eight possible passwords: `111`, `112`, `121`, `122`, `211`, `212`,\n`221`, and `222`.\n\n* * *"}, {"input": "1", "output": "1\n \n\nThere is only one possible password if you can only use one kind of character."}]
|
Print the number of possible passwords.
* * *
|
s866934005
|
Wrong Answer
|
p02915
|
Input is given from Standard Input in the following format:
N
|
integer = int(input("N"))
times = integer * integer * integer
print(times)
|
Statement
Takahashi is going to set a 3-character password.
How many possible passwords are there if each of its characters must be a
digit between 1 and N (inclusive)?
|
[{"input": "2", "output": "8\n \n\nThere are eight possible passwords: `111`, `112`, `121`, `122`, `211`, `212`,\n`221`, and `222`.\n\n* * *"}, {"input": "1", "output": "1\n \n\nThere is only one possible password if you can only use one kind of character."}]
|
Print the number of possible passwords.
* * *
|
s926749779
|
Accepted
|
p02915
|
Input is given from Standard Input in the following format:
N
|
def solve():
data = read()
result = think(data)
write(result)
def read():
return read_int(1)[0]
def read_int(n):
return list(map(lambda x: int(x), read_line().split(" ")))[:n]
def read_float(n):
return list(map(lambda x: float(x), read_line().split(" ")))[:n]
def read_line(n=0):
if n == 0:
return input().rstrip()
else:
return input().rstrip()[:n]
def think(data):
return data**3
def write(result):
print(result)
if __name__ == "__main__":
# import doctest
# doctest.testmod()
# import sys
# sys.setrecursionlimit(10000)
solve()
|
Statement
Takahashi is going to set a 3-character password.
How many possible passwords are there if each of its characters must be a
digit between 1 and N (inclusive)?
|
[{"input": "2", "output": "8\n \n\nThere are eight possible passwords: `111`, `112`, `121`, `122`, `211`, `212`,\n`221`, and `222`.\n\n* * *"}, {"input": "1", "output": "1\n \n\nThere is only one possible password if you can only use one kind of character."}]
|
Print the number of possible passwords.
* * *
|
s614009887
|
Accepted
|
p02915
|
Input is given from Standard Input in the following format:
N
|
# -*- 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 list4d(a, b, c, d, e):
return [[[[e] * d for j in range(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
N = INT()
print(N**3)
|
Statement
Takahashi is going to set a 3-character password.
How many possible passwords are there if each of its characters must be a
digit between 1 and N (inclusive)?
|
[{"input": "2", "output": "8\n \n\nThere are eight possible passwords: `111`, `112`, `121`, `122`, `211`, `212`,\n`221`, and `222`.\n\n* * *"}, {"input": "1", "output": "1\n \n\nThere is only one possible password if you can only use one kind of character."}]
|
Print the number of possible passwords.
* * *
|
s832177321
|
Runtime Error
|
p02915
|
Input is given from Standard Input in the following format:
N
|
N, K = map(int, input().split())
S = input()
H0 = 0
N_LR = 0
N_RL = 0
if S[0] == "R" and S[1] == "R":
H0 += 1
if S[0] == "R" and S[1] == "L":
N_RL += 1
if S[0] == "L" and S[1] == "R":
N_LR += 1
if S[N - 1] == "L" and S[N - 2] == "L":
H0 += 1
for i in range(1, N - 1):
if S[i] == "L" and S[i - 1] == "L" or S[i] == "R" and S[i + 1] == "R":
H0 += 1
if S[i] == "R" and S[i + 1] == "L":
N_RL += 1
if S[i] == "L" and S[i + 1] == "R":
N_LR += 1
M = min(N_RL, N_LR, K)
H1 = H0 + 2 * M
K -= M
N_RL -= M
N_LR -= M
result = H1 + min(K, max(N_RL, N_LR))
print(result)
|
Statement
Takahashi is going to set a 3-character password.
How many possible passwords are there if each of its characters must be a
digit between 1 and N (inclusive)?
|
[{"input": "2", "output": "8\n \n\nThere are eight possible passwords: `111`, `112`, `121`, `122`, `211`, `212`,\n`221`, and `222`.\n\n* * *"}, {"input": "1", "output": "1\n \n\nThere is only one possible password if you can only use one kind of character."}]
|
Print the number of possible passwords.
* * *
|
s763339327
|
Runtime Error
|
p02915
|
Input is given from Standard Input in the following format:
N
|
n = int(input())
b = list(map(int, input().split()))
sum = 0
for i in range(n - 1):
first = b[i]
second = 0
for j in range(i + 1, n):
if second < b[j]:
if first < b[j]:
second = first
first = b[j]
else:
second = b[j]
sum += second
print(sum)
|
Statement
Takahashi is going to set a 3-character password.
How many possible passwords are there if each of its characters must be a
digit between 1 and N (inclusive)?
|
[{"input": "2", "output": "8\n \n\nThere are eight possible passwords: `111`, `112`, `121`, `122`, `211`, `212`,\n`221`, and `222`.\n\n* * *"}, {"input": "1", "output": "1\n \n\nThere is only one possible password if you can only use one kind of character."}]
|
Print the number of possible passwords.
* * *
|
s624708489
|
Runtime Error
|
p02915
|
Input is given from Standard Input in the following format:
N
|
# run-length encoding, decoding
def rle_encode(data):
encoding = ""
prev_char = ""
count = 1
if not data:
return ""
for char in data:
# If the prev and current characters
# don't match...
if char != prev_char:
# ...then add the count and character
# to our encoding
if prev_char:
encoding += str(count) + prev_char + " "
count = 1
prev_char = char
else:
# Or increment our counter
# if the characters do match
count += 1
else:
# Finish off the encoding
encoding += str(count) + prev_char + " "
return encoding
N, K = [int(s) for s in input().split()]
S = input()
S_rle = rle_encode(S).split()
total = 0
for i, bunch in enumerate(S_rle):
total += int(list(bunch)[0]) - 1
if len(S_rle) >= 2 * K + 3:
print(total + 2 * K)
elif len(S_rle) >= 2 * K:
print(total + 2 * K - 1)
else:
print(N - 1)
|
Statement
Takahashi is going to set a 3-character password.
How many possible passwords are there if each of its characters must be a
digit between 1 and N (inclusive)?
|
[{"input": "2", "output": "8\n \n\nThere are eight possible passwords: `111`, `112`, `121`, `122`, `211`, `212`,\n`221`, and `222`.\n\n* * *"}, {"input": "1", "output": "1\n \n\nThere is only one possible password if you can only use one kind of character."}]
|
Print the number of possible passwords.
* * *
|
s436113138
|
Accepted
|
p02915
|
Input is given from Standard Input in the following format:
N
|
print((int(input()) ** 3))
|
Statement
Takahashi is going to set a 3-character password.
How many possible passwords are there if each of its characters must be a
digit between 1 and N (inclusive)?
|
[{"input": "2", "output": "8\n \n\nThere are eight possible passwords: `111`, `112`, `121`, `122`, `211`, `212`,\n`221`, and `222`.\n\n* * *"}, {"input": "1", "output": "1\n \n\nThere is only one possible password if you can only use one kind of character."}]
|
Print the number of possible passwords.
* * *
|
s045429578
|
Runtime Error
|
p02915
|
Input is given from Standard Input in the following format:
N
|
print((int.input()) ** 3)
|
Statement
Takahashi is going to set a 3-character password.
How many possible passwords are there if each of its characters must be a
digit between 1 and N (inclusive)?
|
[{"input": "2", "output": "8\n \n\nThere are eight possible passwords: `111`, `112`, `121`, `122`, `211`, `212`,\n`221`, and `222`.\n\n* * *"}, {"input": "1", "output": "1\n \n\nThere is only one possible password if you can only use one kind of character."}]
|
Print the number of possible passwords.
* * *
|
s454041694
|
Runtime Error
|
p02915
|
Input is given from Standard Input in the following format:
N
|
a = int, input()
print(a ^ 3)
|
Statement
Takahashi is going to set a 3-character password.
How many possible passwords are there if each of its characters must be a
digit between 1 and N (inclusive)?
|
[{"input": "2", "output": "8\n \n\nThere are eight possible passwords: `111`, `112`, `121`, `122`, `211`, `212`,\n`221`, and `222`.\n\n* * *"}, {"input": "1", "output": "1\n \n\nThere is only one possible password if you can only use one kind of character."}]
|
Print the number of possible passwords.
* * *
|
s085617833
|
Wrong Answer
|
p02915
|
Input is given from Standard Input in the following format:
N
|
print(int(input()) ^ 3)
|
Statement
Takahashi is going to set a 3-character password.
How many possible passwords are there if each of its characters must be a
digit between 1 and N (inclusive)?
|
[{"input": "2", "output": "8\n \n\nThere are eight possible passwords: `111`, `112`, `121`, `122`, `211`, `212`,\n`221`, and `222`.\n\n* * *"}, {"input": "1", "output": "1\n \n\nThere is only one possible password if you can only use one kind of character."}]
|
Print the number of possible passwords.
* * *
|
s664691287
|
Wrong Answer
|
p02915
|
Input is given from Standard Input in the following format:
N
|
print(3 ** int(input()))
|
Statement
Takahashi is going to set a 3-character password.
How many possible passwords are there if each of its characters must be a
digit between 1 and N (inclusive)?
|
[{"input": "2", "output": "8\n \n\nThere are eight possible passwords: `111`, `112`, `121`, `122`, `211`, `212`,\n`221`, and `222`.\n\n* * *"}, {"input": "1", "output": "1\n \n\nThere is only one possible password if you can only use one kind of character."}]
|
Print the number of possible passwords.
* * *
|
s689838160
|
Runtime Error
|
p02915
|
Input is given from Standard Input in the following format:
N
|
len = input()
print(len**3)
|
Statement
Takahashi is going to set a 3-character password.
How many possible passwords are there if each of its characters must be a
digit between 1 and N (inclusive)?
|
[{"input": "2", "output": "8\n \n\nThere are eight possible passwords: `111`, `112`, `121`, `122`, `211`, `212`,\n`221`, and `222`.\n\n* * *"}, {"input": "1", "output": "1\n \n\nThere is only one possible password if you can only use one kind of character."}]
|
Print the number of possible passwords.
* * *
|
s059394274
|
Accepted
|
p02915
|
Input is given from Standard Input in the following format:
N
|
n = int(input())
c = n**3
print(c)
|
Statement
Takahashi is going to set a 3-character password.
How many possible passwords are there if each of its characters must be a
digit between 1 and N (inclusive)?
|
[{"input": "2", "output": "8\n \n\nThere are eight possible passwords: `111`, `112`, `121`, `122`, `211`, `212`,\n`221`, and `222`.\n\n* * *"}, {"input": "1", "output": "1\n \n\nThere is only one possible password if you can only use one kind of character."}]
|
Print the number of possible passwords.
* * *
|
s235797845
|
Accepted
|
p02915
|
Input is given from Standard Input in the following format:
N
|
A = int(input())
P = A**3
print(P)
|
Statement
Takahashi is going to set a 3-character password.
How many possible passwords are there if each of its characters must be a
digit between 1 and N (inclusive)?
|
[{"input": "2", "output": "8\n \n\nThere are eight possible passwords: `111`, `112`, `121`, `122`, `211`, `212`,\n`221`, and `222`.\n\n* * *"}, {"input": "1", "output": "1\n \n\nThere is only one possible password if you can only use one kind of character."}]
|
Print the number of possible passwords.
* * *
|
s678074870
|
Wrong Answer
|
p02915
|
Input is given from Standard Input in the following format:
N
|
a = int()
a = a * a * a
print(str(a))
|
Statement
Takahashi is going to set a 3-character password.
How many possible passwords are there if each of its characters must be a
digit between 1 and N (inclusive)?
|
[{"input": "2", "output": "8\n \n\nThere are eight possible passwords: `111`, `112`, `121`, `122`, `211`, `212`,\n`221`, and `222`.\n\n* * *"}, {"input": "1", "output": "1\n \n\nThere is only one possible password if you can only use one kind of character."}]
|
Print the number of possible passwords.
* * *
|
s688589951
|
Runtime Error
|
p02915
|
Input is given from Standard Input in the following format:
N
|
N = input()
if N > 9 or N < 1:
print("error")
else:
password = N * 3
print(password)
|
Statement
Takahashi is going to set a 3-character password.
How many possible passwords are there if each of its characters must be a
digit between 1 and N (inclusive)?
|
[{"input": "2", "output": "8\n \n\nThere are eight possible passwords: `111`, `112`, `121`, `122`, `211`, `212`,\n`221`, and `222`.\n\n* * *"}, {"input": "1", "output": "1\n \n\nThere is only one possible password if you can only use one kind of character."}]
|
Print the number of possible passwords.
* * *
|
s652545544
|
Runtime Error
|
p02915
|
Input is given from Standard Input in the following format:
N
|
e = int(input())
sum = 1
for i in e:
sum *= i**e
print(sum)
|
Statement
Takahashi is going to set a 3-character password.
How many possible passwords are there if each of its characters must be a
digit between 1 and N (inclusive)?
|
[{"input": "2", "output": "8\n \n\nThere are eight possible passwords: `111`, `112`, `121`, `122`, `211`, `212`,\n`221`, and `222`.\n\n* * *"}, {"input": "1", "output": "1\n \n\nThere is only one possible password if you can only use one kind of character."}]
|
Print your solution in the following format:
a_{1,1} ... a_{1,N}
:
a_{N,1} ... a_{N,N}
* * *
|
s716760015
|
Wrong Answer
|
p03257
|
Input is given from Standard Input in the following format:
N
|
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
def sigma(N):
ans = 0
for i in range(1, N + 1):
ans += i
return ans
def comb(n, r):
if n - r < r:
r = n - r
if r == 0:
return 1
if r == 1:
return n
numerator = [n - r + k + 1 for k in range(r)]
denominator = [k + 1 for k in range(r)]
for p in range(2, r + 1):
pivot = denominator[p - 1]
if pivot > 1:
offset = (n - r) % p
for k in range(p - 1, r, p):
numerator[k - offset] /= pivot
denominator[k] /= pivot
result = 1
for k in range(r):
if numerator[k] > 1:
result *= int(numerator[k])
return result
# --------------------------------------------
dp = None
def bisearch(L, target):
low = 0
high = len(L) - 1
if len(L) == 0:
return False
while low <= high:
mid = (low + high) // 2
guess = L[mid]
if guess == target:
return True
elif guess < target:
low = mid + 1
elif guess > target:
high = mid - 1
if guess != target:
return False
def main():
MAX_V = 10**150
N = int(input())
L = [2, 3, 4, 5]
A = [[0] * N for _ in range(N + 1)]
A[0][0] = 2
A[1][0] = 5
A[0][1] = 3
A[1][1] = 4
for t in range(2, N):
for i in range(t):
if i == 0:
f = True
for x in range(A[i][t - 1] + 1, 0, -A[i][t - 1]):
if not bisearch(L, x):
L.append(x)
L.sort()
A[i][t] = x
f = False
break
if f:
for x in range(A[i][t - 1] + 1, MAX_V, A[i][t - 1]):
if not bisearch(L, x):
L.append(x)
L.sort()
A[i][t] = x
break
else:
_lcm = lcm(A[i - 1][t], A[i][t - 1])
f = True
for x in range(_lcm + 1, 0, -_lcm):
if not bisearch(L, x):
L.append(x)
L.sort()
A[i][t] = x
f = False
break
if f:
for x in range(_lcm + 1, MAX_V, _lcm):
if not bisearch(L, x):
L.append(x)
L.sort()
A[i][t] = x
break
for j in range(t):
if j == 0:
f = True
for x in range(A[t - 1][j] + 1, 0, -A[t - 1][j]):
if not bisearch(L, x):
L.append(x)
L.sort()
A[t][j] = x
f = False
break
if f:
for x in range(A[t - 1][j] + 1, MAX_V, A[t - 1][j]):
if not bisearch(L, x):
L.append(x)
L.sort()
A[t][j] = x
break
else:
_lcm = lcm(A[t - 1][j], A[t][j - 1])
f = True
for x in range(_lcm + 1, 0, -_lcm):
if not bisearch(L, x):
L.append(x)
L.sort()
A[t][j] = x
f = False
break
if f:
for x in range(_lcm + 1, MAX_V, _lcm):
if not bisearch(L, x):
L.append(x)
L.sort()
A[t][j] = x
break
print(L)
_lcm = lcm(A[t - 1][t], A[t][t - 1])
f = True
for x in range(_lcm + 1, 0, -_lcm):
if not bisearch(L, x):
L.append(x)
L.sort()
A[t][t] = x
break
if f:
for x in range(_lcm + 1, MAX_V, _lcm):
if not bisearch(L, x):
L.append(x)
L.sort()
A[t][t] = x
break
for i in range(N):
print(" ".join(list(map(str, A[i]))))
main()
|
Statement
You are given an integer N.
Construct any one N-by-N matrix a that satisfies the conditions below. It can
be proved that a solution always exists under the constraints of this problem.
* 1 \leq a_{i,j} \leq 10^{15}
* a_{i,j} are pairwise distinct integers.
* There exists a positive integer m such that the following holds: Let x and y be two elements of the matrix that are vertically or horizontally adjacent. Then, {\rm max}(x,y) {\rm mod} {\rm min}(x,y) is always m.
|
[{"input": "2", "output": "4 7\n 23 10\n \n\n * For any two elements x and y that are vertically or horizontally adjacent, {\\rm max}(x,y) {\\rm mod} {\\rm min}(x,y) is always 3."}]
|
Print your solution in the following format:
a_{1,1} ... a_{1,N}
:
a_{N,1} ... a_{N,N}
* * *
|
s165393242
|
Wrong Answer
|
p03257
|
Input is given from Standard Input in the following format:
N
|
import math
def primes(x):
if x < 2:
return []
primes = [i for i in range(x)]
primes[1] = 0 # 1は素数ではない
for prime in primes:
if prime > math.sqrt(x):
break
if prime == 0:
continue
for non_prime in range(2 * prime, x, prime):
primes[non_prime] = 0
return [prime for prime in primes if prime != 0]
def is_prime(x):
if x < 2:
return False # 2未満に素数はない
if x == 2 or x == 3 or x == 5:
return True # 2,3,5は素数
if x % 2 == 0 or x % 3 == 0 or x % 5 == 0:
return False # 2,3,5の倍数は合成数
prime = 7
step = 4
while prime <= math.sqrt(x):
if x % prime == 0:
return False
prime += step
step = 6 - step
return True
p = primes(10**5)
N = int(input())
for j in range(N):
ans = ""
for i in range(N):
ans += "2" if (i + j) % 2 == 0 else "3"
if i != N - 1:
ans += " "
print(ans)
|
Statement
You are given an integer N.
Construct any one N-by-N matrix a that satisfies the conditions below. It can
be proved that a solution always exists under the constraints of this problem.
* 1 \leq a_{i,j} \leq 10^{15}
* a_{i,j} are pairwise distinct integers.
* There exists a positive integer m such that the following holds: Let x and y be two elements of the matrix that are vertically or horizontally adjacent. Then, {\rm max}(x,y) {\rm mod} {\rm min}(x,y) is always m.
|
[{"input": "2", "output": "4 7\n 23 10\n \n\n * For any two elements x and y that are vertically or horizontally adjacent, {\\rm max}(x,y) {\\rm mod} {\\rm min}(x,y) is always 3."}]
|
Print your solution in the following format:
a_{1,1} ... a_{1,N}
:
a_{N,1} ... a_{N,N}
* * *
|
s602267347
|
Wrong Answer
|
p03257
|
Input is given from Standard Input in the following format:
N
|
n = int(input())
MAX = 10**6
mat = [[0] * n for i in range(n)]
mat[0][0] = MAX
for i in range(1, 2 * n):
MAX -= 2
for j in range(i + 1):
try:
mat[i - j][j] = MAX
except:
pass
for i in mat:
print(*i)
|
Statement
You are given an integer N.
Construct any one N-by-N matrix a that satisfies the conditions below. It can
be proved that a solution always exists under the constraints of this problem.
* 1 \leq a_{i,j} \leq 10^{15}
* a_{i,j} are pairwise distinct integers.
* There exists a positive integer m such that the following holds: Let x and y be two elements of the matrix that are vertically or horizontally adjacent. Then, {\rm max}(x,y) {\rm mod} {\rm min}(x,y) is always m.
|
[{"input": "2", "output": "4 7\n 23 10\n \n\n * For any two elements x and y that are vertically or horizontally adjacent, {\\rm max}(x,y) {\\rm mod} {\\rm min}(x,y) is always 3."}]
|
Print your solution in the following format:
a_{1,1} ... a_{1,N}
:
a_{N,1} ... a_{N,N}
* * *
|
s878782345
|
Wrong Answer
|
p03257
|
Input is given from Standard Input in the following format:
N
|
import itertools
|
Statement
You are given an integer N.
Construct any one N-by-N matrix a that satisfies the conditions below. It can
be proved that a solution always exists under the constraints of this problem.
* 1 \leq a_{i,j} \leq 10^{15}
* a_{i,j} are pairwise distinct integers.
* There exists a positive integer m such that the following holds: Let x and y be two elements of the matrix that are vertically or horizontally adjacent. Then, {\rm max}(x,y) {\rm mod} {\rm min}(x,y) is always m.
|
[{"input": "2", "output": "4 7\n 23 10\n \n\n * For any two elements x and y that are vertically or horizontally adjacent, {\\rm max}(x,y) {\\rm mod} {\\rm min}(x,y) is always 3."}]
|
Print your solution in the following format:
a_{1,1} ... a_{1,N}
:
a_{N,1} ... a_{N,N}
* * *
|
s443754269
|
Wrong Answer
|
p03257
|
Input is given from Standard Input in the following format:
N
|
N = int(input())
n_1 = N % 2
n_2 = N // 2
PN = [2]
L = 3
while len(PN) < N * 2:
c = True
for p in PN:
if L % p == 0:
c = False
if c == True:
PN.append(L)
L += 2
a = [[1] * N for _ in range(N)]
b = [[1] * N for _ in range(N)]
if n_1 == 1:
w = 1
for i in range(n_2):
if w > 0:
for j in range(i + 1):
a[i + j][i - j] = PN[4 * i]
a[i - j][i + j] = PN[4 * i]
a[N - 1 - i + j][N - 1 - i - j] = PN[4 * i + 1]
a[N - 1 - i - j][N - 1 - i + j] = PN[4 * i + 1]
b[i + j][N - 1 - i + j] = PN[4 * i + 2]
b[i - j][N - 1 - i - j] = PN[4 * i + 2]
b[N - 1 - i + j][i + j] = PN[4 * i + 3]
b[N - 1 - i - j][i - j] = PN[4 * i + 3]
else:
for j in range(i + 1):
a[i + j][i - j] = PN[-4 * (i - 1) - 1]
a[i - j][i + j] = PN[-4 * (i - 1) - 1]
a[N - 1 - i + j][N - 1 - i - j] = PN[-4 * (i - 1) - 2]
a[N - 1 - i - j][N - 1 - i + j] = PN[-4 * (i - 1) - 2]
b[i + j][N - 1 - i + j] = PN[-4 * (i - 1) - 3]
b[i - j][N - 1 - i - j] = PN[-4 * (i - 1) - 3]
b[N - 1 - i + j][i + j] = PN[-4 * (i - 1) - 4]
b[N - 1 - i - j][i - j] = PN[-4 * (i - 1) - 4]
w *= -1
r = (n_2 - 1) // 2 + 1
for j in range(n_2 + 1):
a[n_2 + j][n_2 - j] = PN[4 * r]
a[n_2 - j][n_2 + j] = PN[4 * r]
b[n_2 + j][n_2 + j] = PN[4 * r + 1]
b[n_2 - j][n_2 - j] = PN[4 * r + 1]
else:
w = 1
for i in range(n_2):
if w > 0:
for j in range(i + 1):
a[i + j][i - j] = PN[4 * i]
a[i - j][i + j] = PN[4 * i]
a[N - 1 - i + j][N - 1 - i - j] = PN[4 * i + 1]
a[N - 1 - i - j][N - 1 - i + j] = PN[4 * i + 1]
b[i + 1 + j][N - 1 - i + j] = PN[4 * i + 3]
b[i - j][N - 2 - i - j] = PN[4 * i + 3]
b[N - 1 - i + j][i + 1 + j] = PN[4 * i + 2]
b[N - 2 - i - j][i - j] = PN[4 * i + 2]
else:
for j in range(i + 1):
a[i + j][i - j] = PN[-4 * (i - 1) - 1]
a[i - j][i + j] = PN[-4 * (i - 1) - 1]
a[N - 1 - i + j][N - 1 - i - j] = PN[-4 * (i - 1) - 2]
a[N - 1 - i - j][N - 1 - i + j] = PN[-4 * (i - 1) - 2]
b[i + 1 + j][N - 1 - i + j] = PN[-4 * (i - 1) - 4]
b[i - j][N - 2 - i - j] = PN[-4 * (i - 1) - 4]
b[N - 1 - i + j][i + 1 + j] = PN[-4 * (i - 1) - 3]
b[N - 2 - i - j][i - j] = PN[-4 * (i - 1) - 3]
w *= -1
c = [[1] * N for _ in range(N)]
for i in range(N):
for j in range(N):
c[i][j] = a[i][j] * b[i][j]
if n_1 == 1:
for i in range(n_2 + 1):
for j in range(n_2):
c[2 * i][1 + 2 * j] += c[2 * i][1 + 2 * j - 1] * c[2 * i][1 + 2 * j + 1]
for i in range(n_2):
for j in range(n_2 + 1):
c[1 + 2 * i][2 * j] += c[1 + 2 * i - 1][2 * j] * c[1 + 2 * i + 1][2 * j]
else:
for i in range(n_2 - 1):
for j in range(n_2):
c[1 + 2 * i][2 * j] += c[1 + 2 * i - 1][2 * j] * c[1 + 2 * i + 1][2 * j]
c[1 + 2 * i + 1][2 * j + 1] += (
c[1 + 2 * i - 1 + 1][2 * j + 1] * c[1 + 2 * i + 1 + 1][2 * j + 1]
)
for j in range(n_2 - 1):
c[0][1 + 2 * j] += c[0][1 + 2 * j - 1] * c[0][1 + 2 * j + 1]
c[-1][2 + 2 * j] += c[-1][2 + 2 * j - 1] * c[-1][2 + 2 * j + 1]
c[0][-1] += a[0][-2] * a[1][-1] * b[0][-2]
c[-1][0] += a[-2][0] * a[-1][1] * b[-1][1] * 2
print(PN)
for C in c:
print(*C)
|
Statement
You are given an integer N.
Construct any one N-by-N matrix a that satisfies the conditions below. It can
be proved that a solution always exists under the constraints of this problem.
* 1 \leq a_{i,j} \leq 10^{15}
* a_{i,j} are pairwise distinct integers.
* There exists a positive integer m such that the following holds: Let x and y be two elements of the matrix that are vertically or horizontally adjacent. Then, {\rm max}(x,y) {\rm mod} {\rm min}(x,y) is always m.
|
[{"input": "2", "output": "4 7\n 23 10\n \n\n * For any two elements x and y that are vertically or horizontally adjacent, {\\rm max}(x,y) {\\rm mod} {\\rm min}(x,y) is always 3."}]
|
Print your solution in the following format:
a_{1,1} ... a_{1,N}
:
a_{N,1} ... a_{N,N}
* * *
|
s722031659
|
Wrong Answer
|
p03257
|
Input is given from Standard Input in the following format:
N
|
tmp = 1
flag = 0
n = int(input())
mat = [[0] * n for i in range(n)]
for i in range(0, 2 * n, 2):
for j in range(i + 1):
try:
if flag == 0:
mat[i - j][j] = tmp
flag = 1
tmp += 1
else:
mat[i - j][j] = (n * n + 1) // 2 - tmp + 2
flag = 0
except:
pass
for i in range(n):
for j in range(n):
if mat[i][j] == 0:
a = 1
b = 1
c = 1
d = 1
if i - 1 >= 0:
a = mat[i - 1][j]
if i + 1 <= n - 1:
b = mat[i + 1][j]
if j - 1 >= 0:
c = mat[i][j - 1]
if j + 1 <= n - 1:
d = mat[i][j + 1]
mat[i][j] = a * b * c * d + 1
for i in mat:
print(*i)
|
Statement
You are given an integer N.
Construct any one N-by-N matrix a that satisfies the conditions below. It can
be proved that a solution always exists under the constraints of this problem.
* 1 \leq a_{i,j} \leq 10^{15}
* a_{i,j} are pairwise distinct integers.
* There exists a positive integer m such that the following holds: Let x and y be two elements of the matrix that are vertically or horizontally adjacent. Then, {\rm max}(x,y) {\rm mod} {\rm min}(x,y) is always m.
|
[{"input": "2", "output": "4 7\n 23 10\n \n\n * For any two elements x and y that are vertically or horizontally adjacent, {\\rm max}(x,y) {\\rm mod} {\\rm min}(x,y) is always 3."}]
|
Print the winner: either `Alice` or `Brown`.
* * *
|
s981851807
|
Accepted
|
p03742
|
Input is given from Standard Input in the following format:
X Y
|
print(["Alice", "Brown"][-1 <= eval(input().replace(*" -")) <= 1])
|
Statement
Alice and Brown loves games. Today, they will play the following game.
In this game, there are two piles initially consisting of X and Y stones,
respectively. Alice and Bob alternately perform the following operation,
starting from Alice:
* Take 2i stones from one of the piles. Then, throw away i of them, and put the remaining i in the other pile. Here, the integer i (1≤i) can be freely chosen as long as there is a sufficient number of stones in the pile.
The player who becomes unable to perform the operation, loses the game.
Given X and Y, determine the winner of the game, assuming that both players
play optimally.
|
[{"input": "2 1", "output": "Brown\n \n\nAlice can do nothing but taking two stones from the pile containing two\nstones. As a result, the piles consist of zero and two stones, respectively.\nThen, Brown will take the two stones, and the piles will consist of one and\nzero stones, respectively. Alice will be unable to perform the operation\nanymore, which means Brown's victory.\n\n* * *"}, {"input": "5 0", "output": "Alice\n \n\n* * *"}, {"input": "0 0", "output": "Brown\n \n\n* * *"}, {"input": "4 8", "output": "Alice"}]
|
Print the winner: either `Alice` or `Brown`.
* * *
|
s303930274
|
Wrong Answer
|
p03742
|
Input is given from Standard Input in the following format:
X Y
|
# coding: utf-8
import random
print("Alice" if random.randint(0, 3) < 2 else "Brown")
|
Statement
Alice and Brown loves games. Today, they will play the following game.
In this game, there are two piles initially consisting of X and Y stones,
respectively. Alice and Bob alternately perform the following operation,
starting from Alice:
* Take 2i stones from one of the piles. Then, throw away i of them, and put the remaining i in the other pile. Here, the integer i (1≤i) can be freely chosen as long as there is a sufficient number of stones in the pile.
The player who becomes unable to perform the operation, loses the game.
Given X and Y, determine the winner of the game, assuming that both players
play optimally.
|
[{"input": "2 1", "output": "Brown\n \n\nAlice can do nothing but taking two stones from the pile containing two\nstones. As a result, the piles consist of zero and two stones, respectively.\nThen, Brown will take the two stones, and the piles will consist of one and\nzero stones, respectively. Alice will be unable to perform the operation\nanymore, which means Brown's victory.\n\n* * *"}, {"input": "5 0", "output": "Alice\n \n\n* * *"}, {"input": "0 0", "output": "Brown\n \n\n* * *"}, {"input": "4 8", "output": "Alice"}]
|
Print the winner: either `Alice` or `Brown`.
* * *
|
s174805878
|
Wrong Answer
|
p03742
|
Input is given from Standard Input in the following format:
X Y
|
print(["Brown", "Alice"][eval(input().replace(*" -")) > 1])
|
Statement
Alice and Brown loves games. Today, they will play the following game.
In this game, there are two piles initially consisting of X and Y stones,
respectively. Alice and Bob alternately perform the following operation,
starting from Alice:
* Take 2i stones from one of the piles. Then, throw away i of them, and put the remaining i in the other pile. Here, the integer i (1≤i) can be freely chosen as long as there is a sufficient number of stones in the pile.
The player who becomes unable to perform the operation, loses the game.
Given X and Y, determine the winner of the game, assuming that both players
play optimally.
|
[{"input": "2 1", "output": "Brown\n \n\nAlice can do nothing but taking two stones from the pile containing two\nstones. As a result, the piles consist of zero and two stones, respectively.\nThen, Brown will take the two stones, and the piles will consist of one and\nzero stones, respectively. Alice will be unable to perform the operation\nanymore, which means Brown's victory.\n\n* * *"}, {"input": "5 0", "output": "Alice\n \n\n* * *"}, {"input": "0 0", "output": "Brown\n \n\n* * *"}, {"input": "4 8", "output": "Alice"}]
|
Print the winner: either `Alice` or `Brown`.
* * *
|
s121070288
|
Accepted
|
p03742
|
Input is given from Standard Input in the following format:
X Y
|
print(["Alice", "Brown"][abs(eval(input().replace(" ", "-"))) < 2])
|
Statement
Alice and Brown loves games. Today, they will play the following game.
In this game, there are two piles initially consisting of X and Y stones,
respectively. Alice and Bob alternately perform the following operation,
starting from Alice:
* Take 2i stones from one of the piles. Then, throw away i of them, and put the remaining i in the other pile. Here, the integer i (1≤i) can be freely chosen as long as there is a sufficient number of stones in the pile.
The player who becomes unable to perform the operation, loses the game.
Given X and Y, determine the winner of the game, assuming that both players
play optimally.
|
[{"input": "2 1", "output": "Brown\n \n\nAlice can do nothing but taking two stones from the pile containing two\nstones. As a result, the piles consist of zero and two stones, respectively.\nThen, Brown will take the two stones, and the piles will consist of one and\nzero stones, respectively. Alice will be unable to perform the operation\nanymore, which means Brown's victory.\n\n* * *"}, {"input": "5 0", "output": "Alice\n \n\n* * *"}, {"input": "0 0", "output": "Brown\n \n\n* * *"}, {"input": "4 8", "output": "Alice"}]
|
Print the winner: either `Alice` or `Brown`.
* * *
|
s767788811
|
Wrong Answer
|
p03742
|
Input is given from Standard Input in the following format:
X Y
|
# coding: utf-8
print("Alice")
|
Statement
Alice and Brown loves games. Today, they will play the following game.
In this game, there are two piles initially consisting of X and Y stones,
respectively. Alice and Bob alternately perform the following operation,
starting from Alice:
* Take 2i stones from one of the piles. Then, throw away i of them, and put the remaining i in the other pile. Here, the integer i (1≤i) can be freely chosen as long as there is a sufficient number of stones in the pile.
The player who becomes unable to perform the operation, loses the game.
Given X and Y, determine the winner of the game, assuming that both players
play optimally.
|
[{"input": "2 1", "output": "Brown\n \n\nAlice can do nothing but taking two stones from the pile containing two\nstones. As a result, the piles consist of zero and two stones, respectively.\nThen, Brown will take the two stones, and the piles will consist of one and\nzero stones, respectively. Alice will be unable to perform the operation\nanymore, which means Brown's victory.\n\n* * *"}, {"input": "5 0", "output": "Alice\n \n\n* * *"}, {"input": "0 0", "output": "Brown\n \n\n* * *"}, {"input": "4 8", "output": "Alice"}]
|
Print the winner: either `Alice` or `Brown`.
* * *
|
s625684125
|
Runtime Error
|
p03742
|
Input is given from Standard Input in the following format:
X Y
|
X,Y = list(map(int,input().split()))
def game(x,y,turn="Alice"):
if x <= 1 and y <= 1:
if turn == "Alice":
return "Brown"
else:
return "Alice"
return "Alice"
elif x >= y:
if turn == "Alice":
return game(x%2, y+(x-x%2)/2, "Brown")
else:
return game(x%2, y+(x-x%2)/2, "Alice")
else:
if turn == "Alice":
return game(x+(y-y%2)/2, y%2, "Brown")
else:
return game(x+(y-y%2)/2, y%2, "Alice")
print (game(X,Y))
|
Statement
Alice and Brown loves games. Today, they will play the following game.
In this game, there are two piles initially consisting of X and Y stones,
respectively. Alice and Bob alternately perform the following operation,
starting from Alice:
* Take 2i stones from one of the piles. Then, throw away i of them, and put the remaining i in the other pile. Here, the integer i (1≤i) can be freely chosen as long as there is a sufficient number of stones in the pile.
The player who becomes unable to perform the operation, loses the game.
Given X and Y, determine the winner of the game, assuming that both players
play optimally.
|
[{"input": "2 1", "output": "Brown\n \n\nAlice can do nothing but taking two stones from the pile containing two\nstones. As a result, the piles consist of zero and two stones, respectively.\nThen, Brown will take the two stones, and the piles will consist of one and\nzero stones, respectively. Alice will be unable to perform the operation\nanymore, which means Brown's victory.\n\n* * *"}, {"input": "5 0", "output": "Alice\n \n\n* * *"}, {"input": "0 0", "output": "Brown\n \n\n* * *"}, {"input": "4 8", "output": "Alice"}]
|
Print the winner: either `Alice` or `Brown`.
* * *
|
s424331511
|
Runtime Error
|
p03742
|
Input is given from Standard Input in the following format:
X Y
|
if __name__='__main__':
m,n = map(int,input().split())
if abs(m-n)>1:
print('Alice')
else:
print('Brown')
|
Statement
Alice and Brown loves games. Today, they will play the following game.
In this game, there are two piles initially consisting of X and Y stones,
respectively. Alice and Bob alternately perform the following operation,
starting from Alice:
* Take 2i stones from one of the piles. Then, throw away i of them, and put the remaining i in the other pile. Here, the integer i (1≤i) can be freely chosen as long as there is a sufficient number of stones in the pile.
The player who becomes unable to perform the operation, loses the game.
Given X and Y, determine the winner of the game, assuming that both players
play optimally.
|
[{"input": "2 1", "output": "Brown\n \n\nAlice can do nothing but taking two stones from the pile containing two\nstones. As a result, the piles consist of zero and two stones, respectively.\nThen, Brown will take the two stones, and the piles will consist of one and\nzero stones, respectively. Alice will be unable to perform the operation\nanymore, which means Brown's victory.\n\n* * *"}, {"input": "5 0", "output": "Alice\n \n\n* * *"}, {"input": "0 0", "output": "Brown\n \n\n* * *"}, {"input": "4 8", "output": "Alice"}]
|
Print N lines.
The first line should contain K, the number of colors used.
The (i+1)-th line (1 \le i \le N-1) should contain c_i, the integer
representing the color of the i-th edge, where 1 \le c_i \le K must hold.
If there are multiple colorings with the minimum number of colors that satisfy
the condition, printing any of them will be accepted.
* * *
|
s657131514
|
Wrong Answer
|
p02850
|
Input is given from Standard Input in the following format:
N
a_1 b_1
a_2 b_2
\vdots
a_{N-1} b_{N-1}
|
n = int(input())
edge = [0 for i in range(n - 1)]
node = [[0] for i in range(n)]
max_c = 1
for i in range(n - 1):
node1, node2 = map(int, input().split())
c1 = max(node[node1 - 1])
c2 = max(node[node2 - 1])
c = max(c1, c2) + 1
for j in range(c - 1):
if not (j in node[node1 - 1]) and not (j in node[node2 - 1]):
c = j
break
node[node1 - 1].append(c)
node[node2 - 1].append(c)
edge[i] = c
max_c = max(c, max_c)
print(max_c)
for i in edge:
print(i)
|
Statement
Given is a tree G with N vertices. The vertices are numbered 1 through N, and
the i-th edge connects Vertex a_i and Vertex b_i.
Consider painting the edges in G with some number of colors. We want to paint
them so that, for each vertex, the colors of the edges incident to that vertex
are all different.
Among the colorings satisfying the condition above, construct one that uses
the minimum number of colors.
|
[{"input": "3\n 1 2\n 2 3", "output": "2\n 1\n 2\n \n\n* * *"}, {"input": "8\n 1 2\n 2 3\n 2 4\n 2 5\n 4 7\n 5 6\n 6 8", "output": "4\n 1\n 2\n 3\n 4\n 1\n 1\n 2\n \n\n* * *"}, {"input": "6\n 1 2\n 1 3\n 1 4\n 1 5\n 1 6", "output": "5\n 1\n 2\n 3\n 4\n 5"}]
|
Print N lines.
The first line should contain K, the number of colors used.
The (i+1)-th line (1 \le i \le N-1) should contain c_i, the integer
representing the color of the i-th edge, where 1 \le c_i \le K must hold.
If there are multiple colorings with the minimum number of colors that satisfy
the condition, printing any of them will be accepted.
* * *
|
s968655507
|
Wrong Answer
|
p02850
|
Input is given from Standard Input in the following format:
N
a_1 b_1
a_2 b_2
\vdots
a_{N-1} b_{N-1}
|
from collections import defaultdict
import random
class Graph:
def __init__(self):
self.edges = defaultdict(list)
self.weights = {}
def add_edge(self, from_node, to_node, weight):
# Note: assumes edges are bi-directional
self.edges[from_node].append(to_node)
self.edges[to_node].append(from_node)
self.weights[(from_node, to_node)] = weight
self.weights[(to_node, from_node)] = weight
def edge_num(self, node):
return len(self.edges[node])
def set_weight(self, from_node, to_node, weight):
self.weights[(from_node, to_node)] = weight
self.weights[(to_node, from_node)] = weight
def has_node_weight(self, node):
node_set = set()
for x in self.edges[node]:
node_set.add(self.weights[(node, x)])
return node_set
def done(self):
if min(self.weights) > 0:
return True
else:
return False
N = int(input())
A = [0] * N
B = [0] * N
g = Graph()
for i in range(N - 1):
A[i], B[i] = map(int, input().split())
A[i], B[i] = A[i] - 1, B[i] - 1
g.add_edge(A[i], B[i], 0)
lines = [0] * N
for n in range(N):
lines[n] = g.edge_num(n)
K = max(lines)
K_node = lines.index(K)
n = 1
for node in g.edges[K_node]:
g.set_weight(K_node, node, n)
n += 1
for node in g.edges[K_node]:
m = 1
for x in g.edges[node]:
if x == K_node:
continue
if m == g.weights[(node, K_node)]:
m += 1
g.set_weight(node, x, m)
m += 1
for n in range(N):
for node in g.edges[n]:
if g.weights[(n, node)] != 0:
continue
else:
weight = random.choice(list(set(range(1, K + 1)) - g.has_node_weight(node)))
g.set_weight(n, node, weight)
def output():
print(K)
for i in range(N - 1):
print(g.weights[(A[i], B[i])])
output()
|
Statement
Given is a tree G with N vertices. The vertices are numbered 1 through N, and
the i-th edge connects Vertex a_i and Vertex b_i.
Consider painting the edges in G with some number of colors. We want to paint
them so that, for each vertex, the colors of the edges incident to that vertex
are all different.
Among the colorings satisfying the condition above, construct one that uses
the minimum number of colors.
|
[{"input": "3\n 1 2\n 2 3", "output": "2\n 1\n 2\n \n\n* * *"}, {"input": "8\n 1 2\n 2 3\n 2 4\n 2 5\n 4 7\n 5 6\n 6 8", "output": "4\n 1\n 2\n 3\n 4\n 1\n 1\n 2\n \n\n* * *"}, {"input": "6\n 1 2\n 1 3\n 1 4\n 1 5\n 1 6", "output": "5\n 1\n 2\n 3\n 4\n 5"}]
|
Print N lines.
The first line should contain K, the number of colors used.
The (i+1)-th line (1 \le i \le N-1) should contain c_i, the integer
representing the color of the i-th edge, where 1 \le c_i \le K must hold.
If there are multiple colorings with the minimum number of colors that satisfy
the condition, printing any of them will be accepted.
* * *
|
s996105380
|
Wrong Answer
|
p02850
|
Input is given from Standard Input in the following format:
N
a_1 b_1
a_2 b_2
\vdots
a_{N-1} b_{N-1}
|
import sys
from collections import deque
sys.setrecursionlimit(10**6)
if sys.platform in (["ios", "darwin", "win32"]):
sys.stdin = open("Untitled.txt")
input = sys.stdin.readline
def INT():
return int(input())
def MAP():
return [int(s) for s in input().split()]
N = INT()
M = [MAP() for _ in range(N - 1)]
G = [[] for _ in range(N)]
for m in M:
a, b = m
a -= 1
b -= 1
G[a].append(b)
# G[b].append(a)
# print(G)
dist = [[-1, i, -1] for i in range(N)]
queue = deque()
dist[0] = [-1, 0, 0]
queue.append(0)
while queue:
v = queue.popleft()
for nv in G[v]:
# print(v, nv, G[v])
if dist[nv][2] != -1:
continue
dist[nv][0] = v
dist[nv][2] = dist[v][2] + 1
queue.append(nv)
dist[0].append(1)
COLOR = [1]
colors = [-1] * N
colors[0] = -1
# print(colors)
# print(dist)
for i, d in enumerate(dist):
if i == 0:
continue
par = d[0]
me = d[1]
dis = d[2]
bro = []
for di in dist:
if di[0] == par and di[2] == dis and di[1] != me:
bro.append(di)
col = []
col.append(colors[par])
gp = dist[par][0]
col.append(colors[gp])
for b in bro:
idx = b[1]
if colors[idx] != -1:
col.append(colors[idx])
# print("me:{}, bro:{}, col:{}".format(me, bro, col))
# print("COLORS:", COLOR)
for C in COLOR:
if not C in col:
colors[i] = C
break
else:
COLOR.append(max(COLOR) + 1)
colors[i] = COLOR[-1]
# print("my color:", colors[i])
# print(colors)
colors.pop(0)
print(len(set(colors)))
for c in colors:
print(c)
|
Statement
Given is a tree G with N vertices. The vertices are numbered 1 through N, and
the i-th edge connects Vertex a_i and Vertex b_i.
Consider painting the edges in G with some number of colors. We want to paint
them so that, for each vertex, the colors of the edges incident to that vertex
are all different.
Among the colorings satisfying the condition above, construct one that uses
the minimum number of colors.
|
[{"input": "3\n 1 2\n 2 3", "output": "2\n 1\n 2\n \n\n* * *"}, {"input": "8\n 1 2\n 2 3\n 2 4\n 2 5\n 4 7\n 5 6\n 6 8", "output": "4\n 1\n 2\n 3\n 4\n 1\n 1\n 2\n \n\n* * *"}, {"input": "6\n 1 2\n 1 3\n 1 4\n 1 5\n 1 6", "output": "5\n 1\n 2\n 3\n 4\n 5"}]
|
Print N lines.
The first line should contain K, the number of colors used.
The (i+1)-th line (1 \le i \le N-1) should contain c_i, the integer
representing the color of the i-th edge, where 1 \le c_i \le K must hold.
If there are multiple colorings with the minimum number of colors that satisfy
the condition, printing any of them will be accepted.
* * *
|
s491683873
|
Wrong Answer
|
p02850
|
Input is given from Standard Input in the following format:
N
a_1 b_1
a_2 b_2
\vdots
a_{N-1} b_{N-1}
|
N = int(input())
mat = [list(map(int, input().split())) for i in range(N - 1)]
dic = dict(zip(range(1, N + 1), [0] * N))
for i in range(N - 1):
for j in range(2):
dic[mat[i][j]] += 1
K = max(dic.values())
index = max(dic.items(), key=lambda x: x[1])[0]
save = [[] for i in range(N)]
tmp = [0] * (N - 1)
num = 1
for i in range(N - 1):
if index in mat[i]:
tmp[i] = num
save[mat[i][0] - 1].append(num)
save[mat[i][1] - 1].append(num)
num += 1
if 0 not in tmp:
print(K)
for i in range(len(tmp)):
print(tmp[i])
else:
for i in range(len(tmp)):
if tmp[i] == 0:
for j in range(1, K + 1):
if j not in save[mat[i][0] - 1] and j not in save[mat[i][1] - 1]:
tmp[i] = j
save[mat[i][0] - 1].append(j)
save[mat[i][1] - 1].append(j)
print(K)
for k in range(len(tmp)):
print(tmp[i])
|
Statement
Given is a tree G with N vertices. The vertices are numbered 1 through N, and
the i-th edge connects Vertex a_i and Vertex b_i.
Consider painting the edges in G with some number of colors. We want to paint
them so that, for each vertex, the colors of the edges incident to that vertex
are all different.
Among the colorings satisfying the condition above, construct one that uses
the minimum number of colors.
|
[{"input": "3\n 1 2\n 2 3", "output": "2\n 1\n 2\n \n\n* * *"}, {"input": "8\n 1 2\n 2 3\n 2 4\n 2 5\n 4 7\n 5 6\n 6 8", "output": "4\n 1\n 2\n 3\n 4\n 1\n 1\n 2\n \n\n* * *"}, {"input": "6\n 1 2\n 1 3\n 1 4\n 1 5\n 1 6", "output": "5\n 1\n 2\n 3\n 4\n 5"}]
|
Print N lines.
The first line should contain K, the number of colors used.
The (i+1)-th line (1 \le i \le N-1) should contain c_i, the integer
representing the color of the i-th edge, where 1 \le c_i \le K must hold.
If there are multiple colorings with the minimum number of colors that satisfy
the condition, printing any of them will be accepted.
* * *
|
s280784710
|
Wrong Answer
|
p02850
|
Input is given from Standard Input in the following format:
N
a_1 b_1
a_2 b_2
\vdots
a_{N-1} b_{N-1}
|
import sys
from collections import defaultdict
inputs = sys.stdin.readlines()
n = int(inputs[0])
nodes = [tuple(map(int, x.split())) for x in inputs[1:]]
tree = defaultdict(tuple)
for i in range(1, n + 1):
tree[i] = tuple(n[1] for n in nodes if n[0] == i)
colors = list(range(1, max([len(x) for x in tree.values()]) + 2))
def travel(p, bros):
use_colors = [p]
for node in bros:
for c in colors:
if c not in use_colors:
use_colors.append(c)
break
nodes[node] = c
travel(c, tree[node])
nodes = [0] * (n + 1)
node = 1
nodes[node] = 1
childs = tree[node]
travel(node, childs)
for node in nodes[1:]:
print(node)
|
Statement
Given is a tree G with N vertices. The vertices are numbered 1 through N, and
the i-th edge connects Vertex a_i and Vertex b_i.
Consider painting the edges in G with some number of colors. We want to paint
them so that, for each vertex, the colors of the edges incident to that vertex
are all different.
Among the colorings satisfying the condition above, construct one that uses
the minimum number of colors.
|
[{"input": "3\n 1 2\n 2 3", "output": "2\n 1\n 2\n \n\n* * *"}, {"input": "8\n 1 2\n 2 3\n 2 4\n 2 5\n 4 7\n 5 6\n 6 8", "output": "4\n 1\n 2\n 3\n 4\n 1\n 1\n 2\n \n\n* * *"}, {"input": "6\n 1 2\n 1 3\n 1 4\n 1 5\n 1 6", "output": "5\n 1\n 2\n 3\n 4\n 5"}]
|
Print N lines.
The first line should contain K, the number of colors used.
The (i+1)-th line (1 \le i \le N-1) should contain c_i, the integer
representing the color of the i-th edge, where 1 \le c_i \le K must hold.
If there are multiple colorings with the minimum number of colors that satisfy
the condition, printing any of them will be accepted.
* * *
|
s062854258
|
Wrong Answer
|
p02850
|
Input is given from Standard Input in the following format:
N
a_1 b_1
a_2 b_2
\vdots
a_{N-1} b_{N-1}
|
N = int(input())
TopList = [] # 頂点から最少の色の数を求める
GList = [] # i + 1行目の保存
ColorList = []
for i in range(0, N):
if i != 0:
GList.append([0, 0])
TopList.append(0)
ColorList.append([])
for i in range(0, N - 1):
A, B = map(int, input().split())
TopList[A - 1] += 1
TopList[B - 1] += 1
GList[i][0] = A
GList[i][1] = B
count = -1
for i in range(0, len(TopList)):
if count < TopList[i]:
count = TopList[i]
print(count)
for i in range(0, len(GList)):
for q in range(0, count): # color決め
if q in ColorList[GList[i][0] - 1]:
continue
elif q in ColorList[GList[i][1] - 1]:
continue
else:
ColorList[GList[i][0] - 1].append(q)
ColorList[GList[i][1] - 1].append(q)
print(q)
break
|
Statement
Given is a tree G with N vertices. The vertices are numbered 1 through N, and
the i-th edge connects Vertex a_i and Vertex b_i.
Consider painting the edges in G with some number of colors. We want to paint
them so that, for each vertex, the colors of the edges incident to that vertex
are all different.
Among the colorings satisfying the condition above, construct one that uses
the minimum number of colors.
|
[{"input": "3\n 1 2\n 2 3", "output": "2\n 1\n 2\n \n\n* * *"}, {"input": "8\n 1 2\n 2 3\n 2 4\n 2 5\n 4 7\n 5 6\n 6 8", "output": "4\n 1\n 2\n 3\n 4\n 1\n 1\n 2\n \n\n* * *"}, {"input": "6\n 1 2\n 1 3\n 1 4\n 1 5\n 1 6", "output": "5\n 1\n 2\n 3\n 4\n 5"}]
|
Print N lines.
The first line should contain K, the number of colors used.
The (i+1)-th line (1 \le i \le N-1) should contain c_i, the integer
representing the color of the i-th edge, where 1 \le c_i \le K must hold.
If there are multiple colorings with the minimum number of colors that satisfy
the condition, printing any of them will be accepted.
* * *
|
s425878056
|
Runtime Error
|
p02850
|
Input is given from Standard Input in the following format:
N
a_1 b_1
a_2 b_2
\vdots
a_{N-1} b_{N-1}
|
def abc146_d():
n = int(input())
Q = [tuple(map(lambda x: int(x) - 1, input().split())) for _ in range(n - 1)]
deg = [0] * n
adj = [[] for _ in range(n)]
color = dict()
for a, b in Q:
deg[a] += 1
deg[b] += 1
adj[a].append(b)
adj[b].append(a)
def dfs(s, p):
nouse = -1
if p > -1:
nouse = color[(min(s, p), max(s, p))]
c = 1
for t in adj[s]:
if t == p:
continue
if c == nouse:
c += 1
color[(min(s, t), max(s, t))] = c
dfs(t, s)
c += 1
dfs(1, -1)
print(max(deg))
for a, b in Q:
print(color[(a, b)])
if __name__ == "__main__":
abc146_d()
|
Statement
Given is a tree G with N vertices. The vertices are numbered 1 through N, and
the i-th edge connects Vertex a_i and Vertex b_i.
Consider painting the edges in G with some number of colors. We want to paint
them so that, for each vertex, the colors of the edges incident to that vertex
are all different.
Among the colorings satisfying the condition above, construct one that uses
the minimum number of colors.
|
[{"input": "3\n 1 2\n 2 3", "output": "2\n 1\n 2\n \n\n* * *"}, {"input": "8\n 1 2\n 2 3\n 2 4\n 2 5\n 4 7\n 5 6\n 6 8", "output": "4\n 1\n 2\n 3\n 4\n 1\n 1\n 2\n \n\n* * *"}, {"input": "6\n 1 2\n 1 3\n 1 4\n 1 5\n 1 6", "output": "5\n 1\n 2\n 3\n 4\n 5"}]
|
Print N lines.
The first line should contain K, the number of colors used.
The (i+1)-th line (1 \le i \le N-1) should contain c_i, the integer
representing the color of the i-th edge, where 1 \le c_i \le K must hold.
If there are multiple colorings with the minimum number of colors that satisfy
the condition, printing any of them will be accepted.
* * *
|
s434429848
|
Runtime Error
|
p02850
|
Input is given from Standard Input in the following format:
N
a_1 b_1
a_2 b_2
\vdots
a_{N-1} b_{N-1}
|
A, B, X = map(int, input().split())
dn = 0
for k in range(28, -1, -1):
if A * 10 ** (k - 1) + B * k <= X:
dn = k
break
if dn == 0:
ans = 0
else:
ans = min((X - B * dn) // A, 10**9)
print(ans)
|
Statement
Given is a tree G with N vertices. The vertices are numbered 1 through N, and
the i-th edge connects Vertex a_i and Vertex b_i.
Consider painting the edges in G with some number of colors. We want to paint
them so that, for each vertex, the colors of the edges incident to that vertex
are all different.
Among the colorings satisfying the condition above, construct one that uses
the minimum number of colors.
|
[{"input": "3\n 1 2\n 2 3", "output": "2\n 1\n 2\n \n\n* * *"}, {"input": "8\n 1 2\n 2 3\n 2 4\n 2 5\n 4 7\n 5 6\n 6 8", "output": "4\n 1\n 2\n 3\n 4\n 1\n 1\n 2\n \n\n* * *"}, {"input": "6\n 1 2\n 1 3\n 1 4\n 1 5\n 1 6", "output": "5\n 1\n 2\n 3\n 4\n 5"}]
|
Print N lines.
The first line should contain K, the number of colors used.
The (i+1)-th line (1 \le i \le N-1) should contain c_i, the integer
representing the color of the i-th edge, where 1 \le c_i \le K must hold.
If there are multiple colorings with the minimum number of colors that satisfy
the condition, printing any of them will be accepted.
* * *
|
s275436261
|
Accepted
|
p02850
|
Input is given from Standard Input in the following format:
N
a_1 b_1
a_2 b_2
\vdots
a_{N-1} b_{N-1}
|
import sys, collections as cl, 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
def nibu(a, b, r):
ll = 0
rr = r
while True:
mid = (ll + rr) // 2
if ll == mid:
return ll
co = mid * a
mm = mid
while mm != 0:
co += b
mm //= 10
if co >= r:
rr = mid - 1
else:
ll = mid
n = onem()
kkk = [[] for i in range(n)]
for i in range(n - 1):
a, b = m()
kkk[a - 1].append([b - 1, i + 1])
kkk[b - 1].append([a - 1, i + 1])
de = cl.deque([[0, 0, 0]])
kk = []
while de:
j, k, p = de.popleft()
co = 1
for i in range(len(kkk[j])):
if not kkk[j][i][0] == k:
if co == p:
co += 1
de.append([kkk[j][i][0], j, co])
kk.append([co, kkk[j][i][1]])
co += 1
kk.sort(key=lambda x: x[1])
print(max(kk, key=lambda x: x[0])[0])
for i in range(n - 1):
print(kk[i][0])
|
Statement
Given is a tree G with N vertices. The vertices are numbered 1 through N, and
the i-th edge connects Vertex a_i and Vertex b_i.
Consider painting the edges in G with some number of colors. We want to paint
them so that, for each vertex, the colors of the edges incident to that vertex
are all different.
Among the colorings satisfying the condition above, construct one that uses
the minimum number of colors.
|
[{"input": "3\n 1 2\n 2 3", "output": "2\n 1\n 2\n \n\n* * *"}, {"input": "8\n 1 2\n 2 3\n 2 4\n 2 5\n 4 7\n 5 6\n 6 8", "output": "4\n 1\n 2\n 3\n 4\n 1\n 1\n 2\n \n\n* * *"}, {"input": "6\n 1 2\n 1 3\n 1 4\n 1 5\n 1 6", "output": "5\n 1\n 2\n 3\n 4\n 5"}]
|
Print N lines.
The first line should contain K, the number of colors used.
The (i+1)-th line (1 \le i \le N-1) should contain c_i, the integer
representing the color of the i-th edge, where 1 \le c_i \le K must hold.
If there are multiple colorings with the minimum number of colors that satisfy
the condition, printing any of them will be accepted.
* * *
|
s028770053
|
Wrong Answer
|
p02850
|
Input is given from Standard Input in the following format:
N
a_1 b_1
a_2 b_2
\vdots
a_{N-1} b_{N-1}
|
import collections
def my_index_multi(l, x):
return [i for i, _x in enumerate(l) if _x == x]
n = int(input())
al = []
bl = []
cl = []
ngl = []
for i in range(n - 1):
a, b = map(int, input().split())
# aがすでにalに入っているとき
if a in al:
d = my_index_multi(al, a)
for x in d:
ngl.append(cl[x])
if b in al:
d = my_index_multi(al, b)
for x in d:
ngl.append(cl[x])
if a in bl:
d = my_index_multi(bl, a)
for x in d:
ngl.append(cl[x])
if b in bl:
d = my_index_multi(bl, b)
for x in d:
ngl.append(cl[x])
al.append(a)
bl.append(b)
if ngl == []:
cl.append(1)
if ngl != []:
for i, ng in enumerate(set(ngl), 1):
if ng != i:
cl.append(i)
ngl = []
break
if ngl != []:
cl.append((max(ngl) + 1))
ngl = []
print(len(collections.Counter(cl)))
for i in range(len(cl)):
print(cl[i])
|
Statement
Given is a tree G with N vertices. The vertices are numbered 1 through N, and
the i-th edge connects Vertex a_i and Vertex b_i.
Consider painting the edges in G with some number of colors. We want to paint
them so that, for each vertex, the colors of the edges incident to that vertex
are all different.
Among the colorings satisfying the condition above, construct one that uses
the minimum number of colors.
|
[{"input": "3\n 1 2\n 2 3", "output": "2\n 1\n 2\n \n\n* * *"}, {"input": "8\n 1 2\n 2 3\n 2 4\n 2 5\n 4 7\n 5 6\n 6 8", "output": "4\n 1\n 2\n 3\n 4\n 1\n 1\n 2\n \n\n* * *"}, {"input": "6\n 1 2\n 1 3\n 1 4\n 1 5\n 1 6", "output": "5\n 1\n 2\n 3\n 4\n 5"}]
|
Print N lines.
The first line should contain K, the number of colors used.
The (i+1)-th line (1 \le i \le N-1) should contain c_i, the integer
representing the color of the i-th edge, where 1 \le c_i \le K must hold.
If there are multiple colorings with the minimum number of colors that satisfy
the condition, printing any of them will be accepted.
* * *
|
s585734982
|
Accepted
|
p02850
|
Input is given from Standard Input in the following format:
N
a_1 b_1
a_2 b_2
\vdots
a_{N-1} b_{N-1}
|
from operator import mul
from functools import reduce
# from collections import Counter
# from itertools import combinations as comb
# from itertools import permutations as perm
# from copy import copy
# 配列二分法アルゴリズム
# https://docs.python.jp/3/library/bisect.html
# import bisect
# 桁数指定
# print('{:.3f}'.format(X))
# from collections import defaultdict
# dic = defaultdict(lambda: ...)
# 値で辞書をソート
# sorted(dic.items(), key=lambda x:x[1])
# ヒープキュー
# https://docs.python.org/ja/3/library/heapq.html
# import heapq
# 正規表現(regular expression)のためのモジュール
# import re
import sys
sys.setrecursionlimit(10**6)
def inpl():
return list(map(int, input().split()))
# 重複組み合わせは nHr = (n + r - 1)Cn
def cmb(n, r):
# combination
if n < r:
return 0
r = min(n - r, r)
if r == 0:
return 1
over = reduce(mul, range(n, n - r, -1))
under = reduce(mul, range(1, r + 1))
return over // under
def gcd(a, b):
# greatest common divisor
while b > 0:
a, b = b, a % b
return a
def lcm(a, b):
# least common multiple
return a * b // gcd(a, b)
def dfs(visit, a, v_b, v_color):
visit[a] = True
# t_list = [t for t in tmp_list[a] if t != v_b]
# t_color = [c for c in range(ans) if v_color != c]
# print(t_list, t_color)
flag = True
i = 0
for b in tmp_list[a]:
if b == v_b:
continue
# print(a, b, c)
# color[a][c] = True
# color[b][c] = True
if flag is True and i >= v_color:
flag = False
i += 1
c = i
ans_c[min(a, b), max(a, b)] = c
dfs(visit, b, a, c)
i += 1
return
N = int(input())
AB = [inpl() for i in range(N - 1)]
ans_c = {}
tmp_list = [[] for i in range(N + 1)]
for a, b in AB:
tmp_list[a].append(b)
tmp_list[b].append(a)
ans = max(len(a) for a in tmp_list)
# print(ans, "ans")
# color = [[False for j in range(ans)] for i in range(N + 1)]
visit = [False for i in range(N + 1)]
dfs(visit, 1, N + 1, ans + 1)
print(ans)
for a, b in AB:
print(ans_c[a, b] + 1)
|
Statement
Given is a tree G with N vertices. The vertices are numbered 1 through N, and
the i-th edge connects Vertex a_i and Vertex b_i.
Consider painting the edges in G with some number of colors. We want to paint
them so that, for each vertex, the colors of the edges incident to that vertex
are all different.
Among the colorings satisfying the condition above, construct one that uses
the minimum number of colors.
|
[{"input": "3\n 1 2\n 2 3", "output": "2\n 1\n 2\n \n\n* * *"}, {"input": "8\n 1 2\n 2 3\n 2 4\n 2 5\n 4 7\n 5 6\n 6 8", "output": "4\n 1\n 2\n 3\n 4\n 1\n 1\n 2\n \n\n* * *"}, {"input": "6\n 1 2\n 1 3\n 1 4\n 1 5\n 1 6", "output": "5\n 1\n 2\n 3\n 4\n 5"}]
|
Print N lines.
The first line should contain K, the number of colors used.
The (i+1)-th line (1 \le i \le N-1) should contain c_i, the integer
representing the color of the i-th edge, where 1 \le c_i \le K must hold.
If there are multiple colorings with the minimum number of colors that satisfy
the condition, printing any of them will be accepted.
* * *
|
s673334115
|
Runtime Error
|
p02850
|
Input is given from Standard Input in the following format:
N
a_1 b_1
a_2 b_2
\vdots
a_{N-1} b_{N-1}
|
# 920~
# 解法 よく考えたら一度解いた問題な気がする
# 936 まず,最も接続数が多いノードについて,異なる色を決める,
# 他のノードについては,自分が現在接続されているものとは違う色を適当に選んでつける
# 実装
# ノードの色塗りの仕方がわからない. (x,y) = colorってしちゃうと,N*Nのlistを作らないとイケなくない??
#
N = int(input())
A = [[] for _ in range(N)]
J = []
col = {}
for _ in range(N - 1):
ai, bi = map(int, input().split())
A[ai - 1].append(bi)
A[bi - 1].append(ai)
J.append([ai, bi])
node_num = [len(a) for a in A]
# 親から子へ探索をする.ノードごとにつながっているノードを取り出してきて,それが親なら無視する.親以外なら親以外の色をつけて,
# 自身が親となってdfsを返す.
def dfs(this_node, parent_node, parent_color):
# 入力 今のノード,親のエッジ, 親の色,
# エッジに色を塗る
# 出力 子のエッジ,子の色
# 終了条件 なし 親のノードしかないノードに行くと,勝手に探索をやめる
this_color = 0
for a in A[this_node - 1]:
if a == parent_node:
continue
if this_color == parent_color:
this_color += 1
if this_node > a:
tmp = this_node
this_node = a
a = tmp
col[(this_node, a)] = this_color
this_color += 1
dfs(a, this_node, this_color - 1)
# 子供がいる場合は,そいつらにつなぐ
dfs(1, -1, -1)
# 最終的にはエッジを選んで出力しないといけない
print(max(node_num))
for j in J:
j = tuple(j)
print(col[j] + 1)
|
Statement
Given is a tree G with N vertices. The vertices are numbered 1 through N, and
the i-th edge connects Vertex a_i and Vertex b_i.
Consider painting the edges in G with some number of colors. We want to paint
them so that, for each vertex, the colors of the edges incident to that vertex
are all different.
Among the colorings satisfying the condition above, construct one that uses
the minimum number of colors.
|
[{"input": "3\n 1 2\n 2 3", "output": "2\n 1\n 2\n \n\n* * *"}, {"input": "8\n 1 2\n 2 3\n 2 4\n 2 5\n 4 7\n 5 6\n 6 8", "output": "4\n 1\n 2\n 3\n 4\n 1\n 1\n 2\n \n\n* * *"}, {"input": "6\n 1 2\n 1 3\n 1 4\n 1 5\n 1 6", "output": "5\n 1\n 2\n 3\n 4\n 5"}]
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.