input
stringlengths 20
127k
| target
stringlengths 20
119k
| problem_id
stringlengths 6
6
|
---|---|---|
# coding: utf-8
# Your code here!
import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline #文字列入力のときは注意
n = int(eval(input()))
a = [int(i) for i in readline().split()]
b = [int(i) for i in readline().split()]
def op(b,i):
global ans
if i == n-1:
res = (b[i]-a[i])//(b[i-1]+b[0])
b[i] -= (b[i-1]+b[0])*res
else:
res = (b[i]-a[i])//(b[i-1]+b[(i+1)])
b[i] -= (b[i-1]+b[(i+1)])*res
ans += res
if res >= 0:
return res
else: return 0
def check(b,c):#c からチェック 操作ができる最初のi
# print(b,c)
for i in range(c,c+n):
if op(b,i%n) > 0: return i
else:
return(-1)
def rev(b,i):#iから逆向きに操作
for j in range(i-1,-n,-1):
# print(b,j)
if op(b,j%n) == 0: break
c = 0
ans = 0
while True:
i = check(b,c)
if i == -1: break
rev(b,i)
c += 1
if c >= n: c -= n
if a == b:
print(ans)
else:
print((-1))
|
# coding: utf-8
# Your code here!
import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline #文字列入力のときは注意
n = int(eval(input()))
a = [int(i) for i in readline().split()]
b = [int(i) for i in readline().split()]
def op(b,i):
global ans
if i == n-1:
res = (b[i]-a[i])//(b[i-1]+b[0])
if res < 0: return 0
b[i] -= (b[i-1]+b[0])*res
else:
res = (b[i]-a[i])//(b[i-1]+b[(i+1)])
if res < 0: return 0
b[i] -= (b[i-1]+b[(i+1)])*res
ans += res
return res
def check(b,c):#c からチェック 操作ができる最初のi
# print(b,c)
for i in range(c,c+n):
if op(b,i%n) > 0: return i
else:
return(-1)
def rev(b,i):#iから逆向きに操作
for j in range(i-1,-n,-1):
# print(b,j)
if op(b,j%n) == 0: break
c = 0
ans = 0
"""
while True:
i = check(b,c)
if i == -1: break
rev(b,i)
c += 1
if c >= n: c -= n
"""
s = set(range(n))
while s:
i = s.pop()
if op(b,i) > 0:
s.add((i-1)%n)
s.add((i+1)%n)
if a == b:
print(ans)
else:
print((-1))
|
p02941
|
#!/usr/bin/env python3
import sys
# import heapq
def solve(N: int, A: "List[int]", B: "List[int]"):
count = 0
flag = True
while flag:
flag = False
for i in range(N):
a, b, c = B[i-1], B[i], B[(i+1) % N]
if b > A[i] and b > a+c:
d, m = divmod(b-A[i], a+c)
count += d
B[i] = A[i]+m
flag = True
# print(*A)
# print(*B)
if A != B:
print((-1))
return
print(count)
return
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]"
B = [int(next(tokens)) for _ in range(N)] # type: "List[int]"
solve(N, A, B)
if __name__ == '__main__':
main()
|
#!/usr/bin/env python3
import sys
# import heapq
def solve(N: int, A: "List[int]", B: "List[int]"):
count = 0
flag = True
while flag:
flag = False
for i in range(N):
a, b, c = B[i-1], B[i], B[(i+1) % N]
if b > A[i] and b > a+c:
d, m = divmod(b-A[i], a+c)
if m == 0:
B[i] = A[i]
count += d
else:
d, m = divmod(b, a+c)
count += d
B[i] = m
flag = True
# print(*A)
# print(*B)
if A != B:
count = -1
print(count)
return
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]"
B = [int(next(tokens)) for _ in range(N)] # type: "List[int]"
solve(N, A, B)
if __name__ == '__main__':
main()
|
p02941
|
#!/usr/bin/env python3
import sys
from heapq import heapify, heappush, heappop
def solve(N: int, A: "List[int]", B: "List[int]"):
lh = []
for i, b in enumerate(B):
heappush(lh, [-b, i])
count = 0
while lh:
b, i = heappop(lh)
a, b = A[i], B[i]
c = B[i-1]+B[(i+1) % N]
if b > a and b >= c:
d, m = divmod(b-a, c)
if d == 0:
break
count += d
B[i] = a+m
if m != 0:
heappush(lh, [-B[i], i])
if A != B:
count = -1
print(count)
return
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]"
B = [int(next(tokens)) for _ in range(N)] # type: "List[int]"
solve(N, A, B)
if __name__ == '__main__':
main()
|
#!/usr/bin/env python3
import sys
from heapq import heapify, heappush, heappop
def solve(N: int, A: "List[int]", B: "List[int]"):
lh = []
for i, b in enumerate(B):
heappush(lh, (-b, i))
count = 0
while lh:
b, i = heappop(lh)
a, b, c = A[i], B[i], B[i-1]+B[(i+1) % N]
if b > a and b > c:
d, m = divmod(b-a, c)
if d <= 0:
break
count += d
B[i] = a+m
if m > 0:
heappush(lh, (-B[i], i))
if A != B:
count = -1
print(count)
return
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]"
B = [int(next(tokens)) for _ in range(N)] # type: "List[int]"
solve(N, A, B)
if __name__ == '__main__':
main()
|
p02941
|
import sys
input = sys.stdin.readline
n=int(eval(input()))
A=[int(i) for i in input().split()]
B=[int(i) for i in input().split()]
from heapq import heappop, heappush
push = lambda x,i: heappush(BB,(-x,i))
BB=[]
for i,b in enumerate(B):
push(b,i)
ans=0
while BB:
b,ind=heappop(BB)
b,ai=-b,A[ind]
if b<ai:
ans=-1
break
d=B[(ind-1)%n]+B[(ind+1)%n]
dd=(b-ai)//d
if dd==0:
if b==ai:
continue
ans=-1
break
ans+=dd
B[ind]-=d*dd
push(B[ind],ind)
print(ans)
|
n=int(eval(input()))
A=[int(i) for i in input().split()]
B=[int(i) for i in input().split()]
from heapq import heappop, heappush
push = lambda x,i: heappush(BB,(-x,i))
BB=[]
for i,b in enumerate(B):
push(b,i)
ans=0
while BB:
b,ind=heappop(BB)
b,ai=-b,A[ind]
if b<ai:
ans=-1
break
d=B[(ind-1)%n]+B[(ind+1)%n]
dd=(b-ai)//d
if dd==0:
if b==ai:
continue
ans=-1
break
ans+=dd
B[ind]-=d*dd
push(B[ind],ind)
print(ans)
|
p02941
|
n=int(eval(input()))
A=[int(i) for i in input().split()]
B=[int(i) for i in input().split()]
from heapq import heappop, heappush
push = lambda x,i: heappush(BB,(-x,i))
BB=[]
for i,b in enumerate(B):
push(b,i)
ans=0
while BB:
b,ind=heappop(BB)
b=-b
if b<A[ind]:
ans=-1
break
d=B[(ind-1)%n]+B[(ind+1)%n]
dd=(b-A[ind])//d
if dd==0:
if b==A[ind]:
continue
ans=-1
break
ans+=dd
B[ind]-=d*dd
push(B[ind],ind)
print(ans)
|
n=int(eval(input()))
A=[int(i) for i in input().split()]
B=[int(i) for i in input().split()]
from heapq import heappop, heappush
push = lambda x,i: heappush(BB,(-x,i))
BB=[]
for i,b in enumerate(B):
push(b,i)
ans=0
while BB:
b,ind=heappop(BB)
b,ai=-b,A[ind]
if b<ai:
ans=-1
break
if ind==0:
d=B[1]+B[-1]
elif ind==n-1:
d=B[-2]+B[0]
else:
d=B[ind-1]+B[ind+1]
dd=(b-ai)//d
if dd==0:
if b==ai:
continue
ans=-1
break
ans+=dd
B[ind]-=d*dd
push(B[ind],ind)
print(ans)
|
p02941
|
n=int(eval(input()))
A=[int(i) for i in input().split()]
B=[int(i) for i in input().split()]
from heapq import heappop, heappush
push = lambda x,i: heappush(BB,(-x,i))
BB=[]
for i in range(n):
push(B[i],i)
ans=0
chk=0
while chk<n:
b,ind=heappop(BB)
b,ai=-b,A[ind]
if b<ai:
ans=-1
break
d=B[(ind-1)%n]+B[(ind+1)%n]
dd=(b-ai)//d
if dd==0:
if b==ai:
chk+=1
continue
ans=-1
break
ans+=dd
B[ind]-=d*dd
push(b-d*dd,ind)
print(ans)
|
n=int(eval(input()))
A=[int(i) for i in input().split()]
B=[int(i) for i in input().split()]
from heapq import heappop, heappush
push = lambda x,i: heappush(BB,(-x,i))
BB=[]
for i,b in enumerate(B):
push(b,i)
ans=0
while BB:
b,ind=heappop(BB)
b,ai=-b,A[ind]
if b<ai:
ans=-1
break
d=B[(ind-1)%n]+B[(ind+1)%n]
dd=(b-ai)//d
if dd==0:
if b==ai:
continue
ans=-1
break
ans+=dd
B[ind]-=d*dd
push(b-d*dd,ind)
print(ans)
|
p02941
|
n=int(eval(input()))
A=[int(i) for i in input().split()]
B=[int(i) for i in input().split()]
from heapq import heappop, heappush
push = lambda x,i: heappush(BB,(-x,i))
BB=[]
for i,b in enumerate(B):
push(b,i)
ans=0
while BB:
b,ind=heappop(BB)
b,ai=-b,A[ind]
if b<ai:
ans=-1
break
d=B[(ind-1)%n]+B[(ind+1)%n]
dd=(b-ai)//d
if dd==0:
if b==ai:
continue
ans=-1
break
ans+=dd
B[ind]-=d*dd
push(b-d*dd,ind)
print(ans)
|
n=int(eval(input()))
A=[int(i) for i in input().split()]
B=[int(i) for i in input().split()]
key=2**18
from heapq import heappop, heappush
push = lambda x,i: heappush(BB,-(x*key+i))
BB=[]
for i,b in enumerate(B):
push(b,i)
ans=0
while BB:
bb=heappop(BB)
bb=-bb
b,ind=bb//key,bb%key
ai=A[ind]
if b<ai:
ans=-1
break
d=B[(ind-1)%n]+B[(ind+1)%n]
dd=(b-ai)//d
if dd==0:
if b==ai:
continue
ans=-1
break
ans+=dd
B[ind]-=d*dd
push(B[ind],ind)
print(ans)
|
p02941
|
import heapq
N = int(eval(input()))
A = list(map(int, input().split()))
Temp = input().split()
B = []
for i in range(N):
heapq.heappush(B, (-int(Temp[i]), i))
now = list(map(int, Temp))
complete = [False]*N
fin = [True]*N
ans = 0
while True:
v, i = heapq.heappop(B)
if A[i] == now[i]:
complete[i] = True
if not complete[i]:
if i == 0:
nv = v + now[-1] + now[1]
elif i == N-1:
nv = v + now[0] + now[-2]
else:
nv = v + now[i-1] + now[i+1]
if nv <= -A[i]:
heapq.heappush(B, (nv, i))
now[i] = -nv
ans += 1
if not B:
if complete == fin:
break
else:
print((-1))
exit()
print(ans)
|
import heapq
N = int(eval(input()))
A = list(map(int, input().split()))
B = input().split()
C = []
for i in range(N):
heapq.heappush(C, (A[i] - int(B[i]), i))
B = list(map(int, B))
ans = 0
while True:
v, i = heapq.heappop(C)
if v == 0:
break
nv = B[i-1] + B[(i+1) % N]
n = -v // nv
if n <= 0:
print((-1))
exit()
v += n * nv
B[i] -= n * nv
heapq.heappush(C, (v, i))
ans += n
print(ans)
|
p02941
|
def calc(l):
A1=2*(l[1][0]-l[0][0])
B1=2*(l[1][1]-l[0][1])
C1=l[0][0]**2-l[1][0]**2+l[0][1]**2-l[1][1]**2
A2=2*(l[2][0]-l[0][0])
B2=2*(l[2][1]-l[0][1])
C2=l[0][0]**2-l[2][0]**2+l[0][1]**2-l[2][1]**2
X=(B1*C2-B2*C1)/(A1*B2-A2*B1)
Y=(C1*A2-C2*A1)/(A1*B2-A2*B1)
R=((X-l[0][0])**2+(Y-l[0][1])**2)**0.5
return tuple(map(round, [X,Y,R], [3]*3))
l=[list(zip(*[iter(map(float,input().split()))]*2)) for i in range(eval(input()))]
for ll in l:
print("%.3f %.3f %.3f"%(calc(ll)))
|
def calc(a,b,c,d,e,f):
A1=2*(c-a)
B1=2*(d-b)
C1=a**2-c**2+b**2-d**2
A2=2*(e-a)
B2=2*(f-b)
C2=a*a-e*e+b*b-f*f
X=(B1*C2-B2*C1)/(A1*B2-A2*B1)
Y=(C1*A2-C2*A1)/(A1*B2-A2*B1)
R=((X-a)**2+(Y-b)**2)**0.5
return tuple(map(round, [X,Y,R], [3]*3))
l=[list(map(float,input().split())) for i in range(eval(input()))]
for ll in l:
print("%.3f %.3f %.3f"%(calc(*ll)))
|
p00010
|
for _ in range(int(eval(input()))):
x1, y1, x2, y2, x3, y3 = list(map(float, input().split()))
d = 2 * (x2 * y3 - x3 * y2 + x3 * y1 - x1 * y3 + x1 * y2 - x2 * y1)
px = ((y2 - y3) * (x1 ** 2 + y1 ** 2) + (y3 - y1) * (x2 ** 2 + y2 ** 2) + (y1 - y2) * (x3 ** 2 + y3 ** 2)) / d
py = -1 * ((x2 - x3) * (x1 ** 2 + y1 ** 2) + (x3 - x1) * (x2 ** 2 + y2 ** 2) + (x1 - x2) * (x3 ** 2 + y3 ** 2)) / d
print(('{0:.3f} {1:.3f} {2:.3f}'.format(px, py, ((x1 - px) ** 2 + (y1 - py) ** 2) ** 0.5)))
|
for _ in[0]*int(eval(input())):
a,d,b,e,c,f=list(map(float,input().split()))
z=2*(b*f-c*e+c*d-a*f+a*e-b*d)
x=((e-f)*(a**2+d**2)+(f-d)*(b**2+e**2)+(d-e)*(c**2+f**2))/z
y=((c-b)*(a**2+d**2)+(a-c)*(b**2+e**2)+(b-a)*(c**2+f**2))/z
print(('{0:.3f} {1:.3f} {2:.3f}'.format(x,y,((a-x)**2+(d-y)**2)**0.5)))
|
p00010
|
from heapq import heappop as pop
from heapq import heappush as push
INF = 1000000000000
while True:
R = int(eval(input()))
if not R:
break
w1, h1, x1, y1 = list(map(int, input().split()))
x1 -= 1
y1 -= 1
lst1 = [list(map(int, input().split())) for _ in range(h1)]
used1 = [[False] * w1 for _ in range(h1)]
w2, h2, x2, y2 = list(map(int, input().split()))
x2 -= 1
y2 -= 1
lst2 = [list(map(int, input().split())) for _ in range(h2)]
used2 = [[False] * w2 for _ in range(h2)]
def bfs(lst, used, que, w, h):
v, y, x = pop(que)
if y > 0 and not used[y - 1][x]:
push(que, (lst[y - 1][x], y - 1, x))
used[y - 1][x] = True
if h > y + 1 and not used[y + 1][x]:
push(que, (lst[y + 1][x], y + 1, x))
used[y + 1][x] = True
if x > 0 and not used[y][x - 1]:
push(que, (lst[y][x - 1], y, x - 1))
used[y][x - 1] = True
if w > x + 1 and not used[y][x + 1]:
push(que, (lst[y][x + 1], y, x + 1))
used[y][x + 1] = True
return v
que = [(1, y1, x1)]
used1[y1][x1] = True
rec1 = [[0, 0]]
Max = 0
acc = 0
while que:
v = bfs(lst1, used1, que, w1, h1)
acc += 1
if v > Max:
rec1.append([v, acc])
Max = v
else:
rec1[-1][1] += 1
que = [(1, y2, x2)]
used2[y2][x2] = True
rec2 = [[0, 0]]
Max = 0
acc = 0
while que:
v = bfs(lst2, used2, que, w2, h2)
acc += 1
if v > Max:
rec2.append([v, acc])
Max = v
else:
rec2[-1][1] += 1
end1 = len(rec1)
end2 = len(rec2)
ind1 = 0
ind2 = end2 - 1
ans = INF
# print(rec1)
# print(rec2)
while ind1 < end1 and ind2 > 0:
r1, sum1 = rec1[ind1]
r2, sum2 = rec2[ind2]
if sum1 + sum2 < R:
ind1 += 1
continue
while ind2 > 0 and sum1 + sum2 >= R:
ind2 -= 1
r2, sum2 = rec2[ind2]
if ind2 == 0 and sum1 + sum2 >= R:
ans = min(ans, r1 + r2)
break
else:
if ind2 < end2 - 1:
ind2 += 1
r2, sum2 = rec2[ind2]
ans = min(ans, r1 + r2)
ind1 += 1
print(ans)
|
from heapq import heappop as pop
from heapq import heappush as push
INF = 1000000000000
def solve():
while True:
R = int(eval(input()))
if not R:
break
w1, h1, x1, y1 = list(map(int, input().split()))
x1 -= 1
y1 -= 1
lst1 = [list(map(int, input().split())) for _ in range(h1)]
used1 = [[False] * w1 for _ in range(h1)]
w2, h2, x2, y2 = list(map(int, input().split()))
x2 -= 1
y2 -= 1
lst2 = [list(map(int, input().split())) for _ in range(h2)]
used2 = [[False] * w2 for _ in range(h2)]
def bfs(lst, used, que, w, h):
v, y, x = pop(que)
if y > 0 and not used[y - 1][x]:
push(que, (lst[y - 1][x], y - 1, x))
used[y - 1][x] = True
if h > y + 1 and not used[y + 1][x]:
push(que, (lst[y + 1][x], y + 1, x))
used[y + 1][x] = True
if x > 0 and not used[y][x - 1]:
push(que, (lst[y][x - 1], y, x - 1))
used[y][x - 1] = True
if w > x + 1 and not used[y][x + 1]:
push(que, (lst[y][x + 1], y, x + 1))
used[y][x + 1] = True
return v
def make_dic(lst, w, h, x, y):
que = [(1, y, x)]
used = [[False] * w for _ in range(h)]
used[y][x] = True
dic = [[0, 0]]
app = dic.append
Max = 0
acc = 0
while que:
v = bfs(lst, used, que, w, h)
acc += 1
if v > Max:
app([v, acc])
Max = v
else:
dic[-1][1] += 1
return dic
dic1 = make_dic(lst1, w1, h1, x1, y1)
dic2 = make_dic(lst2, w2, h2, x2, y2)
end1 = len(dic1)
end2 = len(dic2)
ind1 = 0
ind2 = end2 - 1
ans = INF
while ind1 < end1 and ind2 > 0:
r1, sum1 = dic1[ind1]
r2, sum2 = dic2[ind2]
if sum1 + sum2 < R:
ind1 += 1
continue
while ind2 > 0 and sum1 + sum2 >= R:
ind2 -= 1
r2, sum2 = dic2[ind2]
if ind2 == 0 and sum1 + sum2 >= R:
rs = r1 + r2
if rs < ans:
ans = rs
break
else:
if ind2 < end2 - 1:
ind2 += 1
r2 = dic2[ind2][0]
rs = r1 + r2
if rs < ans:
ans = rs
ind1 += 1
print(ans)
solve()
|
p00465
|
from random import randint
D = int(input())
C = list(map(int, input().split()))
S = [list(map(int, input().split())) for _ in range(D)]
T = []
for i in range(D):
l = S[i].index(max(S[i]))
T.append(l+1)
print(*T, sep="\n")
|
D = int(input())
C = list(map(int, input().split()))
S = [list(map(int, input().split())) for _ in range(D)]
T = []
for i in range(D):
l = S[i].index(max(S[i]))
T.append(l+1)
print(*T, sep="\n")
|
p02618
|
D = int(eval(input()))
c = list(map(int, input().split()))
last = [0] * 26
ans = []
S = []
prev_score = 0
maxsi_list = []
for d in range(1, D+1):
s = list(map(int, input().split()))
S += [s]
maxs = float('-inf')
maxss = float('-inf')
maxi = -1
maxii = -1
cumsump = 0
for i in range(26):
tmp = -c[i] * (d - last[i])
cumsump += tmp
for i in range(26):
tmp = -c[i] * (d - last[i])
tmp2 = s[i] + cumsump - tmp
if tmp2 > maxs:
maxs = tmp2
maxi = i
if s[i] > maxss:
maxii = i
maxss = s[i]
ans += [maxi+1]
last[maxi] = d
prev_score += maxs
maxsi_list += [maxii+1]
best_ans = ans
best_score = prev_score
mergin = 1300
for tt in range(31):
for dd in range(D):
last = [0] * 26
score = 0
for d in range(1, D+1):
if dd == (d-1):
maxc = 0
maxci = -1
for i in range(26):
cost = c[i] * (d - last[i])
if maxc < cost:
maxc = cost
maxci = i+1
prev_a = ans[dd]
ans[dd] = maxci
td = ans[d-1] - 1
cumsump = 0
for i in range(26):
if td != i:
tmp = -c[i] * (d - last[i])
cumsump += tmp
last[td] = d
score += S[d-1][td]+cumsump
if score <= prev_score-mergin:
ans[dd] = prev_a
elif best_score < score:
best_ans = ans
best_score = score
prev_score = score
else:
prev_score = score
for dd in range(D):
last = [0] * 26
score = 0
prev_a = ans[dd]
ans[dd] = maxsi_list[dd]
for d in range(1, D+1):
td = ans[d-1] - 1
cumsump = 0
for i in range(26):
if td != i:
tmp = -c[i] * (d - last[i])
cumsump += tmp
last[td] = d
score += S[d-1][td]+cumsump
if score <= prev_score-mergin:
ans[dd] = prev_a
elif best_score < score:
best_ans = ans
best_score = score
prev_score = score
else:
prev_score = score
for a in best_ans:
print(a)
|
D = int(eval(input()))
c = list(map(int, input().split()))
last = [0] * 26
ans = []
S = []
prev_score = 0
maxsi_list = []
for d in range(1, D+1):
s = list(map(int, input().split()))
S += [s]
maxs = float('-inf')
maxss = float('-inf')
maxi = -1
maxii = -1
cumsump = 0
for i in range(26):
tmp = -c[i] * (d - last[i])
cumsump += tmp
for i in range(26):
tmp = -c[i] * (d - last[i])
tmp2 = s[i] + cumsump - tmp
if tmp2 > maxs:
maxs = tmp2
maxi = i
if s[i] > maxss:
maxii = i
maxss = s[i]
ans += [maxi+1]
last[maxi] = d
prev_score += maxs
maxsi_list += [maxii+1]
best_ans = ans
best_score = prev_score
# mergin = 1300
mergin = 13000
for tt in range(31):
for dd in range(D):
last = [0] * 26
score = 0
for d in range(1, D+1):
if dd == (d-1):
maxc = 0
maxci = -1
for i in range(26):
cost = c[i] * (d - last[i])
if maxc < cost:
maxc = cost
maxci = i+1
prev_a = ans[dd]
ans[dd] = maxci
td = ans[d-1] - 1
cumsump = 0
for i in range(26):
if td != i:
tmp = -c[i] * (d - last[i])
cumsump += tmp
last[td] = d
score += S[d-1][td]+cumsump
# if score <= prev_score-mergin:
if score <= best_score-mergin:
ans[dd] = prev_a
elif best_score < score:
best_ans = ans
best_score = score
prev_score = score
else:
prev_score = score
for dd in range(D):
last = [0] * 26
score = 0
prev_a = ans[dd]
ans[dd] = maxsi_list[dd]
for d in range(1, D+1):
td = ans[d-1] - 1
cumsump = 0
for i in range(26):
if td != i:
tmp = -c[i] * (d - last[i])
cumsump += tmp
last[td] = d
score += S[d-1][td]+cumsump
# if score <= prev_score-mergin:
if score <= best_score-mergin:
ans[dd] = prev_a
elif best_score < score:
best_ans = ans
best_score = score
prev_score = score
else:
prev_score = score
for a in best_ans:
print(a)
|
p02618
|
def main():
from builtins import int, map, list, print, len
from collections import defaultdict
import sys
sys.setrecursionlimit(10 ** 6)
input = (lambda: (sys.stdin.readline()).rstrip())
input_list = (lambda: input().split())
input_number = (lambda: int(input()))
input_number_list = (lambda: list(map(int, input_list())))
D = input_number()
c = input_number_list()
last = defaultdict(lambda: 0)
s = []
for i in range(D):
s.append(input_number_list())
for i in range(D):
t_idx = 0
t_pt = 0
for j in range(len(s[i])):
pt = s[i][j] + (i - last[j]) * c[j]
if t_pt < pt:
t_idx = j
t_pt = pt
elif t_pt == pt:
if c[t_idx] < c[j]:
t_idx = j
t_pt = pt
print(t_idx + 1)
if __name__ == '__main__':
main()
|
def main():
from builtins import int, map, list, print, len
from collections import defaultdict
import sys
sys.setrecursionlimit(10 ** 6)
input = (lambda: (sys.stdin.readline()).rstrip())
input_list = (lambda: input().split())
input_number = (lambda: int(input()))
input_number_list = (lambda: list(map(int, input_list())))
D = input_number()
c = input_number_list()
last = defaultdict(lambda: 0)
s = []
c_pt = c.copy()
c_total = sum(c)
ans_pt = 0
for i in range(D):
s.append(input_number_list())
for i in range(D):
pt_ls = s[i].copy()
# 一番ポイント高いのを選ぶ
t_idx = pt_ls.index(max(pt_ls))
ans_pt += pt_ls[t_idx]
# 不幸値を計算
for j in range(len(c)):
if j == t_idx:
# リセット
c_pt[j] = c[j]
else:
ans_pt -= c_pt[j]
c_pt[j] += c[j]
# 出力
print(t_idx + 1)
# 選択したものの不幸値をリセット
c_pt[t_idx] = 0
if __name__ == '__main__':
main()
|
p02618
|
D = int(eval(input()))
A = [[0]*26]*D
S = 0
C = list(map(int,input().split()))
P = 0
ld =[0]*26#最後に行った日の格納
l = [0]*26#損失の計算
sp = 0#一時格納
for i in range(D):
A[i] = list(map(int,input().split()))
for j in range(D):
maxvalue = max(A[j])
index = A[j].index(maxvalue)
for n in range(26):
ld[n] = ld[n]+1
sp = ld[index]
ld[index] = 0
for k in range(26):
l[k] = C[k]*ld[k]
lmax =max(l)
if 13*lmax > maxvalue:
lindex = l.index(lmax)
ld[index] = sp
ld[lindex] = 0
for m in range(26):
l[m] = C[m]*ld[m]
S = S+maxvalue-sum(l)
print((index+1))
|
D = int(eval(input()))
A = [[0]*26]*D
S = 0
C = list(map(int,input().split()))
P = 0
ld =[0]*26#最後に行った日の格納
l = [0]*26#損失の計算
sp = 0#一時格納
t = [0]*D
for i in range(D):
A[i] = list(map(int,input().split()))
for j in range(D):
maxvalue = max(A[j])
index = A[j].index(maxvalue)
for n in range(26):
ld[n] = ld[n]+1
sp = ld[index]
ld[index] = 0
for k in range(26):
l[k] = C[k]*ld[k]
lmax =max(l)
if 13*lmax > maxvalue:
lindex = l.index(lmax)
ld[index] = sp
ld[lindex] = 0
for m in range(26):
l[m] = C[m]*ld[m]
S = S+maxvalue-sum(l)
t[j] = index+1
for num in range(D):
print((t[num]))
|
p02618
|
D = int(eval(input()))
C = list(map(int, input().split()))
for i in range(D):
S = list(map(int, input().split()))
print((S.index(max(S))+1))
|
D = int(eval(input()))
C = list(map(int, input().split()))
ans = []
for i in range(D):
S = list(map(int, input().split()))
ans.append(S.index(max(S))+1)
for e in ans:
print(e)
|
p02618
|
import math
import fractions
#import sys
#input = sys.stdin.readline
def make_divisors(n):
divisors = []
for i in range(1, int(n**0.5)+1):
if n % i == 0:
divisors.append(i)
if i != n // i:
divisors.append(n//i)
# divisors.sort()
return divisors
def ValueToBits(x,digit):
res = [0 for i in range(digit)]
now = x
for i in range(digit):
res[i]=now%2
now = now >> 1
return res
def BitsToValue(arr):
n = len(arr)
ans = 0
for i in range(n):
ans+= arr[i] * 2**i
return ans
def ZipArray(a):
aa = [[a[i],i]for i in range(n)]
aa.sort(key = lambda x : x[0])
for i in range(n):
aa[i][0]=i+1
aa.sort(key = lambda x : x[1])
b=[aa[i][0] for i in range(len(a))]
return b
def ValueToArray10(x, digit):
ans = [0 for i in range(digit)]
now = x
for i in range(digit):
ans[digit-i-1] = now%10
now = now //10
return ans
def Zeros(a,b):
if(b<=-1):
return [0 for i in range(a)]
else:
return [[0 for i in range(b)] for i in range(a)]
class Bit:
def __init__(self, n):
self.size = n
self.tree = [0] * (n + 1)
def sum(self, i):
s = 0
while i > 0:
s += self.tree[i]
i -= i & -i
return s
def add(self, i, x):
while i <= self.size:
self.tree[i] += x
i += i & -i
'''
def cmb(n, r, p):
if (r < 0) or (n < r):
return 0
r = min(r, n - r)
return fact[n] * factinv[r] * factinv[n-r] % p
p = 2
N = 10 ** 6 + 2
fact = [1, 1] # fact[n] = (n! mod p)
factinv = [1, 1] # factinv[n] = ((n!)^(-1) mod p)
inv = [0, 1] # factinv 計算用
for i in range(2, N + 1):
fact.append((fact[-1] * i) % p)
inv.append((-inv[p % i] * (p // i)) % p)
factinv.append((factinv[-1] * inv[-1]) % p)
'''
#a = list(map(int, input().split()))
#################################################
#################################################
#################################################
#################################################
n = int(eval(input()))
c = list(map(int, input().split()))
a = []
for i in range(n):
temp = list(map(int, input().split()))
a.append(temp)
ans = [(i%26) for i in range(n)]
def cost(a,c,ans):
val = 0
last = [0 for i in range(26)]
for i in range(n):
for j in range(26):
last += 1
here = ans[i]
val += a[i][here]
last[here] = 0
for j in range(26):
val -= last[j]*c[j]
return val
#
for i in range(n):
maxim = -10**9
idx = -1
for j in range(26):
if(maxim < a[i][j]):
idx = j
maxim = a[i][j]
ans[i] = idx
#print(ans)
#d = [[i,c[i]]]
for i in ans:
print((i+1))
|
import math
import fractions
#import sys
#input = sys.stdin.readline
def make_divisors(n):
divisors = []
for i in range(1, int(n**0.5)+1):
if n % i == 0:
divisors.append(i)
if i != n // i:
divisors.append(n//i)
# divisors.sort()
return divisors
def ValueToBits(x,digit):
res = [0 for i in range(digit)]
now = x
for i in range(digit):
res[i]=now%2
now = now >> 1
return res
def BitsToValue(arr):
n = len(arr)
ans = 0
for i in range(n):
ans+= arr[i] * 2**i
return ans
def ZipArray(a):
aa = [[a[i],i]for i in range(n)]
aa.sort(key = lambda x : x[0])
for i in range(n):
aa[i][0]=i+1
aa.sort(key = lambda x : x[1])
b=[aa[i][0] for i in range(len(a))]
return b
def ValueToArray10(x, digit):
ans = [0 for i in range(digit)]
now = x
for i in range(digit):
ans[digit-i-1] = now%10
now = now //10
return ans
def Zeros(a,b):
if(b<=-1):
return [0 for i in range(a)]
else:
return [[0 for i in range(b)] for i in range(a)]
class Bit:
def __init__(self, n):
self.size = n
self.tree = [0] * (n + 1)
def sum(self, i):
s = 0
while i > 0:
s += self.tree[i]
i -= i & -i
return s
def add(self, i, x):
while i <= self.size:
self.tree[i] += x
i += i & -i
'''
def cmb(n, r, p):
if (r < 0) or (n < r):
return 0
r = min(r, n - r)
return fact[n] * factinv[r] * factinv[n-r] % p
p = 2
N = 10 ** 6 + 2
fact = [1, 1] # fact[n] = (n! mod p)
factinv = [1, 1] # factinv[n] = ((n!)^(-1) mod p)
inv = [0, 1] # factinv 計算用
for i in range(2, N + 1):
fact.append((fact[-1] * i) % p)
inv.append((-inv[p % i] * (p // i)) % p)
factinv.append((factinv[-1] * inv[-1]) % p)
'''
#a = list(map(int, input().split()))
#################################################
#################################################
#################################################
#################################################
n = int(eval(input()))
c = list(map(int, input().split()))
a = []
for i in range(n):
temp = list(map(int, input().split()))
a.append(temp)
ans = [(i%26) for i in range(n)]
def cost(a,c,ans):
val = 0
last = [0 for i in range(26)]
for i in range(n):
for j in range(26):
last += 1
here = ans[i]
val += a[i][here]
last[here] = 0
for j in range(26):
val -= last[j]*c[j]
return val
#
for i in range(n):
maxim = -10**9
idx = -1
for j in range(26):
if(maxim < a[i][j]):
idx = j
maxim = a[i][j]
ans[i] = idx
#print(ans)
#d = [[i,c[i]]]
for i in range(n):
if(i//26%2==0):
print((ans[i]+1))
else:
print((i%26+1))
|
p02618
|
from time import time
start = time()
D = int(eval(input()))
C = [int(i) for i in input().split()]
scores = [[int(i) for i in input().split()] for j in range(D)]
t = []
for i in scores:
t.append(i.index(max(i))+1)
DC = [0]*26
def calcScore(t):
score = []
S = 0
last = [0]*26
for d in range(1,D+1):
S += scores[d-1][t[d-1]-1]
last[t[d-1]-1] = d
for i in range(26):
S -= C[i] * (d - last[i])
DC[i] += (d - last[i])
score.append(S)
return score[-1]
ts = calcScore(t)
i = 0
j = 1
while time() - start < 2:
d,q = i, j
temp = [t[i] if d-1 != i else q for i in range(D)]
j += 1
if calcScore(temp) > ts:
t = temp
i += 1
j = 0
print(("\n".join(map(str, t))))
|
from time import time
start = time()
D = int(eval(input()))
C = [int(i) for i in input().split()]
scores = [[int(i) for i in input().split()] for j in range(D)]
t = []
for i in scores:
t.append(i.index(max(i))+1)
DC = [0]*26
def calcScore(t):
score = []
S = 0
last = [0]*26
for d in range(1,D+1):
S += scores[d-1][t[d-1]-1]
last[t[d-1]-1] = d
for i in range(26):
S -= C[i] * (d - last[i])
DC[i] += (d - last[i])
score.append(S)
return score[-1]
ts = calcScore(t)
i = 0
j = 1
while time() - start < 1.95:
d,q = i, j
temp = [t[i] if d-1 != i else q for i in range(D)]
j += 1
if calcScore(temp) > ts:
t = temp
i += 1
j = 0
print(("\n".join(map(str, t))))
|
p02618
|
from time import time
start = time()
D = int(eval(input()))
C = [int(i) for i in input().split()]
scores = [[int(i) for i in input().split()] for j in range(D)]
t = []
for i in scores:
t.append(i.index(max(i))+1)
DC = [0]*26
def calcScore(t):
score = []
S = 0
last = [0]*26
for d in range(1,D+1):
S += scores[d-1][t[d-1]-1]
last[t[d-1]-1] = d
for i in range(26):
S -= C[i] * (d - last[i])
DC[i] += (d - last[i])
score.append(S)
return score[-1]
ts = calcScore(t)
i = 0
j = 1
while time() - start < 1.95:
d,q = i, j
temp = [t[i] if d-1 != i else q for i in range(D)]
j += 1
if calcScore(temp) > ts:
t = temp
i += 1
j = 0
print(("\n".join(map(str, t))))
|
from time import time
start = time()
D = int(eval(input()))
C = [int(i) for i in input().split()]
scores = [[int(i) for i in input().split()] for j in range(D)]
t = []
for i in scores:
t.append(i.index(max(i))+1)
DC = [0]*26
def calcScore(t):
score = []
S = 0
last = [0]*26
for d in range(1,D+1):
S += scores[d-1][t[d-1]-1]
last[t[d-1]-1] = d
for i in range(26):
S -= C[i] * (d - last[i])
DC[i] += (d - last[i])
score.append(S)
return score[-1]
from random import randint
ts = calcScore(t)
i = 0
while time() - start < 1.8:
d,q = i, randint(1,26)
temp = [t[i] if d-1 != i else q for i in range(D)]
if calcScore(temp) > ts:
t = temp
i += 1
print(("\n".join(map(str, t))))
|
p02618
|
d=int(eval(input()))
C=[int(i) for i in input().split()]
s=[[int(i) for i in input().split()] for q in range(d)]
sco=0
L=[0 for i in range(26)]
ans=[]
#calc
for i in range(d):
mayou=0
est=s[i][0]+C[0]*(i+1-L[0])
for p in range(1,26):
if s[i][p]+C[p]*(i+1-L[p]) > est:
mayou=p
est=s[i][p]+C[p]*(i+1-L[p])
ans.append(mayou)
print((mayou+1)) #output
##以下表示
"""
L=[0 for i in range(26)]
for q in range(d):
t=ans[q]
sco+=s[q][t]
L[t]=q+1
for i in range(26):
if L[i]!=-1:
sco-=C[i]*(q+1-L[i])
print(sco)
"""
|
d=int(eval(input()))
C=[int(i) for i in input().split()]
s=[[int(i) for i in input().split()] for q in range(d)]
sco=0
L=[0 for i in range(26)]
ans=[]
#calc
for i in range(d):
mayou=0
est=s[i][0]+C[0]*(i+1-L[0])
for p in range(1,26):
if s[i][p]+C[p]*(i+1-L[p]) > est:
mayou=p
est=s[i][p]+C[p]*(i+1-L[p])
ans.append(mayou)
print((mayou+1)) #output
|
p02618
|
def choose(D, c, s, d, last, depth, p):
maxpoint = -999999
maxnum = 0
if depth > 0 and d < D:
for i in range(26):
point = p
point += s[d][i]
point += changepoint(c, d, i, last)
nlast = []
nlast.extend(last)
nlast[i] = d
z, point = choose(D, c, s, d+1, nlast, depth-1, point)
if point > maxpoint:
maxpoint = point
maxnum = i
return maxnum, maxpoint
return 0, p
def changepoint(c, d, num, last):
point = 0
for j in range(26):
if j != num:
point -= c[j]*(d-last[j])
return point
def main():
D = int(eval(input()))
c = list(map(int, input().split()))
s = []
last = [-1]*26
for _ in range(D):
s.append(list(map(int, input().split())))
point = 0
for i in range(D):
num, point = choose(D, c, s, i, last, 2, 0)
print((num+1))
main()
|
def choose(D, c, s, d, last, depth, p):
maxpoint = -999999
maxnum = 0
if depth > 0 and d < D:
for i in range(26):
point = p
point += s[d][i]
point += changepoint(c, d, i, last)
nlast = []
nlast.extend(last)
nlast[i] = d
z, point = choose(D, c, s, d+1, nlast, depth-1, point)
if point > maxpoint:
maxpoint = point
maxnum = i
return maxnum, maxpoint
return 0, p
def changepoint(c, d, num, last):
point = 0
for j in range(26):
if j != num:
point -= c[j]*(d-last[j])
return point
def main():
D = int(eval(input()))
c = list(map(int, input().split()))
s = []
last = [-1]*26
for _ in range(D):
s.append(list(map(int, input().split())))
point = 0
for i in range(D):
num, point = choose(D, c, s, i, last, 1, 0)
print((num+1))
main()
|
p02618
|
import sys
import math
from collections import deque
import heapq
import itertools
from decimal import Decimal
import bisect
from operator import itemgetter
MAX_INT = int(10e18)
MIN_INT = -MAX_INT
mod = 1000000000+7
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return eval(input())
def tami(now, ContestType):
res = c[ContestType] * (now - LastDay[ContestType])
return res
def nasu(now, x, y, z):
res = 0
res += s[now-1][x]
res += s[now][y]
res += s[now+1][z]
if x == y == z:
res += (D - now) * ((D - LastDay[x]) * c[x])
now += 1
res += (D - now) * (1 * c[y])
now += 1
res += (D - now) * (1 * c[z])
elif x == y:
res += (D - now) * ((D - LastDay[x]) * c[x])
now += 1
res += (D - now) * (1 * c[y])
now += 1
res += (D - now) * ((D - LastDay[z]) * c[z])
elif y == z:
res += (D - now) * ((D - LastDay[x]) * c[x])
now += 1
res += (D - now) * ((D - LastDay[y]) * c[y])
now += 1
res += (D - now) * (1 * c[z])
elif x == z:
res += (D - now) * ((D - LastDay[x]) * c[x])
now += 1
res += (D - now) * ((D - LastDay[y]) * c[y])
now += 1
res += (D - now) * (2 * c[z])
else:
res += (D - now) * ((D - LastDay[x]) * c[x])
now += 1
res += (D - now) * ((D - LastDay[y]) * c[y])
now += 1
res += (D - now) * ((D - LastDay[z]) * c[z])
return res
D = I()
c = IL()
s = [IL() for i in range(D)]
LastDay = [0]*26
for i in range(1,D+1-3):
tmp = ["", 0]
for x in range(26):
for y in range(26):
for z in range(26):
score = nasu(i, x, y, z)
if tmp[1] < score:
tmp = [(x, y, z), score]
LastDay[tmp[0][0]] = i
print((tmp[0][0]+1))
else:
tmp = ["", 0]
for x in range(26):
for y in range(26):
for z in range(26):
score = nasu(D-2, x, y, z)
if tmp[1] < score:
tmp = [(x, y, z), score]
for i in tmp[0]:
print((i+1))
|
import sys
import math
from collections import deque
import heapq
import itertools
from decimal import Decimal
import bisect
from operator import itemgetter
MAX_INT = int(10e18)
MIN_INT = -MAX_INT
mod = 1000000000+7
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return eval(input())
def tami(now, ContestType):
res = c[ContestType] * (now - LastDay[ContestType])
return res
def nasu(now, x, y, z):
res = 0
res += s[now-1][x]
res += s[now][y]
res += s[now+1][z]
if x == y == z:
res += (D - now) * ((now - LastDay[x]) * c[x])
now += 1
res += (D - now) * (1 * c[y])
now += 1
res += (D - now) * (1 * c[z])
elif x == y:
res += (D - now) * ((now - LastDay[x]) * c[x])
now += 1
res += (D - now) * (1 * c[y])
now += 1
res += (D - now) * ((now - LastDay[z]) * c[z])
elif y == z:
res += (D - now) * ((now - LastDay[x]) * c[x])
now += 1
res += (D - now) * ((now - LastDay[y]) * c[y])
now += 1
res += (D - now) * (1 * c[z])
elif x == z:
res += (D - now) * ((now - LastDay[x]) * c[x])
now += 1
res += (D - now) * ((now - LastDay[y]) * c[y])
now += 1
res += (D - now) * (2 * c[z])
else:
res += (D - now) * ((now - LastDay[x]) * c[x])
now += 1
res += (D - now) * ((now - LastDay[y]) * c[y])
now += 1
res += (D - now) * ((now - LastDay[z]) * c[z])
return res
D = I()
c = IL()
s = [IL() for i in range(D)]
LastDay = [0]*26
for i in range(1,D+1-3):
tmp = ["", 0]
for x in range(26):
for y in range(26):
for z in range(26):
score = nasu(i, x, y, z)
if tmp[1] < score:
tmp = [(x, y, z), score]
LastDay[tmp[0][0]] = i
print((tmp[0][0]+1))
else:
tmp = ["", 0]
for x in range(26):
for y in range(26):
for z in range(26):
score = nasu(D-2, x, y, z)
if tmp[1] < score:
tmp = [(x, y, z), score]
for i in tmp[0]:
print((i+1))
|
p02618
|
import sys
import math
from collections import deque
import heapq
import itertools
from decimal import Decimal
import bisect
from operator import itemgetter
MAX_INT = int(10e18)
MIN_INT = -MAX_INT
mod = 1000000000+7
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return eval(input())
def tami(now, ContestType):
res = c[ContestType] * (now - LastDay[ContestType])
return res
def nasu(now, x, y, z):
res = 0
res += s[now-1][x]
res += s[now][y]
res += s[now+1][z]
if x == y == z:
res += (D - now) * ((now - LastDay[x]) * c[x])
now += 1
res += (D - now) * (1 * c[y])
now += 1
res += (D - now) * (1 * c[z])
elif x == y:
res += (D - now) * ((now - LastDay[x]) * c[x])
now += 1
res += (D - now) * (1 * c[y])
now += 1
res += (D - now) * ((now - LastDay[z]) * c[z])
elif y == z:
res += (D - now) * ((now - LastDay[x]) * c[x])
now += 1
res += (D - now) * ((now - LastDay[y]) * c[y])
now += 1
res += (D - now) * (1 * c[z])
elif x == z:
res += (D - now) * ((now - LastDay[x]) * c[x])
now += 1
res += (D - now) * ((now - LastDay[y]) * c[y])
now += 1
res += (D - now) * (2 * c[z])
else:
res += (D - now) * ((now - LastDay[x]) * c[x])
now += 1
res += (D - now) * ((now - LastDay[y]) * c[y])
now += 1
res += (D - now) * ((now - LastDay[z]) * c[z])
return res
D = I()
c = IL()
s = [IL() for i in range(D)]
LastDay = [0]*26
for i in range(1,D+1-2):
tmp = ["", 0]
for x in range(26):
for y in range(26):
for z in range(26):
score = nasu(i, x, y, z)
if tmp[1] < score:
tmp = [(x, y, z), score]
LastDay[tmp[0][0]] = i
print((tmp[0][0]+1))
else:
print((tmp[0][1]+1))
print((tmp[0][2]+1))
|
import sys
import math
from collections import deque
import heapq
import itertools
from decimal import Decimal
import bisect
from operator import itemgetter
MAX_INT = int(10e18)
MIN_INT = -MAX_INT
mod = 1000000000+7
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return eval(input())
def tami(date, LastDay, type, score):
res = score
res += s[date-1][type]
for i in range(26):
if i == type:
continue
res -= (date - LastDay[i]) *c[i]
return res
def nasu():
res = []
for d in range(1,D+1):
tmp1 = ["", 0]
tmp2 = ["", 0]
for i in range(26):
if tmp1[1] < (d - LastDay[i]) * c[i]:
tmp1 = [i, (d - LastDay[i]) * c[i]]
if tmp2[1] < s[d-1][i]:
tmp2 = [i, s[d-1][i]]
if tmp1[1] > tmp2[1]:
res.append(tmp1[0])
else:
res.append(tmp2[0])
LastDay[res[-1]] = d
return res
D = I()
c = IL()
s = [IL() for i in range(D)]
LastDay = [0]*26
score = 0
ans = nasu()
for i in ans:
print((i+1))
"""
for d in range(D):
score = tami(d+1, LastDay, ans[d]-1, score)
LastDay[ans[d]-1] = d+1
print(score)
"""
|
p02618
|
D = int(eval(input()))
c = list(map(int, input().split()))
s = [list(map(int, input().split())) for _ in range(D)]
last = [-1]*26
ans = 0
for d in range(D):
stack = []
for i in range(26):
if (d-last[i])*c[i]<0:
stack.append(i)
if stack:
tmp, res = 0, 0
for i in stack:
if tmp<s[d][i]:
tmp, res = s[d][i], i
last[res] = d
print((res+1))
else:
tmp, res = 0, 0
for i in range(26):
if tmp<s[d][i]:
tmp, res = s[d][i], i
last[res] = d
print((res+1))
|
D = int(eval(input()))
c = list(map(int, input().split()))
s = [list(map(int, input().split())) for _ in range(D)]
do_list = [-1]*D
for i in range(D):
tmp, res = s[i][0], 0
for j in range(1,26):
if tmp<s[i][j]:
tmp, res = s[i][j], j
do_list[i] = res
for i in do_list: print((i+1))
|
p02618
|
import copy
D = int(eval(input()))
c = list(map(int,input().split()))
s = [ [0 for j in range(26)] for i in range(D)]
for i in range(D):
tmp = list(map(int,input().split()))
for j in range(26):
s[i][j] = tmp[j]
t = []
v = [0] * D
last = [ [0 for j in range(26)] for i in range(D)]
sum = 0
for i in range(D):
max = -10000
for j in range(26):
tmp_sum = sum
tmp_last = copy.deepcopy(last)
tmp_sum += s[i][j]
tmp_last[i][j] = i+1
for k in range(26):
tmp_sum -= c[k] * ( (i+1) - tmp_last[i][j] )
if tmp_sum > max:
max_j = j
max = tmp_sum
last[i][j] = i+1
sum = max
t.append(max_j+1)
for i in range(D):
print((t[i]))
|
import copy
D = int(eval(input()))
c = list(map(int,input().split()))
s = [ [0 for j in range(26)] for i in range(D)]
for i in range(D):
tmp = list(map(int,input().split()))
for j in range(26):
s[i][j] = tmp[j]
t = []
v = [0] * D
last = [ [0 for j in range(26)] for i in range(D)]
sum = 0
for i in range(D):
max = -10000
tmp_last = copy.deepcopy(last)
for j in range(26):
tmp_sum = sum
if j != 0:
tmp_last[i][j-1] = last[i][j-1]
tmp_sum += s[i][j]
tmp_last[i][j] = i+1
for k in range(26):
tmp_sum -= c[k] * ( (i+1) - tmp_last[i][j] )
if tmp_sum > max:
max_j = j
max = tmp_sum
last[i][j] = i+1
sum = max
t.append(max_j+1)
for i in range(D):
print((t[i]))
|
p02618
|
D = int(eval(input()))
C = list(map(int, input().split()))
SS = [list(map(int, input().split())) for i in range(D)]
Last = [-1] * 26
for d in range(D):
S = SS[d]
t = -1
x = -1e100
for i, s in enumerate(S):
score = s - sum(c * d - (max(last, 0)) for c, last in zip(C, Last))
if score > x:
x = score
t = i
print((t + 1))
|
D = int(eval(input()))
C = list(map(int, input().split()))
SS = [list(map(int, input().split())) for i in range(D)]
Last = [-1] * 26
for d in range(D):
S = SS[d]
t = -1
x = -1e100
minus=sum(c * (d-max(last, 0)) for c, last in zip(C, Last))
for i, s in enumerate(S):
score = s - minus + C[i] * (d - max(Last[i], 0))
if score > x:
x = score
t = i
print((t + 1))
|
p02618
|
d = int(eval(input()))
clst = list(map(int, input().split()))
s = [list(map(int, input().split())) for _ in range(d)]
last = [0 for _ in range(26)]
def score_minus(d, q):
minus = 0
for i, (c, ls) in enumerate(zip(clst, last)):
if i == d:
continue
minus += c * (d - ls)
return minus
ans = 0
for i in range(d):
tmp = 0
for q in range(26):
tmp_score = s[i][q] - score_minus(i, q)
if tmp_score > tmp:
tmp = tmp_score
max_q = q
print((max_q + 1))
last[max_q] = i
|
d = int(eval(input()))
clst = list(map(int, input().split()))
s = [list(map(int, input().split())) for _ in range(d)]
last = [0 for _ in range(26)]
def score_minus(d, q):
minus = 0
for i, (c, ls) in enumerate(zip(clst, last)):
if i == d:
continue
minus += c * (d - ls)
return minus
ans = 0
for i in range(1, d + 1):
tmp = -10 ** 10
for q in range(26):
tmp_score = s[i - 1][q] - score_minus(i, q)
if tmp_score > tmp:
tmp = tmp_score
max_q = q
print((max_q + 1))
last[max_q] = i
|
p02618
|
import sys
readline = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
#mod = 998244353
INF = 10**18
eps = 10**-7
D = int(readline())
C = list(map(int,readline().split()))
S = [list(map(int,readline().split())) for i in range(D)]
for s in S:
ansidx = 0
anssum = 0
for i,si in enumerate(s,start=1):
if anssum < si:
ansidx = i
anssum = si
print(ansidx)
|
import sys
readline = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
#mod = 998244353
INF = 10**18
eps = 10**-7
D = int(readline())
C = list(map(int,readline().split()))
S = [list(map(int,readline().split())) for i in range(D)]
past = -1
for s in S:
ansidx = 0
anssum = 0
for i,si in enumerate(s,start=1):
if anssum < si and past != i:
ansidx = i
anssum = si
print(ansidx)
past = ansidx
|
p02618
|
from copy import copy
d = int(eval(input()))
c = [0] + list(map(int, input().split(' ')))
s = [[]] + [[0] + list(map(int, input().split(' '))) for _ in range(d)]
t = 0 # 算出結果
ca = [0] * (1 + 26) # 放置された不満の数々
cat = [] # 不満度の最適な算出のための一時配列
cat2 = []
dc = 0 # カレントな満足度
#dl = [] # 満足度のログ
for i in range(1, d + 1):
cat = [0]
for i2 in range(1, 27):
cat2 = copy(ca)
cat2[i2] = i
cat.append(s[i][i2] + sum(c[i3] * (i - ca[i3]) for i3 in range(1, 27)))
t = cat.index(max(cat))
dc += s[i][t]
ca[t] = i
dc -= sum(c[i3] * (i - ca[i3]) for i3 in range(1, 27))
print(t)
|
from copy import copy
d = int(eval(input()))
c = [0] + list(map(int, input().split(' ')))
s = [[]] + [[0] + list(map(int, input().split(' '))) for _ in range(d)]
t = 0 # 算出結果
ca = [0] * (1 + 26) # 放置された不満の数々
cat = [] # 不満度の最適な算出のための一時配列
cat2 = []
for i in range(1, d + 1):
cat = [0]
for i2 in range(1, 27):
cat2 = copy(ca)
cat2[i2] = i
cat.append(s[i][i2] + sum(c[i3] * (i - ca[i3]) for i3 in range(1, 27)))
t = cat.index(max(cat))
ca[t] = i
print(t)
|
p02618
|
#coding:utf-8
import random
D = int(eval(input()))
C = [int(y) for y in input().split()]
S = []
ans = []
def scoring(inp,poi):
score = 0
day = 1
last = [0] * 26
for I in inp:
score += poi[day-1][I-1]
last[I-1] = day
for ind,J in enumerate(last):
score -= C[ind] * (day - ind - 1)
day += 1
return score
for i in range(D):
s = [int(y) for y in input().split()]
S.append(s)
for i in S:
k = 0
num = 0
for f,t in enumerate(i):
k = max(k,t)
if k == t:
num = f + 1
ans.append(num)
counter = 10000
base = scoring(ans,S)
nbase = 0
d = 0
ansc = ans.copy()
for i in range(counter):
p = random.randint(0,25)
q = random.randint(0,D-1)
ansc[q] = p
nbase = scoring(ansc,S)
if nbase > base:
ans = ansc.copy()
else:
ansc = ans.copy()
for i in ans:
print(("{}".format(int(i))))
|
#coding:utf-8
import random
D = int(eval(input()))
C = [int(y) for y in input().split()]
S = []
ans = []
def scoring(inp,poi):
score = 0
day = 1
last = [0] * 26
for I in inp:
score += poi[day-1][I-1]
last[I-1] = day
for ind,J in enumerate(last):
score -= C[ind] * (day - ind - 1)
day += 1
return score
for i in range(D):
s = [int(y) for y in input().split()]
S.append(s)
for i in S:
k = 0
num = 0
for f,t in enumerate(i):
k = max(k,t)
if k == t:
num = f + 1
ans.append(num)
counter = 100
base = scoring(ans,S)
nbase = 0
d = 0
ansc = ans.copy()
for i in range(counter):
p = random.randint(0,25)
q = random.randint(0,D-1)
ansc[q] = p
nbase = scoring(ansc,S)
if nbase > base:
ans = ansc.copy()
else:
ansc = ans.copy()
for i in ans:
print(("{}".format(int(i))))
|
p02618
|
import sys
readline = sys.stdin.readline
# 0-indexでやる
D = int(readline())
C = list(map(int,readline().split())) # 満足度の下がりやすさ
S = [None] * D
sortS = [None] * D
for i in range(D):
s = list(map(int,readline().split()))
S[i] = s.copy()
for j in range(len(s)):
s[j] = (s[j],j)
sortS[i] = sorted(s, key = lambda x:x[0], reverse = True)
def make_ans(D,C,limiter = 52, threshold = 42, balance = 0.8):
ans = []
last_submit = [0] * 26
for i in range(D):
info = sortS[i]
# limiter回以上提出がないものがあれば、threshold回を超えたもののうちCの値が高いものを提出
if i - min(last_submit) >= limiter:
ind = -1
for j in range(len(last_submit)):
if i - last_submit[j] >= threshold:
if ind == -1:
ind = j
else:
if C[ind] < C[j]:
ind = j
ans += [ind]
last_submit[ind] = i
continue
topval = info[0][0]
for j in range(len(info)):
val = info[j][0]
if val < topval * (balance):
continue # 最高値の半分になるのであればやめよう
index = info[j][1]
if i - last_submit[index] < 26:
continue
ans += [index]
last_submit[index] = i
break
else:
ans += [info[0][1]]
return ans
def calc_score(arr):
point = 0
last_submit = [0] * 26
for i in range(len(arr)):
# i日目
point += S[i][arr[i]]
for j in range(len(last_submit)):
point -= (i - last_submit[j]) * C[j]
return point
ans = make_ans(D,C)
#print(ans)
from collections import defaultdict
#used_limiter = defaultdict(int)
#used_threshold = defaultdict(int)
#used_balance = defaultdict(int)
best = calc_score(ans)
for limiter in range(40,62):
for threshold in range(36, limiter):
for balance in (0.75,0.8,0.85):
new_ans = make_ans(D,C,limiter,threshold,balance)
new_score = calc_score(new_ans)
if new_score > best:
ans = new_ans
best = new_score
# used_limiter[limiter] += 1
# used_threshold[threshold] += 1
# used_balance[balance] += 1
def show(arr):
for a in arr:
print((a + 1))
#print(used_limiter)
#print(used_threshold)
#print(used_balance)
show(ans)
|
import sys
readline = sys.stdin.readline
# 0-indexでやる
D = int(readline())
C = list(map(int,readline().split())) # 満足度の下がりやすさ
S = [None] * D
sortS = [None] * D
for i in range(D):
s = list(map(int,readline().split()))
S[i] = s.copy()
for j in range(len(s)):
s[j] = (s[j],j)
sortS[i] = sorted(s, key = lambda x:x[0], reverse = True)
def make_ans(D,C,limiter = 4, threshold = 2, balance = 0.5, check_limit = False):
ans = []
last_submit = [0] * 26
for i in range(D):
info = sortS[i]
if check_limit:
# limiter回以上提出がないものがあれば、threshold回を超えたもののうちCの値が高いものを提出
if i - min(last_submit) >= limiter:
ind = -1
for j in range(len(last_submit)):
if i - last_submit[j] >= threshold:
if ind == -1:
ind = j
else:
if C[ind] < C[j]:
ind = j
ans += [ind]
last_submit[ind] = i
continue
topval = info[0][0]
for j in range(len(info)):
val = info[j][0]
if check_limit:
if val < topval * (balance):
continue # 最高値の半分になるのであればやめよう
index = info[j][1]
if i - last_submit[index] < 26:
continue
ans += [index]
last_submit[index] = i
break
else:
ans += [info[0][1]]
return ans
def calc_score(arr):
point = 0
last_submit = [0] * 26
for i in range(len(arr)):
# i日目
point += S[i][arr[i]]
for j in range(len(last_submit)):
point -= (i - last_submit[j]) * C[j]
return point
ans = make_ans(D,C)
#print(ans)
best = calc_score(ans)
for limiter in range(36,52):
for threshold in range(26, limiter):
for balance in (0.25, 0.5, 0.75):
new_ans = make_ans(D,C,limiter,threshold,balance,True)
new_score = calc_score(new_ans)
if new_score > best:
ans = new_ans
best = new_score
def show(arr):
for a in arr:
print((a + 1))
show(ans)
|
p02618
|
D = int(eval(input()))
c = [int(_) for _ in input().split()]
s = [[int(_) for _ in input().split()] for _ in range(D)]
sat = 0
last = [0] * 26
for d in range(D):
v = 0
j = 0
for x in range(26):
if v < s[d][x]:
j = x
v = s[d][x]
last[j] = d + 1
print((j+1))
for i in range(26):
sat -= (d + 1 - last[i]) * c[i]
sat += s[d][j]
# print(sat)
|
D = int(eval(input()))
c = [int(_) for _ in input().split()]
s = [[int(_) for _ in input().split()] for _ in range(D)]
for d in range(D):
v = -20000
j = 0
for x in range(26):
if v < s[d][x]:
j = x
v = s[d][x]
print((j+1))
|
p02618
|
def main():
D = int(eval(input()))
C = list(map(int, input().split()))
S = [list(map(int, input().split()))for _ in range(D)]
len_C = len(C)
types = []
lasts = [0] * 26
for i in range(D):
s = max(S[i])
c = []
c_sum = 0
for j in range(len_C):
c.append((i + 1 - lasts[j]) * C[j])
c_sum += (i + 1 - lasts[j]) * C[j] # 満足度低下の合計
if c_sum >= s:
t = c.index(max(c)) + 1
lasts[t - 1] = i + 1
else:
t = S[i].index(s) + 1
types.append(t)
for type in types:
print(type)
if __name__ == '__main__':
main()
|
def main():
D = int(eval(input()))
C = list(map(int, input().split()))
S = [list(map(int, input().split()))for _ in range(D)]
len_C = len(C)
types = []
lasts = [0] * 26
for i in range(D):
s = max(S[i])
c = []
c_sum = 0
for j in range(len_C):
c.append((i + 1 - lasts[j]) * C[j])
c_sum += (i + 1 - lasts[j]) * C[j] # 満足度低下の合計
if c_sum >= s: # 低下が増加の最高値より高ければ一番大きい低下を無くす
t = c.index(max(c)) + 1
lasts[t - 1] = i + 1
else:
t = S[i].index(s) + 1
types.append(t)
for type in types:
print(type)
if __name__ == '__main__':
main()
|
p02618
|
D = int(eval(input()))
cs = list(map(int, input().split()))
#s = [input().split() for l in range(D)]
S=0
for d in range(D):
s=list(map(int, input().split()))
max_value = max(s)
max_index = s.index(max_value)
print((max_index+1))
S+=max_value
|
D = int(eval(input()))
cs = list(map(int, input().split()))
#s = [input().split() for l in range(D)]
S=0
l=[]
for d in range(D):
s=list(map(int, input().split()))
max_value = max(s)
max_index = s.index(max_value)
l.append(max_index+1)
S+=max_value
for i in range(D):
print((l[i]))
|
p02618
|
def lackSatisfaction(c, d, last):
lack = 0
max = 0
mindex = 0
for i in range(len(c)):
tmp = c[i] * (d - last[i])
lack += tmp
if (max < tmp):
max = tmp
mindex = i
return max, mindex
#365
D = int(eval(input()))
c = list(map(int, input().split()))
d = []
last = {}
for i in range(26):
last[i] = 0
for i in range(D):
s = list(map(int, input().split()))
rate = 0
type = 0
maxLack, mindex = lackSatisfaction(c, i + 1, last)
for j in range(len(s)):
if (rate < s[j]):
rate = s[j]
type = j + 1
if (maxLack < rate):
d.append(type)
else:
d.append(mindex)
last[type - 1] = i + 1
for i in range(len(d)):
print((d[i]))
|
def lackSatisfaction(c, d, last):
lack = 0
max = 0
mindex = 0
for i in range(len(c)):
tmp = c[i] * (d - last[i])
lack += tmp
if (max < tmp):
max = tmp
mindex = i
return max, mindex
#365
D = int(eval(input()))
c = list(map(int, input().split()))
d = []
last = {}
for i in range(26):
last[i] = 0
score = 0
for i in range(D):
s = list(map(int, input().split()))
rate = 0
type = 0
maxLack, mindex = lackSatisfaction(c, i + 1, last)
for j in range(len(s)):
if (rate < s[j]):
rate = s[j]
type = j + 1
if (maxLack < rate):
d.append(type)
else:
d.append(mindex + 1)
last[d[i] - 1] = i + 1
for i in range(len(d)):
print((d[i]))
|
p02618
|
from collections import deque
n = int(eval(input()))
s = input().rstrip() + "#"
dic = {"R": deque(), "G":deque(), "B":deque()}
prev_ch = s[0]
cnt = 1
ans = 1
for i, ch in enumerate(s[1:]):
if ch == prev_ch:
cnt += 1
else:
dic[prev_ch].append([cnt, i-1])
while dic["R"] and dic["G"] and dic["B"]:
r = dic["R"].popleft()
g = dic["G"].popleft()
b = dic["B"].popleft()
while(r[0] and g[0] and b[0]):
ans *= r[0] * g[0] * b[0] // cnt
r[0] -= 1; g[0] -= 1; b[0] -= 1
cnt -= 1
if r[0]:
dic["R"].appendleft(r)
if g[0]:
dic["G"].appendleft(g)
if b[0]:
dic["B"].appendleft(b)
cnt = 1
prev_ch = ch
for i in range(n):
ans *= (i+1)
print(ans)
|
#!/usr/bin/env python3
n = int(eval(input()))
s = input().rstrip()
MOD = 998244353
r = 0; g = 0; b = 0
rg = 0
gb = 0
br = 0
ans = 1
for ch in s:
if ch == "R":
if gb > 0:
ans *= gb
gb -= 1
elif g > 0:
ans *= g
g -= 1
rg += 1
elif b > 0:
ans *= b
b -= 1
br += 1
else:
r += 1
elif ch == "G":
if br > 0:
ans *= br
br -= 1
elif b > 0:
ans *= b
b -= 1
gb += 1
elif r > 0:
ans *= r
r -= 1
rg += 1
else:
g += 1
elif ch == "B":
if rg > 0:
ans *= rg
rg -= 1
elif g > 0:
ans *= g
g -= 1
gb += 1
elif r > 0:
ans *= r
r -= 1
br += 1
else:
b += 1
ans %= MOD
for i in range(n):
ans *= i+1
ans %= MOD
print(ans)
|
p02940
|
from functools import reduce
n = int(eval(input()))
s = input().strip()
MOD = 998244353
R = 1
G = 2
B = 4
RG = R + G
RB = R + B
GB = G + B
RGB = R + G + B
table = {'R': R, 'G': G, 'B': B}
counts = {
0: 0,
R: 0, G: 0, B: 0,
RG: 0, RB: 0, GB: 0,
}
patterns = 1
for cv in [table[c] for c in s]:
rest = RGB - cv
if counts[rest] > 0:
patterns *= counts[rest]
counts[rest] -= 1
elif sum([counts[v] for v in [R, G, B] if v != cv]) > 0:
for bc in [R, G, B]:
if rest & bc != 0 and counts[bc] > 0:
patterns *= counts[bc]
counts[bc] -= 1
counts[bc + cv] += 1
break
else:
counts[cv] += 1
print(((patterns * reduce(lambda o, v: o * v, list(range(1, n + 1)), 1)) % MOD))
|
from functools import reduce
n = int(eval(input()))
s = input().strip()
MOD = 998244353
R = 1
G = 2
B = 4
RG = R + G
RB = R + B
GB = G + B
RGB = R + G + B
table = {'R': R, 'G': G, 'B': B}
counts = {
0: 0,
R: 0, G: 0, B: 0,
RG: 0, RB: 0, GB: 0,
}
patterns = 1
for cv in [table[c] for c in s]:
rest = RGB - cv
if counts[rest] > 0:
patterns = (patterns * counts[rest]) % MOD
counts[rest] -= 1
elif R != cv and counts[R] > 0:
patterns = (patterns * counts[R]) % MOD
counts[R] -= 1
counts[R + cv] += 1
elif G != cv and counts[G] > 0:
patterns = (patterns * counts[G]) % MOD
counts[G] -= 1
counts[G + cv] += 1
elif B != cv and counts[B] > 0:
patterns = (patterns * counts[B]) % MOD
counts[B] -= 1
counts[B + cv] += 1
else:
counts[cv] += 1
print(((patterns * reduce(lambda o, v: (o * v) % MOD, list(range(1, n + 1)), 1)) % MOD))
|
p02940
|
inp = [int(n) for n in input().split(" ")]
res = inp[0] == inp[1] and inp[0] == inp[2] and 1 <= inp[0] <= 100
if res:
print("Yes")
else:
print("No")
|
n = [int(x) for x in input().split()]
res = 1 <= n[0] <= 100 and n[0] == n[1] == n[2]
if res:
print("Yes")
else:
print("No")
|
p03079
|
a,b,c=list(map(int,input().split()))
if a==b and b==c:
print("Yes")
else:
print("No")
|
A,B,C=list(map(int,input().split()))
if A==B and B==C:
print("Yes")
else:
print("No")
|
p03079
|
A, B, C = list(map(int, input().split()))
if A == B and B == C:
print('Yes')
else:
print('No')
|
li = set(map(int, input().split()))
print(('Yes' if len(li) == 1 else 'No'))
|
p03079
|
A, B, C = [i for i in input().split()]
print(('Yes' if A == B and B == C else 'No'))
|
a, b, c = [int(I) for I in input().split()]
print(('YNeos'[not(a == b and b == c)::2]))
|
p03079
|
s = input().strip()
n = len(s)
if s[0]==s[-1]:
if n%2==0:
print("First")
else:
print("Second")
else:
if n%2==0:
print("Second")
else:
print("First")
|
s = input().strip()
N = len(s)
if N%2==0 and s[0]==s[-1]:
print("First")
elif N%2==0 and s[0]!=s[-1]:
print("Second")
elif N%2==1 and s[0]==s[-1]:
print("Second")
else:
print("First")
|
p03863
|
s = input()
n = 0
while (len(s) > 2):
for i in range(1, len(s)-1):
if s[i-1] != s[i+1]:
s = s[0:i] + s[i+1:len(s)]
n += 1
break
if len(s) == 3 and s[0] == s[2]:
break
if n % 2 == 1:
print("First")
else:
print("Second")
|
s = input()
n = len(s)-2
if s[0] == s[len(s)-1]:
n -= 1
if n % 2 == 1:
print("First")
else:
print("Second")
|
p03863
|
import sys
def main():
s=list(sys.stdin.readline().strip())
t=0
while len(s)>2:
ps,cs,f=s[0],s[1],False
for i,ns in enumerate(s[2:],1):
if ps!=ns:
s.pop(i)
f,t=True,t^1
break
ps,cs=cs,ns
if f is False:
break
print('First') if t==1 else print('Second')
if __name__=='__main__':main()
|
import sys
def main():
s=list(sys.stdin.readline().strip())
t=0
while len(s)>2:
ps,cs,i,f=s[0],s[1],1,False
for ns in s[2:]:
if ps!=ns:
cs,f,t=ns,True,t^1
s.pop(i)
else:ps,cs,i=cs,ns,i+1
if f is False:break
print('First') if t==1 else print('Second')
if __name__=='__main__':main()
|
p03863
|
# -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0181
"""
import sys
from sys import stdin
input = stdin.readline
def Cond(m, n, mid, books):
if max(books) > mid:
return False
rem = mid
while books:
while rem >= books[0]:
rem -= books[0]
books = books[1:]
if len(books) == 0:
break
rem = mid
m -= 1
if m >= 0:
return True
else:
return False
def solve(m, n, books):
ub = 1500000
lb = 0
min_width = float('inf')
for i in range(100):
mid = (ub + lb) // 2
if Cond(m, n, mid, books):
min_width = min(min_width, mid)
ub = mid
else:
lb = mid
return min_width
def main(args):
while True:
m, n = list(map(int, input().split()))
if m == 0 and n == 0:
break
books = [int(eval(input())) for _ in range(n)]
result = solve(m, n, books)
print(result)
if __name__ == '__main__':
main(sys.argv[1:])
|
# -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0181
"""
import sys
from sys import stdin
input = stdin.readline
def Cond(m, n, mid, books):
if max(books) > mid:
return False
rem = mid
while books:
while rem >= books[0]:
rem -= books[0]
books = books[1:]
if len(books) == 0:
break
rem = mid
m -= 1
if m >= 0:
return True
else:
return False
def solve(m, n, books):
ub = 1500000
lb = 0
min_width = float('inf')
for i in range(50):
mid = (ub + lb) // 2
if Cond(m, n, mid, books):
min_width = min(min_width, mid)
ub = mid
else:
lb = mid
return min_width
def main(args):
while True:
m, n = list(map(int, input().split()))
if m == 0 and n == 0:
break
books = [int(eval(input())) for _ in range(n)]
result = solve(m, n, books)
print(result)
if __name__ == '__main__':
main(sys.argv[1:])
|
p00181
|
a, b, c = input().split()
colors = 0
if a == b and b == c:
colors = 1
elif a == b or b == c or c == a:
colors = 2
else:
colors = 3
print(colors)
|
s = set(input().split())
print((len(s)))
|
p03962
|
l=list(map(int,input().split()))
ls=[]
for i in l:
ls.append(i)
k=set(ls)
print((len(k)))
|
a,b,c=input().split()
if a==b==c:
print("1")
elif a==b or b==c or c==a:
print("2")
else:
print("3")
|
p03962
|
print((len(set(list(map(int,input().split()))))))
|
print((len(set(input().split()))))
|
p03962
|
l = [ int(x) for x in input().split() ]
l = set(l)
print((len(list(l))))
|
l = [ int(x) for x in input().split() ]
print((len(set(l))))
|
p03962
|
from collections import Counter
A,B,C = list(map(int,input().split()))
print((len(Counter([A,B,C]).most_common())))
|
A,B,C = list(map(int,input().split()))
print((len(set([A,B,C]))))
|
p03962
|
A,B,C = list(map(int,input().split()))
print((len(set([A,B,C]))))
|
# python3 (3.4.3)
import sys
input = sys.stdin.readline
# main
A,B,C = list(map(int,input().split()))
print((len({A,B,C})))
|
p03962
|
from collections import Counter
a = list(input().split())
print((len(Counter(a))))
|
a = list(map(int, input().split()))
print((len(set(a))))
|
p03962
|
import collections
p = [int(x) for x in input().split()]
c = collections.Counter(p)
print((len(c)))
|
p = [int(x) for x in input().split()]
print((len(set(p))))
|
p03962
|
a,b,c = list(map(int,input().split()))
if a == b == c:
print((1))
elif a == c or a == b or b == c:
print((2))
else:
print((3))
|
colors = list(map(int,input().split()))
print((len(set(colors))))
|
p03962
|
s = list(map(int, input().split()))
c = set(s)
print((len(c)))
|
p = list(map(int, input().split()))
print((len(set(p))))
|
p03962
|
a=list(map(int,input().split()))
s=set(a)
print((len(s)))
|
a=set(list(map(int,input().split())))
print((len(a)))
|
p03962
|
import collections
pen = list(map(str,input().split()))
print((len(collections.Counter(pen))))
|
a,b,c = list(map(int,input().split()))
if a == b == c:
print((1))
elif a == b or b == c or c ==a:
print((2))
else:
print((3))
|
p03962
|
print((len(set([x for x in input().split()]))))
|
print((len(set(input().split()))))
|
p03962
|
a,b,c=list(map(int, input().split()))
if a==b and a==c:
print((1))
elif a!=b and b!=c and c!=a:
print((3))
else:
print((2))
|
a,b,c=list(map(int, input().split()))
d={}
d[a]=1
d[b]=1
d[c]=1
print((len(d)))
|
p03962
|
a,b,c=list(map(int, input().split()))
d={}
d[a]=1
d[b]=1
d[c]=1
print((len(d)))
|
print((len(set(input().split()))))
|
p03962
|
m=998244353
M=1<<20
f=[0]*M
g=[0]*M
h=[0]*M
f[0]=g[0]=f[1]=g[1]=h[1]=1
for i in range(2,M):
f[i]=f[i-1]*i%m
h[i]=m-h[m%i]*(m//i)%m
g[i]=g[i-1]*h[i]%m
A,B=list(map(int,input().split()))
if A<B:A,B=B,A
a=0
b=1
for j in range(1,B+1):
a+=b*f[A+B-j]*g[B-j]*g[A]
b=b*2%m
print(((a*f[A]*f[B]*g[A+B]+A)%m))
|
m=998244353
M=1<<20
f=[1]*M
g=[1]*M
h=[1]*M
h[0]=0
for i in range(2,M):
f[i]=f[i-1]*i%m
h[i]=m-h[m%i]*(m//i)%m
g[i]=g[i-1]*h[i]%m
A,B=list(map(int,input().split()))
if A<B:A,B=B,A
a=0
b=1
for j in range(1,B+1):
a+=b*f[A+B-j]*g[B-j]*g[A]
b=b*2%m
print(((a*f[A]*f[B]*g[A+B]+A)%m))
|
p03622
|
M=8**7
m,f,g,i,a,b=M*476+1,[1],[1]*M,1,0,1
while i<M:f+=f[-1]*i%m,;i+=1
g[-1]=pow(f[-1],m-2,m)
while i>1:i-=1;g[i-1]=g[i]*i%m
A,B=list(map(int,input().split()))
if A<B:A,B=B,A
while i<=B:a+=b*f[A+B-i]*g[B-i];b=b*2%m;i+=1
print(((a*f[B]*g[A+B]+A)%m))
|
M=8**7
m,f,g,i=M*476+1,[j:=1],[k:=1]*M,1
while i<M:f+=f[-1]*i%m,;i+=1
g+=pow(M*f[-1],m-2,m),
while i:g[i-1]=g[i]*i%m;i-=1
A,B=list(map(int,input().split()))
if A<B:A,B=B,A
while j<=B:i+=k*f[A+B-j]*g[B-j];k=k*2%m;j+=1
print(((i*f[B]*g[A+B]+A)%m))
|
p03622
|
while True:
n = int(eval(input()))
if n == 0:
break
z = sorted([tuple(map(int, input().split())) for _ in range(n)], key=lambda x: x[1])
cnt = total = 0
for a, b in z:
total += a
if total > b:
break
cnt += 1
print(("Yes" if cnt == n else "No"))
|
while True:
n = int(eval(input()))
if n == 0:
break
z = sorted([tuple(map(int, input().split())) for _ in range(n)], key=lambda x: x[1])
cnt = total = 0
for a, b in z:
total += a
if total > b:
cnt = 1
break
print(("No" if cnt else "Yes"))
|
p00638
|
while 1:
n = int(input())
if n == 0:
break
bridge = [0 for i in range(n)]
gold = [0 for i in range(n)]
for i in range(n):
gold[i], bridge[i] = list(map(int,input().split(" ")))
dp = {0:0}
for i in range(n):
tmp_dp = dict()
for k,v in dp.items():
for j in range(n):
bit = 1 << j
if (k & bit != 0) or (k|bit in tmp_dp):
continue
if v + gold[j] <= bridge[j]:
tmp_dp[k|bit] = v + gold[j]
dp = tmp_dp
print("Yes" if (2**n - 1) in dp else "No")
|
while 1:
n = int(input())
if n == 0:
break
land = [list(map(int,input().split(" "))) for i in range(n)]
land.sort(key = lambda x:(x[1],x[0]))
gold = 0
for i in range(n):
gold += land[i][0]
if gold > land[i][1]:
print("No")
break
else:
print("Yes")
|
p00638
|
import sys
C = sys.stdin.readlines()
print((C[0][0]+C[1][1]+C[2][2]))
|
print((input()[0]+input()[1]+input()[2]))
|
p03415
|
l = [0] * 3
for i in range(3):
l[i] = list(input())
for i in range(3):
for j in range(3):
if i == j:
print(l[i][j], end='')
print("")
|
for i in range(3):
print(input()[i], end='')
print()
|
p03415
|
a=input()[0]
b=input()[1]
c=input()[2]
print((a+b+c))
|
a,b,c=[input()[i] for i in range(3)]
print((a+b+c))
|
p03415
|
print((''.join(input()[i]for i in range(3))))
|
print((open(0).read()[::5]))
|
p03415
|
N = int(eval(input()))
A = [int(eval(input())) for _ in range(N)]
if A[0] != 0:
print((-1))
exit()
ans = 0
tmp = 0
for num in reversed(A):
if tmp > 0:
if num == tmp-1:
tmp = num
elif num >= tmp:
ans += num
tmp = num
elif num < tmp-1:
print((-1))
exit()
else:
ans += num
tmp = num
print(ans)
|
N = int(eval(input()))
A = [int(eval(input())) for _ in range(N)]
#先頭は増やせないから0以外なら終わり
if A[0] != 0:
print((-1))
exit()
ans = 0
prev = 0
for n in reversed(A):
if prev != 0:
# 後ろから見て1ずつ減少する場合
if n == prev - 1:
prev = n
# 前以上のとき、新たにその数字のために階段を構成する(前の数字を作る仮定で作れない)ので、その分の操作数が必要
elif n >= prev:
ans += n
prev = n
# 2以上の差があると作れない
else:
print((-1))
exit()
else:
ans += n
prev = n
print(ans)
|
p03347
|
N = int(eval(input()))
A = [int(eval(input())) for i in range(N)]
if A[0] != 0:
print((-1))
exit()
for i in range(N - 1):
if A[i] < A[i + 1] and A[i + 1] - A[i] != 1:
print((-1))
exit()
if A[i] > i + 1:
print((-1))
exit()
ans = 0
i = 1
old = 0
while i != N:
if A[i] <= old:
ans += old
old = A[i]
i += 1
print((ans + A[-1]))
|
N = int(eval(input()))
A = [int(eval(input())) for i in range(N)]
if A[0] != 0:
print((-1))
exit()
for i in range(N - 1):
if A[i] < A[i + 1] and A[i + 1] - A[i] != 1:
print((-1))
exit()
if A[i] > i + 1:
print((-1))
exit()
ans = 0
for i in range(1, N):
if A[i-1] >= A[i]:
ans += A[i-1]
print((ans + A[-1]))
|
p03347
|
# AGC024C - Sequence Growing Easy
def main():
N, *A = list(map(int, open(0)))
A.append(0)
if A[0]: # corner case
print((-1))
return
ans = 0
for i, j in zip(A[::-1], A[::-1][1:]):
if i > j + 1:
print((-1))
return
if j >= i:
ans += j
print(ans)
if __name__ == "__main__":
main()
|
# AGC024C - Sequence Growing Easy
def main():
N, *A = list(map(int, open(0)))
if A[0]: # can't increment A_0
print((-1))
return
A.append(0)
ans, B = 0, A[::-1]
for i, j in zip(B, B[1:]): # check from the last
if i > j + 1: # increment from left one must be 0 or 1
print((-1))
return
if j >= i: # left one is an end of subsequence
ans += j
print(ans)
if __name__ == "__main__":
main()
|
p03347
|
import heapq
class Value:
def __init__(self, val, f):
self.val = val
self.key = f(val)
def __lt__(self, other):
return self.key < other.key
def __repr__(self):
return repr(self.val)
class Heapq:
def __init__(self, arr, f=lambda x: x):
for i in range(len(arr)):
arr[i] = Value(arr[i], f)
self.func = f
self.hq = arr
heapq.heapify(self.hq)
def pop(self):
return heapq.heappop(self.hq).val
def push(self, a):
heapq.heappush(self.hq, Value(a, self.func))
def top(self):
return self.hq[0].val
n = int(eval(input()))
a = [int(eval(input())) for _ in range(n)]
if a[0] > 0:
print((-1))
exit(0)
hq = Heapq([], f=lambda x: (-a[x], x))
for i, x in enumerate(a):
if x > 0:
hq.push(i)
ans = 0
while hq.hq:
i = hq.pop()
if a[i] - 1 == a[i - 1]:
ans += 1
a[i] = (a[i + 1] - 1 if i != n - 1 else 0)
if a[i] > 0:
hq.push(i)
else:
print((-1))
exit(0)
print(ans)
|
n = int(eval(input()))
a = [int(eval(input())) for _ in range(n)] + [0]
if a[0] > 0:
print((-1))
else:
ans = 0
for i in range(n):
if a[i] < a[i + 1] - 1:
print((-1))
break
elif a[i] >= a[i + 1]:
ans += a[i]
else:
print(ans)
|
p03347
|
N = int(eval(input()))
A = [0]*N
for i in range(N):
A[i] = int(eval(input()))
B = [0]*N
possible = True
tot = 0
for i in range(N):
if A[-(i+1)] > N-i-1:
possible = False
break
elif B[-(i+1)] > A[-(i+1)]:
possible = False
break
elif B[-(i+1)] == A[-(i+1)]:
continue
else:
if i == 0:
B[-(i+1+A[-(i+1)]):] = list(range(A[-(i+1)]+1))
tot += A[-(i+1)]
else:
B[-(i+1+A[-(i+1)]):-i] = list(range(A[-(i+1)]+1))
tot += A[-(i+1)]
if not possible:
print((-1))
else:
print(tot)
|
N = int(eval(input()))
A = [0]*N
for i in range(N):
A[i] = int(eval(input()))
B = [0]*N
possible = True
tot = 0
if A[0] == 0:
for i in range(N-1):
if A[-(i+1)] > N-i-1:
possible = False
break
elif B[-(i+1)] > A[-(i+1)]:
possible = False
break
elif B[-(i+1)] == A[-(i+1)]:
B[-(i+2)] = A[-(i+1)]-1
continue
else:
B[-(i+2)] = A[-(i+1)]-1
tot += A[-(i+1)]
if not possible:
print((-1))
else:
print(tot)
else:
print((-1))
|
p03347
|
n=int(eval(input()))
l=[int(eval(input())) for _ in range(n)]
ans=0
if l[0]!=0:
print((-1))
exit()
for i in range(n-1):
if l[i+1]-l[i]>1:
print((-1))
exit()
elif (l[i]+1==l[i+1]):
ans+=1
else:
ans+=l[i+1]
print(ans)
|
n=int(eval(input()))
l=[int(eval(input())) for _ in range(n)]
ans=0
if l[0]!=0:
print((-1))
exit()
for i in range(n-1):
if (l[i]+1==l[i+1]):
ans+=1
elif (l[i]>=l[i+1]):
ans+=l[i+1]
else:
print((-1))
exit()
print(ans)
|
p03347
|
#!/usr/bin/env python3
#AGC24 C
import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
n = I()
a = [I() for _ in range(n)]
if a[0] != 0:
print((-1))
quit()
for i in range(1,n):
if a[i] - a[i-1] > 1:
print((-1))
quit()
ans = 0
for i in range(1,n):
if a[i] == a[i-1] and a[i] > 0:
ans += a[i]
elif a[i] == a[i-1] + 1:
ans += 1
elif a[i] < a[i-1]:
ans += a[i]
print(ans)
|
#!/usr/bin/env python3
#AGC24 C
import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
n = I()
a = [I() for _ in range(n)]
if a[0] != 0:
print((-1))
quit()
for i in range(1,n):
if a[i] - a[i-1] > 1:
print((-1))
quit()
ans = 0
for i in range(1,n):
if a[i] <= a[i-1]:
ans += a[i]
continue
if a[i] == a[i-1] + 1:
ans += 1
continue
print(ans)
|
p03347
|
N = int( eval(input()))
A = [ int( eval(input())) for _ in range(N)]
now = 0
ans = 0
if A[0] != 0:
ans = -1
else:
for i in range(1,N):
if A[i] > i:
ans = -1
break
elif now + 1 == A[i]:
ans += 1
now += 1
elif now >= A[i]:
ans += A[i]
now = A[i]
else:
ans = -1
break
print(ans)
|
N = int( eval(input()))
A = [ int( eval(input())) for _ in range(N)]
now = 0
ans = 0
if A[0] != 0:
ans = -1
else:
for i in range(1,N):
a = A[i]
if a > i:
ans = -1
break
elif now + 1 == a:
ans += 1
now += 1
elif now >= a:
ans += a
now = a
else:
ans = -1
break
print(ans)
|
p03347
|
N = int( eval(input()))
A = [ int( eval(input())) for _ in range(N)]
now = 0
ans = 0
if A[0] != 0:
ans = -1
else:
for i in range(1,N):
# if A[i] > i:
# ans = -1
# break
if now + 1 == A[i]:
ans += 1
now += 1
elif now >= A[i]:
ans += A[i]
now = A[i]
else:
ans = -1
break
print(ans)
|
N = int( eval(input()))
A = [ int( eval(input())) for _ in range(N)]
now = 0
ans = 0
if A[0] != 0:
ans = -1
else:
for i in range(1,N):
a = A[i]
# if a > i:
# ans = -1
# break
#el
if now + 1 == a:
ans += 1
now += 1
elif now >= a:
ans += a
now = a
else:
ans = -1
break
print(ans)
|
p03347
|
n = int(eval(input()))
a = []
for i in range(n):
a.append(int(eval(input())))
flag = True
for i in range(n - 1):
if a[i + 1] - a[i] >= 2:
flag = False
if a[0] != 0:
flag = False
count = 0
start = 0
if flag == True:
while a != [0] * n:
for i in range(start, n - 1):
if a[i] + 1 == a[i + 1]:
start = i
break
for j in range(start, n - 1):
if a[j] + 1 != a[j + 1]:
end = j
break
if j == n - 2:
end = n - 1
for k in range(end, start - 1, -1):
if end != n - 1:
a[k] = max(0, a[k + 1] - 1)
else:
a[k] = 0
count = count + end - start
if flag == False:
print((-1))
else:
print(count)
|
n = int(eval(input()))
a = []
for i in range(n):
a.append(int(eval(input())))
flag = True
for i in range(n - 1):
if a[i + 1] - a[i] >= 2:
flag = False
if a[0] != 0:
flag = False
count = 0
if flag == True:
for i in range(n - 1):
if a[i] != 0:
count = count + 1
if a[i] >= a[i + 1]:
count = count + max(0, a[i + 1] - 1)
if flag == False:
print((-1))
elif a[n - 1] != 0:
print((count + 1))
else:
print(count)
|
p03347
|
n = int(eval(input()))
a = [int(eval(input())) for _ in range(n)]
ans, tmp = 0, 0
for i in range(n - 1, 0, -1):
if a[i] - a[i - 1] > 1:
print((-1))
break
if tmp != a[i]:
ans += a[i]
tmp = max(a[i] - 1, 0)
else:
print((ans if a[0] == 0 else - 1))
|
n = int(eval(input()))
a = [int(eval(input())) for _ in range(n)]
ans, tmp = 0, 0
for i in range(n - 1, 0, -1):
if a[i] - a[i - 1] > 1:
print((-1))
break
if tmp != a[i]:
ans += a[i]
tmp = max(a[i] - 1, 0)
else:
print((-1 if a[0] > 0 else ans))
|
p03347
|
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(eval(input()))
def MAP(): return list(map(int, input().split()))
def LIST(): return list(map(int, input().split()))
def TUPLE(): return tuple(map(int, input().split()))
def ZIP(n): return list(zip(*(MAP() for _ in range(n))))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
#mod = 998244353
from decimal import *
#import numpy as np
#decimal.getcontext().prec = 10
N = INT()
A = [INT() for _ in range(N)]
tmp = 0
cnt = 0
for i in range(N-1, -1, -1):
tmp -= 1
if i < A[i]:
print((-1))
exit()
elif A[i] < tmp:
print((-1))
exit()
elif tmp < A[i]:
cnt += A[i]
tmp = A[i]
print(cnt)
|
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(eval(input()))
def MAP(): return list(map(int, input().split()))
def LIST(): return list(map(int, input().split()))
def TUPLE(): return tuple(map(int, input().split()))
def ZIP(n): return list(zip(*(MAP() for _ in range(n))))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
#mod = 998244353
from decimal import *
#import numpy as np
#decimal.getcontext().prec = 10
N = INT()
A = [INT() for _ in range(N)]
ans = 0
tmp = A[0]
for i, a in enumerate(A):
if i < a or tmp+1 < a:
print((-1))
break
if a != tmp+1:
ans += tmp
tmp = a
else:
ans += tmp
print(ans)
|
p03347
|
N = int(eval(input()))
A = [[]]
for _ in range(N):
a = int(eval(input()))
if len(A[-1]) > 0 and a < A[-1][-1]:
A.append([])
A[-1].append(a)
def isOk():
for l, r in zip(A, A[1:]):
if l[-1] + 1 < r[0]:
return False
for grp in A:
for l, r in zip(grp, grp[1:]):
if l + 1 < r:
return False
return A[0][0] == 0
if not isOk():
print((-1))
exit()
B = []
for a in A:
B.extend(a)
B = [-10**18] + B[::-1]
ans = 0
for r, l in zip(B, B[1:]):
if l >= r:
ans += l
print(ans)
|
import sys
input = sys.stdin.buffer.readline
N = int(eval(input()))
G = [[]]
A = []
for _ in range(N):
a = int(eval(input()))
if len(G[-1]) > 0 and G[-1][-1] > a:
G.append([])
A.append(a)
G[-1].append(a)
def isOk():
if any(l[-1] + 1 < r[0] for l, r in zip(G, G[1:])):
return False
for grp in G:
if any(l + 1 < r for l, r in zip(grp, grp[1:])):
return False
return A[0] == 0
if not isOk():
print((-1))
exit()
ans = 0
A = [-10**18] + A[::-1]
for r, l in zip(A, A[1:]):
if l >= r:
ans += l
print(ans)
|
p03347
|
n = int(eval(input()))
a = [int(eval(input())) for _i in range(n)] + [-1]
result = -1
for i in range(n):
if a[i-1] >= a[i]:
result += a[i]
elif a[i-1] + 1 == a[i]:
result += 1
else:
result = -1
break
print(result)
|
n,r=int(eval(input())),-1
a = [int(eval(input())) for _i in range(n)]+[-1]
for i in range(n):
if a[i-1] >= a[i]:r+=a[i]
elif a[i-1]+1==a[i]:r+=1
else:r=-1;break
print(r)
|
p03347
|
n = int(eval(input()))
A = [-1]
for _ in range(n):
A.append(int(eval(input())))
X = [0]*(n+1)
count = 0
if A[1] != 0:
print((-1))
else:
for i in range(n,0,-1):
if A[i] > X[i]:
for j in range(A[i]):
X[i-j] = A[i] - j
count += A[i]
elif A[i] < X[i]:
print((-1))
break
else:
print(count)
|
n = int(eval(input()))
A = [-1]
for _ in range(n):
A.append(int(eval(input())))
num = 0
count = 0
if A[1] != 0:
print((-1))
else:
for i in range(n,0,-1):
if A[i] > num:
num = A[i]
count += num
elif A[i] < num:
print((-1))
break
num -= 1
else:
print(count)
|
p03347
|
n=int(eval(input()))
a=[int(eval(input())) for _ in range(n)]
#a(n+1)!=0の時、a(n+1)=a(n)+1である
cnt=0
if a[0]!=0:
print((-1))
exit()
b=[0]*n
#print(a)
for ii in range(1,n):
i=n-ii
if a[i]==b[i]:
continue
elif a[i]<b[i] or a[i]>i:
print((-1))
exit()
else:
for k in range(a[i]+1):
b[i-k]=a[i]-k
cnt+=a[i]
#print(b)
print(cnt)
"""
t: 0 1 1 0 1 2 2 1 2
s: 0 0 0 0 0 0 0 0 0
1: 0 0 1 0 0 0 0 0 0
2: 0 1 1 0 0 0 0 0 0
3: 0 1 1 0 0 0 0 1 0
4: 0 1 1 0 0 0 0 1 2
5: 0 1 1 0 0 1 0 1 2
"""
|
n=int(eval(input()))
a=[int(eval(input())) for _ in range(n)]
#a(n+1)!=0の時、a(n+1)=a(n)+1である
cnt=0
if a[0]!=0:
print((-1))
exit()
#print(" ".join(list(map(str,a))))
for ii in range(1,n):
i=n-ii
if a[i]==0:
continue
elif a[i]<=a[i-1]:
cnt+=a[i]
elif a[i]==a[i-1]+1:
cnt+=1
elif a[i]>a[i-1]+1 or a[i]>i:
print((-1))
exit()
#print(b)
#print(" "*(i+1),"^",cnt)
print(cnt)
"""
t: 0 1 1 0 1 2 2 1 2
s: 0 0 0 0 0 0 0 0 0
1: 0 0 1 0 0 0 0 0 0
2: 0 1 1 0 0 0 0 0 0
3: 0 1 1 0 0 0 0 1 0
4: 0 1 1 0 0 0 0 1 2
5: 0 1 1 0 0 1 0 1 2
"""
|
p03347
|
N = int(eval(input()))
A = [int(eval(input())) for _ in range(N)][::-1]
if A[-1] != 0:
print((-1))
else:
bef = A[0]
c, ans = 0, 0
for i in A:
if bef!=i:
if bef-i > 1:
print((-1))
break
ans += bef*c
c = 1 if bef<i else 0
else:
c += 1
bef = i
else:
print(ans)
|
N = int(eval(input()))
A = [int(eval(input())) for _ in range(N)][::-1]
if A[-1]:
print((-1))
else:
bef = A[0]
c, ans = 0, 0
for i in A:
if bef!=i:
if bef-i > 1:
ans = -1
break
ans += bef*c
c = 1 if bef<i else 0
else:
c += 1
bef = i
print(ans)
|
p03347
|
n = int(eval(input()))
a = [int(eval(input())) for _ in range(n)]
ans = 0
if a[0] != 0:
print((-1))
exit()
for i in range(n-1):
if a[i+1] - a[i] > 1:
print((-1))
exit()
for _ in range(n):
if set(a) == set([-1,0]) or set(a) == set([0]):
break
i = a.index(max(a))
if i == 0:
print((-1))
exit()
if a[i-1] + 1 == a[i]:
a[i] = -1
ans += 1
elif a[i-1] == -1:
a[i-1] = a[i] - 1
a[i] = -1
ans += 1
else:
print((-1))
exit()
print(ans)
|
n = int(eval(input()))
prev = ans = -1
a = [int(eval(input())) for _ in range(n)]
for i in a:
if i - prev > 1:
print((-1))
exit()
elif i - prev == 1:
ans += 1
else:
ans += i
prev = i
print(ans)
|
p03347
|
N = int(eval(input()))
A = [int(eval(input())) for i in range(N)]
if A[0]:
print((-1))
exit()
ans = 0
for a,b in zip(A,A[1:]):
if b-a > 1:
print((-1))
exit()
if b==0: continue
if b-a == 1:
ans += 1
else:
ans += b
print(ans)
|
N = int(eval(input()))
A = [int(eval(input())) for i in range(N)]
if A[0]:
print((-1))
exit()
ans = 0
for a,b in zip(A,A[1:]):
if a+1 < b:
print((-1))
exit()
if a+1 == b:
ans += 1
else:
ans += b
print(ans)
|
p03347
|
n = int(eval(input()))
A = [int(eval(input()))for _ in range(n)]
if A[0] != 0:
print((-1))
exit()
ans = A[-1]
for a, prev_a in reversed(tuple(zip(A, A[1:]))):
if a == prev_a-1:
continue
if a < prev_a-1:
print((-1))
break
ans += a
else:
print(ans)
|
n = int(eval(input()))
ans = -1
prev = -1
for _ in range(n):
a = int(eval(input()))
if prev+1 == a:
prev = a
ans += 1
continue
if prev+1 < a:
print((-1))
break
ans += a
prev = a
else:
print(ans)
|
p03347
|
n = int(eval(input()))
a = []
for i in range(n):
a.append(int(eval(input())))
if a[0] > 0:
print((-1))
exit()
for i in range(1, n):
if a[i] > i:
print((-1))
exit()
if a[i] > a[i-1] + 1:
print((-1))
exit()
result = 0
last = n
b = [0 for i in range(n)]
while 1:
for i in range(last):
j = last - i - 1
if a[j] != b[j]:
start = j
last = j
max_diff = a[j]
break
if j == 0:
print(result)
exit()
for i in range(max_diff):
b[start - i] = max_diff - i
result += max_diff
|
n = int(eval(input()))
a = []
for i in range(n):
a.append(int(eval(input())))
if a[0] > 0:
print((-1))
exit()
for i in range(1, n):
if a[i] > i:
print((-1))
exit()
if a[i] > a[i - 1] + 1:
print((-1))
exit()
if n == 1:
print((0))
exit()
result = 0
if a[n-1] != 0:
result += a[n-1]
for i in range(2, n):
j = n - i
if a[j] != 0 and a[j] != a[j + 1] - 1:
result += a[j]
print(result)
|
p03347
|
n, *a = list(map(int, open(0).read().split()))
# hantei
ok = True
for i in range(n - 1):
if a[i + 1] - a[i] > 1:
ok = False
if not ok or a[0] != 0:
print((-1))
exit()
ans = 0
a = list(reversed(a))
i = 0
while i < n:
ans += a[i]
while i < n - 1 and a[i] - 1 == a[i + 1]:
i += 1
i += 1
print(ans)
|
n, *a = list(map(int, open(0).read().split()))
# 状態1: iとi+1が1違う
# 状態2: iとi+1が同じ
# これ以外のiとi+1の関係があったら構築できない
# 状態1ではi+1を作る過程でiも作れる。
# 状態2ではi+1を作った後にiを作る必要がある。
# 後ろから見てa[i] - 1 == a[i - 1]となってる数を数えなければおk
# check
if a[0] != 0:
print((-1))
exit()
for i in range(n - 1):
if a[i + 1] - a[i] > 1:
print((-1))
exit()
# count
i = n - 1
ans = 0
while i > 0:
ans += a[i]
while i > 0 and a[i] - 1 == a[i - 1]:
i -= 1
i -= 1
print(ans)
|
p03347
|
N = int(eval(input()))
A = [int(eval(input())) for _ in range(N)]
if A[0]:
print((-1))
exit()
ans = 0
dp = A[-1]
for i in range(N - 1, 0, -1):
if A[i - 1] == A[i] - 1:
continue
elif A[i - 1] >= A[i]:
ans += dp
dp = A[i - 1]
else:
print((-1))
exit()
print((ans + dp))
|
N = int(eval(input()))
A = [int(eval(input())) for _ in range(N)]
if A[0]:
print((-1))
exit()
ans = 0
dp = A[-1]
for a, b in zip(A[-2::-1], A[-1::-1]):
if a == b - 1:
continue
elif a >= b:
ans += dp
dp = a
else:
print((-1))
exit()
print((ans + dp))
|
p03347
|
N=int(eval(input()))
A=[int(eval(input())) for _ in range(N)]
ans=0
if A[0]!=0:
print((-1))
exit()
for i in range(N-1,0,-1):
l,a=A[i-1],A[i]
if a>l+1:
print((-1))
exit()
elif a==l+1:
ans+=1
elif a!=0:
ans+=a
print(ans)
|
import sys
def main():
input = sys.stdin.readline
N=int(eval(input()))
A=[int(eval(input())) for _ in range(N)]
if A[0]!=0:
print((-1))
exit()
ans=0
d=0
for i in range(1,N):
if A[i]==0: continue
if A[i]>d+1:
print((-1))
exit()
d=A[i]
if A[i]==A[i-1]+1:
ans+=1
else:
ans+=A[i]
print(ans)
if __name__ == '__main__':
main()
|
p03347
|
import sys
import math
import collections
import bisect
import copy
import itertools
# import numpy as np
sys.setrecursionlimit(10 ** 7)
INF = 10 ** 16
MOD = 10 ** 9 + 7
# MOD = 998244353
ni = lambda: int(sys.stdin.readline())
ns = lambda: list(map(int, sys.stdin.readline().split()))
na = lambda: list(map(int, sys.stdin.readline().split()))
na1 = lambda: list([int(x) - 1 for x in sys.stdin.readline().split()])
# ===CODE===
def main():
n = ni()
a = [ni() for _ in range(n)]
ans = 0
if a[0] != 0:
print((-1))
exit(0)
prev = -1
for i, ai in enumerate(reversed(a)):
if ai > n - i - 1:
print((-1))
exit(0)
if i == 0:
ans += ai
else:
if ai != prev - 1:
if ai > prev - 1:
ans += ai
else:
print((-1))
exit(0)
prev = ai
print(ans)
if __name__ == '__main__':
main()
|
import sys
import math
import collections
import bisect
import copy
import itertools
# import numpy as np
sys.setrecursionlimit(10 ** 7)
INF = 10 ** 16
MOD = 10 ** 9 + 7
# MOD = 998244353
ni = lambda: int(sys.stdin.readline())
ns = lambda: list(map(int, sys.stdin.readline().split()))
na = lambda: list(map(int, sys.stdin.readline().split()))
na1 = lambda: list([int(x) - 1 for x in sys.stdin.readline().split()])
# ===CODE===
def main():
n = ni()
a = [ni() for _ in range(n)]
ans = 0
prev = -1
for i, ai in enumerate(reversed(a)):
if ai > n - i - 1:
print((-1))
exit(0)
if i == 0:
ans += ai
else:
if ai != prev - 1:
if ai > prev - 1:
ans += ai
else:
print((-1))
exit(0)
prev = ai
print(ans)
if __name__ == '__main__':
main()
|
p03347
|
n=int(eval(input()))
A=[int(eval(input())) for _ in range(n)]
if A[0]!=0:print((-1));exit()
cnt=0
for i in range(1,n):
if A[i-1]+1==A[i]:
cnt +=1
elif A[i-1]==A[i]:
cnt +=A[i]
elif A[i-1]>A[i]:
cnt +=A[i]
else:print((-1));exit()
print(cnt)
|
n=int(eval(input()))
A=[int(eval(input())) for _ in range(n)]
if A[0]!=0:print((-1));exit()
cnt=0
for i in range(1,n):
if A[i-1]+1==A[i]:
cnt +=1
elif A[i-1]==A[i] or A[i-1]>A[i]:
cnt +=A[i]
else:print((-1));exit()
print(cnt)
|
p03347
|
N, W, H = list(map(int, input().split()))
row, col = [0] * (H + 1), [0] * (W + 1)
for _ in range(N):
x, y, w = list(map(int, input().split()))
row[max(0, y - w)] += 1
row[min(H, y + w)] -= 1
col[max(0, x - w)] += 1
col[min(W, x + w)] -= 1
flag1 = flag2 = True
for i in range(H):
row[i + 1] += row[i]
flag1 &= row[i] > 0
if flag1:
print("Yes")
quit()
for i in range(W):
col[i + 1] += col[i]
flag2 &= col[i] > 0
if flag2:
print("Yes")
else:
print("No")
|
N, W, H = list(map(int, input().split()))
row, col = [0] * (H + 1), [0] * (W + 1)
for _ in range(N):
x, y, w = list(map(int, input().split()))
row[max(0, y - w)] += 1
row[min(H, y + w)] -= 1
col[max(0, x - w)] += 1
col[min(W, x + w)] -= 1
for i in range(H):
row[i + 1] += row[i]
if not row[i]:
break
else:
print("Yes")
quit()
for i in range(W):
col[i + 1] += col[i]
if not col[i]:
break
else:
print("Yes")
quit()
print("No")
|
p01712
|
N, W, H = [int(x) for x in input().split()]
map_x = [False] * W
count_x = 0
map_y = [False] * H
count_y = 0
wifi_x = []
wifi_y = []
for _ in range(N):
x, y, w = [int(x) for x in input().split()]
wifi_x.append((x - w, x + w))
wifi_y.append((y - w, y + w))
wifi_x.sort(key=lambda a: a[1], reverse=True)
wifi_y.sort(key=lambda a: a[1], reverse=True)
def check_wifi(wifi, l):
for x1, x2 in wifi:
if x1 <= l < x2:
return x2
return None
ans_x = True
b = 0
for x in range(W):
if x < b:
continue
b = check_wifi(wifi_x, x)
if not b:
ans_x = False
break
if not ans_x:
b = 0
for y in range(H):
if y < b:
continue
b = check_wifi(wifi_y, y)
if not b:
print('No')
exit()
print('Yes')
|
N, W, H = [int(x) for x in input().split()]
map_x = [0] * W
map_y = [0] * H
for _ in range(N):
x, y, w = [int(x) for x in input().split()]
map_x[max(0, x - w)] = max(map_x[max(0, x - w)], x + w - max(0, x - w))
map_y[max(0, y - w)] = max(map_y[max(0, y - w)], y + w - max(0, y - w))
def check_wifi(wifi):
m = 0
end = len(wifi)
for i, x in enumerate(wifi):
if x:
m = max(m, i + x)
if m >= end:
return True
if i < m:
continue
return False
return False
print(('Yes' if check_wifi(map_x) or check_wifi(map_y) else 'No'))
|
p01712
|
N, W, H = [int(x) for x in input().split()]
map_x = [0] * W
map_y = [0] * H
for _ in range(N):
x, y, w = [int(x) for x in input().split()]
map_x[max(0, x - w)] = max(map_x[max(0, x - w)], x + w - max(0, x - w))
map_y[max(0, y - w)] = max(map_y[max(0, y - w)], y + w - max(0, y - w))
def check_wifi(wifi):
m = 0
end = len(wifi)
for i, x in enumerate(wifi):
if x:
m = max(m, i + x)
if m >= end:
return True
if i < m:
continue
return False
return False
print(('Yes' if check_wifi(map_x) or check_wifi(map_y) else 'No'))
|
N, W, H = [int(x) for x in input().split()]
map_x = [0] * W
map_y = [0] * H
for _ in range(N):
x, y, w = [int(x) for x in input().split()]
map_x[max(0, x - w)] = max(map_x[max(0, x - w)], x + w - max(0, x - w))
map_y[max(0, y - w)] = max(map_y[max(0, y - w)], y + w - max(0, y - w))
def check_wifi(wifi):
m = 0
end = len(wifi)
for i, x in enumerate(wifi):
if x and i + x > m:
m = i + x
if m >= end:
return True
if i < m:
continue
return False
return False
print(('Yes' if check_wifi(map_x) or check_wifi(map_y) else 'No'))
|
p01712
|
N, W, H = [int(x) for x in input().split()]
map_x = [0] * W
map_y = [0] * H
for _ in range(N):
x, y, w = [int(x) for x in input().split()]
map_x[max(0, x - w)] = max(map_x[max(0, x - w)], x + w - max(0, x - w))
map_y[max(0, y - w)] = max(map_y[max(0, y - w)], y + w - max(0, y - w))
def check_wifi(wifi):
m = 0
end = len(wifi)
for i, x in enumerate(wifi):
if x and i + x > m:
m = i + x
if m >= end:
return True
if i < m:
continue
return False
return False
print(('Yes' if check_wifi(map_x) or check_wifi(map_y) else 'No'))
|
N, W, H = [int(x) for x in input().split()]
map_x = [0] * W
map_y = [0] * H
for _ in range(N):
x, y, w = [int(x) for x in input().split()]
mx = max(0, x - w)
map_x[mx] = max(map_x[mx], x + w - mx)
my = max(0, y - w)
map_y[my] = max(map_y[my], y + w - my)
def check_wifi(wifi):
m = 0
end = len(wifi)
for i, x in enumerate(wifi):
if x and i + x > m:
m = i + x
if m >= end:
return True
if i < m:
continue
return False
return False
print(('Yes' if check_wifi(map_x) or check_wifi(map_y) else 'No'))
|
p01712
|
a = [list(map(int, input().split())) for _ in range(3)]
n = int(eval(input()))
for _ in range(n):
b = int(eval(input()))
for i in range(9):
if b == a[i // 3][i % 3]:
a[i // 3][i % 3] = 0
flag = False
if a[0][0] == a[0][1] == a[0][2] == 0:
flag = True
if a[1][0] == a[1][1] == a[1][2] == 0:
flag = True
if a[2][0] == a[2][1] == a[2][2] == 0:
flag = True
if a[0][0] == a[1][0] == a[2][0] == 0:
flag = True
if a[0][1] == a[1][1] == a[2][1] == 0:
flag = True
if a[0][2] == a[1][2] == a[2][2] == 0:
flag = True
if a[0][0] == a[1][1] == a[2][2] == 0:
flag = True
if a[0][2] == a[1][1] == a[2][0] == 0:
flag = True
if flag:
print('Yes')
else:
print('No')
|
a = [list(map(int, input().split())) for _ in range(3)]
n = int(eval(input()))
for _ in range(n):
b = int(eval(input()))
for i in range(9):
if b == a[i // 3][i % 3]:
a[i // 3][i % 3] = 0
flag = True
if a[0][0] == a[0][1] == a[0][2] == 0:
flag = False
if a[1][0] == a[1][1] == a[1][2] == 0:
flag = False
if a[2][0] == a[2][1] == a[2][2] == 0:
flag = False
if a[0][0] == a[1][0] == a[2][0] == 0:
flag = False
if a[0][1] == a[1][1] == a[2][1] == 0:
flag = False
if a[0][2] == a[1][2] == a[2][2] == 0:
flag = False
if a[0][0] == a[1][1] == a[2][2] == 0:
flag = False
if a[0][2] == a[1][1] == a[2][0] == 0:
flag = False
print(('YNeos' [flag::2]))
|
p02760
|
A = [list(map(int,input().split())) for _ in range(3)]
N = int(eval(input()))
B = [int(eval(input())) for _ in range(N)]
for b in B:
for i in range(3):
for j in range(3):
if A[i][j] == b:
A[i][j] = -100
f = False
for i in range(3):
s = 0
for j in range(3):
s += A[i][j]
if s == -300:
f = True
for i in range(3):
s = 0
for j in range(3):
s += A[j][i]
if s == -300:
f = True
s = 0
for i in range(3):
s += A[i][i]
if s == -300:
f = True
s = 0
for i in range(3):
s += A[i][2-i]
if s == -300:
f = True
print(('Yes' if f else 'No'))
|
A = [list(map(int,input().split())) for _ in range(3)]
N = int(eval(input()))
B = [int(eval(input())) for _ in range(N)]
for b in B:
for i in range(3):
for j in range(3):
if A[i][j] == b:
A[i][j] = 0
f = False
for i in range(3):
s = 0
for j in range(3):
s += A[i][j]
if s == 0:
f = True
for i in range(3):
s = 0
for j in range(3):
s += A[j][i]
if s == 0:
f = True
s = 0
for i in range(3):
s += A[i][i]
if s == 0:
f = True
s = 0
for i in range(3):
s += A[i][2-i]
if s == 0:
f = True
print(('Yes' if f else 'No'))
|
p02760
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.