結果
| 問題 | No.3678 しゃべりすぎた男 |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-09-06 20:56:25 |
| 言語 | PyPy3 (7.3.23 + ACL) |
| 結果 |
RE
不安定
|
| 実行時間 | - |
| コード長 | 20,685 bytes |
| 記録 | |
| コンパイル時間 | 242 ms |
| コンパイル使用メモリ | 96,072 KB |
| 実行使用メモリ | 93,440 KB |
| 最終ジャッジ日時 | 2026-09-06 20:56:46 |
| 合計ジャッジ時間 | 8,721 ms |
|
ジャッジサーバーID (参考情報) |
judge3_0 / judge2_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | RE * 3 |
| other | RE * 33 |
ソースコード
# きつねdefault
# コンテスト前にこれを作りました。AIはコンテスト中に使っていません。
# メモ書き
# modする系の問題はmint使え!
# collections.Counterはdictと同じように使える、あと
# Counter.most_common()
# タプルで(要素, 出現回数)が出現回数順になっているリスト
# dictは
# keys キー
# values 数値
# items tuple(キー,数値)
# メモ化再帰のとき、@cacheに変える。
"""
# lazysegtree
# 求めるのは...
# # 区間最小値
def op(a,b):return min(a,b)
e=inf
# # 区間最大値
def op(a,b):return max(a,b)
e=-inf
# # 区間和
def op(a,b):return a+b
e=-inf
# # 区間 or
def op(a,b):return a|b
e=0
# # 区間 xor
def op(a,b):return a^b
e=0
# # 区間 and
def op(a,b):return a&b
e=inf-1
# 区間...
# # 区間加算
id_tannigen=0
def mapping(func,ele):
return func+ele
def composition(func1,func2):
return func1+func2
# # 区間変更
id_tannigen=0
def mapping(func,ele):
if func == id_tannigen:
return ele
else:
return func
def composition(func1,func2):
if func1 == id_tannigen:
return func2
else:
return func1
# # 区間 or
id_tannigen=0
def mapping(func,ele):
return func|ele
def composition(func1,func2):
return func1|func2
# # 区間 xor
id_tannigen=0
def mapping(func,ele):
return func^ele
def composition(func1,func2):
return func1^func2
# # 区間 and
id_tannigen=inf-1 # (2<<63)-1 = 1111111...(base2)
def mapping(func,ele):
return func&ele
def composition(func1,func2):
return func1&func2
# 初期化
seg = lst(op, e, mapping, composition, id_tannigen, a)
"""
# /**
#from collections import deque
from collections import defaultdict as dfd
from collections import Counter as cntr
from itertools import permutations as permutlist
import heapq
import bisect
from atcoder.lazysegtree import LazySegTree as lst
from atcoder.dsu import DSU as dsu
import math
from functools import cache
import sys
#input = sys.stdin.readline
sys.set_int_max_str_digits(0)
sys.setrecursionlimit(2147483646)
bs_lft=bisect.bisect_left
bs_rgt=bisect.bisect_right
map=lambda x,y:[x(i) for i in y]
enum=enumerate
lower=[chr(i)for i in range(97,97+26)]
upper=[chr(i)for i in range(65,65+26)]
pi=math.pi
inf=1<<63
#def系
def many(x):
"""
O(|x|)
一番個数が多いやつ
"""
d=dfd(int)
for i in x:
d[i]+=1
mosthl=0
for i in d:
kosuu=d[i]
mosthl=max(kosuu,mosthl)
ans=[]
for i in d:
if d[i]==mosthl:
ans.append(i)
return ans
def few(x):
"""
O(|x|)
一番個数が少ないやつ
"""
d=dfd(int)
for i in x:
d[i]+=1
mosthl=1<<63
for i in d:
kosuu=d[i]
mosthl=min(kosuu,mosthl)
ans=[]
for i in d:
if d[i]==mosthl:
ans.append(i)
return ans
def filter_tuple(x,y):
"""
O(n)
((a,b), (c,d))であるような要素で、2番目がyであるなら
1番目を答えに追加し、それをlistで出力する
"""
ans=[]
for i in x:
if type(y)==list or type(y)==tuple:
for y2 in y:
if i[1]==y2:
ans.append(i[0])
break
else:
if i[1]==y:
ans.append(i[0])
return ans
def notfilter_tuple(x,y):
"""
O(n)
((a,b), (c,d))であるような要素で、2番目がyでないなら
1番目を答えに追加し、それをlistで出力する
"""
ans=[]
for i in x:
if type(y)==list or type(y)==tuple:
for y2 in y:
if i[1]==y2:
break
else:
ans.append(i[0])
else:
if i[1]!=y:
ans.append(i[0])
return ans
def idx_0to1(x):
"""
O(|x|)
xの全要素を+1
"""
return [i+1 for i in x]
def idx_1to0(x):
"""
O(|x|)
xの全要素を-1
"""
return [i-1 for i in x]
def tostr(x):
"""
O(|x|)
xの全要素をstrに
"""
return map(str,x)
def toint(x):
"""
O(|x|)
xの全要素をintに
"""
return map(int,x)
def i_graph(n,m,weighted=False,zindex=False,directed=False):
g=[set() for i in range(n)]
for i in range(m):
if weighted:
u,v,w=map(int,input().split())
if not zindex:u-=1;v-=1
g[u].add((v,w))
if not directed:g[v].add((u,w))
else:
u,v=map(int,input().split())
if not zindex:u-=1;v-=1
g[u].add(v)
if not directed:g[v].add(u)
return g
def imos(x):
y=[]
c=0
for i in x:
c+=i
y.append(c)
return y
def rrotate(x):
"""
O(hw)
rot演算ではない。
"""
return [i[::-1] for i in list(zip(*x))]
def lrotate(x):
"""
O(hw)
rot演算ではない。
"""
return list(zip(*x))[::-1]
def rrrotate(x):
"""
O(hw)
rot演算ではない。
"""
return rrotate(rrotate(x))
def llrotate(x):
"""
O(hw)
rot演算ではない。
"""
return lrotate(lrotate(x))
def grid_include(x,y,w,h,zidx=True):
if zidx:
z=0
else:
z=1
if z<=x<w+z and z<=y<h+z:
return True
else:
return False
def grid_4move(x,y,w,h,zidx=True):
ans=[]
for xd,yd in ((-1, 0), (1, 0), (0, -1), (0, 1)):
if grid_include(xd+x,yd+y,w,h,zidx=zidx):
ans.append((xd+x,yd+y))
return ans
def grid_8move(x,y,w,h,zidx=True):
ans=[]
for xd,yd in ((-1, 0), (1, 0), (0, -1), (0, 1), (-1, -1), (-1, 1), (1, -1), (1, 1)):
if grid_include(xd+x,yd+y,w,h,zidx=zidx):
ans.append((xd+x,yd+y))
return ans
def grid_knightmove(x,y,w,h,zidx=True):
ans=[]
for xd,yd in ((-2, -1), (-2, 1), (-1, -2), (-1, 2), (1, -2), (1, 2), (2, -1), (2, 1)):
if grid_include(xd+x,yd+y,w,h,zidx=zidx):
ans.append((xd+x,yd+y))
return ans
def grid_rookmove(x,y,w,h,zidx=True):
ans=[]
moved=1
while True:
xd,yd=moved,0
if grid_include(xd+x,yd+y,w,h,zidx=zidx):
ans.append((xd+x,yd+y))
else:
break
moved+=1
moved=1
while True:
xd,yd=-moved,0
if grid_include(xd+x,yd+y,w,h,zidx=zidx):
ans.append((xd+x,yd+y))
else:
break
moved+=1
moved=1
while True:
xd,yd=0,moved
if grid_include(xd+x,yd+y,w,h,zidx=zidx):
ans.append((xd+x,yd+y))
else:
break
moved+=1
moved=1
while True:
xd,yd=0,-moved
if grid_include(xd+x,yd+y,w,h,zidx=zidx):
ans.append((xd+x,yd+y))
else:
break
moved+=1
return ans
def grid_bishopmove(x,y,w,h,zidx=True):
ans=[]
moved=1
while True:
xd,yd=moved,-moved
if grid_include(xd+x,yd+y,w,h,zidx=zidx):
ans.append((xd+x,yd+y))
else:
break
moved+=1
moved=1
while True:
xd,yd=-moved,-moved
if grid_include(xd+x,yd+y,w,h,zidx=zidx):
ans.append((xd+x,yd+y))
else:
break
moved+=1
moved=1
while True:
xd,yd=moved,moved
if grid_include(xd+x,yd+y,w,h,zidx=zidx):
ans.append((xd+x,yd+y))
else:
break
moved+=1
moved=1
while True:
xd,yd=-moved,moved
if grid_include(xd+x,yd+y,w,h,zidx=zidx):
ans.append((xd+x,yd+y))
else:
break
moved+=1
return ans
def prime(x):
"""
O(n log log n)
エラトステネスの篩。xまでの素数のリストを作成
"""
res=[]
mem=[0 for i in range(x+1)]
for i in range(2,x+1):
if mem[i]==1:continue
res.append(i)
for j in range(i,x+1,i):mem[j]=1
def join(x,sep=" "):
return sep.join(tostr(x))
def custom_bisect(l,r,cond):
"""
O(log (r-l))
if cond(mid):
upper
else:
lower
"""
while l<=r:
m=(l+r)//2
if cond(m):
l=m+1
else:
r=m-1
return r
def yn(cond,yes="Yes",no="No"):
if cond:
print(yes)
else:
print(no)
def kaibun(txt):
"""
O(|txt|)
464にて、回文が来そうだから追加。
"""
for a,b in zip(txt,txt[::-1]):
if a!=b:
return False
return True
def dijkstra(edges, n, start=0):
"""
O((n+m)log n)
"""
node = [float('inf')] * n
node[start] = 0
node_name = []
heapq.heappush(node_name, [0, start])
while len(node_name) > 0:
_, min_point = heapq.heappop(node_name)
for factor in edges[min_point]:
goal = factor[0]
cost = factor[1]
if node[min_point] + cost < node[goal]:
node[goal] = node[min_point] + cost
heapq.heappush(node_name, [node[min_point] + cost, goal])
return node
def floor(num):
return int(num)
def ceil(num):
return int(num+0.9999999999999999)
def sishagonyu(num):
if num%1>=0.5:
return ceil(num)
else:
return floor(num)
def yes():
print("Yes")
def no():
print("No")
def imos2d(l):
return map(imos,zip(*map(imos,l)))
def getimos2d(l,x1,y1,x2,y2):
a,b,c,d=0,0,0,0
x1-=1
y1-=1
a=l[y2][x2]
if x1!=-1:
b=l[y2][x1]
if y1!=-1:
c=l[y1][x2]
if x1!=-1 and y1!=-1:
d=l[y1][x1]
return a-b-c+d
def shakutori(left,right,addrmv,dame=lambda l,r,hanni:False,ansadd=lambda l,r,_,ans: ans+(r-l-1),index1=True):
r=left+1+index1
ans=0
hanni=0
for l in range(left+index1,right+index1):
r=max(r,l+1)
while True:
if r==right+index1:break
if dame(l,r,hanni):break
hanni+=addrmv(hanni,r)
r+=1
ans=ansadd(l,r,hanni,ans)
hanni-=addrmv(hanni,l)
return ans
def divceil(a,b):
return (a+b-1)//b
def invmod(a,b,mod=998244353):
return a*pow(b,-1,mod)%mod
def fugou(x):
if x>0:
return 1
elif x<0:
return -1
else:
return 0
def dist_manhattan(x1,y1,x2,y2):
return abs(x1-x2)+abs(y1-y2)
def dist_yuqurid(x1,y1,x2,y2):
return (x1-x2)**2+(y1-y2)**2
def dist_sqrtyuqurid(x1,y1,x2,y2):
return math.sqrt((x1-x2)**2+(y1-y2)**2)
#class系
class modint998244353:
def __init__(self, x: int):
self.val = x % 998244353
def __str__(self):
return str(self.val)
def __repr__(self):
return f"mint({self.val})"
def __add__(self, other):
other_val = other.val if isinstance(other, modint998244353) else other
return modint998244353(self.val + other_val)
def __sub__(self, other):
other_val = other.val if isinstance(other, modint998244353) else other
return modint998244353(self.val - other_val)
def __mul__(self, other):
other_val = other.val if isinstance(other, modint998244353) else other
return modint998244353(self.val * other_val)
def __truediv__(self, other):
other_val = other.val if isinstance(other, modint998244353) else other
inv = pow(other_val, 998244353 - 2, 998244353)
return modint998244353(self.val * inv)
__radd__ = __add__
__rmul__ = __mul__
def __rsub__(self, other):
return modint998244353(other - self.val)
def __rtruediv__(self, other):
inv = pow(self.val, 998244353 - 2, 998244353)
return modint998244353(other * inv)
def __pow__(self, power: int):
return modint998244353(pow(self.val, power, 998244353))
class modint1000000007:
def __init__(self, x: int):
self.val = x % 1000000007
def __str__(self):
return str(self.val)
def __repr__(self):
return f"mint({self.val})"
def __add__(self, other):
other_val = other.val if isinstance(other, modint1000000007) else other
return modint1000000007(self.val + other_val)
def __sub__(self, other):
other_val = other.val if isinstance(other, modint1000000007) else other
return modint1000000007(self.val - other_val)
def __mul__(self, other):
other_val = other.val if isinstance(other, modint1000000007) else other
return modint1000000007(self.val * other_val)
def __truediv__(self, other):
other_val = other.val if isinstance(other, modint1000000007) else other
inv = pow(other_val, 1000000007 - 2, 1000000007)
return modint1000000007(self.val * inv)
__radd__ = __add__
__rmul__ = __mul__
def __rsub__(self, other):
return modint1000000007(other - self.val)
def __rtruediv__(self, other):
inv = pow(self.val, 1000000007 - 2, 1000000007)
return modint1000000007(other * inv)
def __pow__(self, power: int):
return modint1000000007(pow(self.val, power, 1000000007))
class rollinghash:
def __init__(self, s):
self.s = s
self.n = len(s)
self.base1, self.mod1 = 10007, 1000000007
self.base2, self.mod2 = 20011, 1000000009
self.h1 = [0] * (self.n + 1)
self.h2 = [0] * (self.n + 1)
self.power1 = [1] * (self.n + 1)
self.power2 = [1] * (self.n + 1)
for i in range(self.n):
code = ord(self.s[i])
self.h1[i+1] = (self.h1[i] * self.base1 + code) % self.mod1
self.h2[i+1] = (self.h2[i] * self.base2 + code) % self.mod2
self.power1[i+1] = (self.power1[i] * self.base1) % self.mod1
self.power2[i+1] = (self.power2[i] * self.base2) % self.mod2
def get(self, l, r):
res1 = (self.h1[r] - self.h1[l] * self.power1[r - l]) % self.mod1
res2 = (self.h2[r] - self.h2[l] * self.power2[r - l]) % self.mod2
return (res1, res2)
def get_lcp(self, i, j):
low = 0
high = min(self.n - i, self.n - j) + 1
while high - low > 1:
mid = (low + high) // 2
if self.get(i, i + mid) == self.get(j, j + mid):
low = mid
else:
high = mid
return low
class basenum:
def __init__(self,base,num,order="0123456789"+join(lower,sep="")):
self.num=0
self.base=base
self.order=order
if type(num)==str:
j=1
for i in num[::-1].lower():
self.num+=j*order.index(i)
j*=self.base
elif type(num)==list or type(num)==tuple:
j=1
for i in num[::-1]:
self.num+=j*i
j*=self.base
elif type(num)==int:
self.num=num
def int(self):
return self.num
def __add__(self,other):
if self.base!=other.base:
raise TypeError("The base numbers are different")
return basenum(self.base,self.int()+other.int())
def __sub__(self,other):
if self.base!=other.base:
raise TypeError("The base numbers are different")
return basenum(self.base,self.int()-other.int())
def __rsub__(self,other):
if self.base!=other.base:
raise TypeError("The base numbers are different")
return basenum(self.base,other.int()-self.int())
def __mul__(self,other):
if self.base!=other.base:
raise TypeError("The base numbers are different")
return basenum(self.base,self.int()+other.int())
def __floordiv__(self,other):
if self.base!=other.base:
raise TypeError("The base numbers are different")
return basenum(self.base,self.int()//other.int())
__radd__=__add__
__rmul__=__mul__
def __str__(self):
txt=""
if self.base<=len(self.order):
num=self.num
while num!=0:
txt+=self.order[num%self.base]
num//=self.base
else:
raise TypeError("base is too big")
return txt[::-1]
def __repr__(self):
ans=[]
num=self.num
while num!=0:
ans.append(num%self.base)
num//=self.base
return "basenum("+str(self.base)+", ["+join(ans[::-1],sep=", ")+"], order='"+self.order+"')"
def tolist(self):
ans=[]
num=self.num
while num!=0:
ans.append(num%self.base)
num//=self.base
return ans
def baseto(self,base):
self.base=base
def __iand__(self,other):
if self.base!=2 or other.base!=2:
raise TypeError("and only support base 2")
return self.num&other.num
def __ior__(self,other):
if self.base!=2 or other.base!=2:
raise TypeError("or only support base 2")
return self.num|other.num
def __ixor__(self,other):
if self.base!=2 or other.base!=2:
raise TypeError("xor only support base 2")
return self.num^other.num
class yousocounter:
def __init__(self,cnt):
"""
O(|cnt|)
set()ぽいけどカウントが必要な時に、これ
"""
self.d=dfd(int)
self.cnt=set()
self.all_youso=0
for i in cnt:
self.d[i]+=1
self.cnt.add(i)
self.all_youso+=1
def add(self,a,b):
if self.d[a]==0:
self.cnt.add(a)
self.d[a]+=b
self.all_youso+=b
def remove(self,a,b):
self.d[a]-=b
if self.d[a]==0:
self.cnt.remove(a)
self.all_youso-=b
def length(self):
return len(self.cnt)
def youso(self):
return self.all_youso
class fastncr:
def __init__(self,maxn,mod=998244353):
#前計算
fact = [1 for i in range(maxn+1)]
invfact = [1 for i in range(maxn+1)]
for i in range(1, maxn + 1):
fact[i] = fact[i - 1] * i % mod
invfact[maxn] = pow(fact[maxn], mod - 2, mod)
for i in range(maxn, 0, -1):
invfact[i - 1] = invfact[i] * i % mod
self.fact=fact
self.invfact=invfact
self.mod=mod
def ncr(self,n,r):
if r < 0 or r > n:
return 0
return self.fact[n] * self.invfact[r] % self.mod * self.invfact[n - r] % self.mod
class aii:
def __getitem__(self,key):
return key
class deque:
def __init__(self, src_arr=[], max_size=1000000):
self.N = max(max_size, len(src_arr)) + 1
self.buf = list(src_arr) + [None] * (self.N - len(src_arr))
self.head = 0
self.tail = len(src_arr)
def __index(self, i):
l = len(self)
if not -l <= i < l: raise IndexError('index out of range: ' + str(i))
if i < 0:
i += l
return (self.head + i) % self.N
def __extend(self):
ex = self.N - 1
self.buf[self.tail+1 : self.tail+1] = [None] * ex
self.N = len(self.buf)
if self.head > 0:
self.head += ex
def is_full(self):
return len(self) >= self.N - 1
def is_empty(self):
return len(self) == 0
def append(self, x):
if self.is_full(): self.__extend()
self.buf[self.tail] = x
self.tail += 1
self.tail %= self.N
def appendleft(self, x):
if self.is_full(): self.__extend()
self.buf[(self.head - 1) % self.N] = x
self.head -= 1
self.head %= self.N
def pop(self):
if self.is_empty(): raise IndexError('pop() when buffer is empty')
ret = self.buf[(self.tail - 1) % self.N]
self.tail -= 1
self.tail %= self.N
return ret
def popleft(self):
if self.is_empty(): raise IndexError('popleft() when buffer is empty')
ret = self.buf[self.head]
self.head += 1
self.head %= self.N
return ret
def __len__(self):
return (self.tail - self.head) % self.N
def __getitem__(self, key):
return self.buf[self.__index(key)]
def __setitem__(self, key, value):
self.buf[self.__index(key)] = value
def __str__(self):
return 'deque({0})'.format(str(list(self)))
class point:
def __init__(self,x,y):
self.x=x
self.y=y
def rotate_90r(self,center=None):
if center==None:
center=point(0,0)
self.x-=center.x
self.y-=center.y
self.x,self.y=self.y,-self.x
self.x+=center.x
self.y+=center.y
return self.x,self.y
def rotate_90l(self,center=None):
if center==None:
center=point(0,0)
self.x-=center.x
self.y-=center.y
self.x,self.y=-self.y,self.x
self.x+=center.x
self.y+=center.y
return self.x,self.y
class line:
def __init__(self,p:point,q:point):
self.px=p.x
self.py=p.y
self.qx=q.x
self.qy=q.y
def __len__(self):
return math.sqrt((self.px-self.qx)**2+(self.py-self.qy)**2)
def intlen(self):
return math.isqrt((self.px-self.qx)**2+(self.py-self.qy)**2)
def axbyc0(self):
px,py,qx,qy=self.px,self.py,self.qx,self.qy
a=qy-py
b=-(qx-px)
c=(qx*py)-(px*qy)
return a,b,c
class circle:
def __init__(self,center:point,radius):
self.c=center
self.r=radius
def cross(a,b,change=False):
# line > circle > point
if type(a)==line:
if type(b)==line:
px,py,qx,qy,rx,ry,sx,sy=a.px,a.py,a.qx,a.qy,b.px,b.py,b.qx,b.qy
ax = px - qx
ay = py - qy
bx = rx - sx
by = ry - sy
if ax * by - ay * bx == 0:
pr_x = rx - px
pr_y = ry - py
if (ax * pr_y - ay * pr_x) == 0:
return True
else:
return False
else:
return True
if type(b)==circle:
aa,ab,ac=a.axbyc0()
bx=b.c.x
by=b.c.y
r=b.r
# abs(aa*bx+ab*by+c) / sqrt(aa**2+ab**2) = r
# 割り算の上下を二乗して
# (aa*bx+ab*by+c)**2 / (aa**2+ab**2) = r**2
# 両辺を(a**2+b**2)かけると
# (aa*bx+ab*by+c)**2 = r**2*(aa**2+ab**2)
p=(aa*bx+ab*by+ac)**2
q=r**2*(aa**2+ab**2)
return p<=q
if type(b)==point:
aa,ab,ac=a.axbyc0()
return aa*b.x+ab*b.y+ac==0
if type(a)==circle:
if type(b)==circle:
return (a.c.x-b.c.x)**2+(a.c.y-b.c.y)**2<=(a.r+b.r)**2
if type(b)==point:
dx=b.x-a.c.x
dy=b.y-a.c.y
dist=dx**2+dy**2
rad=a.r**2
return dist==rad
if type(a)==point:
if type(b)==point:
return a.x==b.x and a.y==b.y
if not change:
return cross(b,a,True)
raise ValueError(f"(a: {type(b).__name__} b: {type(a).__name__}) type is invalid")
# **/
t=map(int,input().split())
unsolveable=False
for e,i in enum(imos(t)):
if t[e]==-1:
unsolveable=True
if 6000-i<0 and not unsolveable:
print(-1)
else:
if unsolveable:
print(-1)
else:
print(6000-i)