题解 | 01序列
01序列
https://www.nowcoder.com/practice/b0c948dbe577485598b982a430d65c39
import sys
import math
import heapq
import bisect
import re
import inspect
import copy
from collections import Counter, deque, defaultdict
from itertools import combinations, permutations, accumulate
MOD = 998244353
input = lambda: sys.stdin.readline().rstrip("\r\n")
def print(*args, sep=" ", end="\n"):
sys.stdout.write(sep.join(map(str, args)) + end)
def LI():
return list(map(int, input().split()))
def LS():
return list(map(str, input().split()))
def NTI():
return list(map(int, re.findall(r"-?\d+", input())))
def NTS():
return re.findall(r"[a-zA-Z]+", input())
def I():
return int(input())
def S():
return input()
_DEBUG = True
def dbg(*args):
if not _DEBUG:
return
try:
frame = inspect.currentframe().f_back
line = inspect.getframeinfo(frame).code_context[0].strip()
names = line[line.find("(") + 1 : line.rfind(")")].split(",")
res = [f"{n.strip()}={repr(v)}" for n, v in zip(names, args)]
sys.stderr.write(f"[{frame.f_lineno}] {' | '.join(res)}\n")
except:
pass
DIR4 = [(0, 1), (0, -1), (1, 0), (-1, 0)]
DIR8 = [(0, 1), (0, -1), (1, 0), (-1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)]
ES=1e-9
def solve():
m=I()+2
li=LI()
n=I()
li=[0]+li+[0]
d=[[] for i in range(m+10)]
p=0
for i in range(1,m-1):
val=li[i]
if val==0 and (li[i+1] != 1 and li[i-1]!=1):
d[p].append(val)
else:
p+=1
al=0
for j in d:
al+=math.ceil(len(j)/2-ES)
if n>al:
print('false')
else:
print('true')
if __name__ == "__main__":
sys.setrecursionlimit(200000)
solve()
用了很笨的方法存储
查看6道真题和解析