好像上周练习赛忘记写题解了....最近vp的有点多懒得写题解了,见谅0.0
A.究极博弈输出自己即可
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
B.因为能复制就是变成两倍,跟二进制有关的
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
C.首先a%b=m 直接让a=m就行,b=n-m就行,然后看题目条件判断a b就行
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
D.对于0和1直接相加即可,等大于2的时候后面除了1 0全部相乘肯定是最优的
但是题目ai=1e9 1e9的2e5次方巨大,所以等大于2的时候可以进行mod运算,
import random
import sys
import os
import math
from collections import Counter, defaultdict, deque
from functools import lru_cache, reduce
from itertools import accumulate, combinations, permutations
from heapq import nsmallest, nlargest, heapify, heappop, heappush
from io import BytesIO, IOBase
from copy import deepcopy
import threading
import bisect
BUFSIZE = 4096
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
def I():
return input()
def II():
return int(input())
def MI():
return map(int, input().split())
def LI():
return list(input().split())
def LII():
return list(map(int, input().split()))
def GMI():
return map(lambda x: int(x) - 1, input().split())
def LGMI():
return list(map(lambda x: int(x) - 1, input().split()))
def solve():
x=0
mod=998244353
n=II()
a=LII()
f=0
for i in a:
if i==0:continue
if i==1:
x+=1
continue
if x>=2:
f=1
if f==1:
x*=i
x=x%mod
else:
x+=i
print(x%mod)
if __name__ == '__main__':
for _ in range(II()):
solve()
E.
首先括号序列过程要保证大于等于0的,即(括号大于等于)括号
我们先入队(括号
如果当前出现了)括号,且等于过程中的计数是小于0的,那么就是不合法,从后面位置里面找一个(括号调换即可,为啥不从前面找,因为前面都已经合法了别动他了,动了代价更大
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
F.首先get函数里面就是把矩阵变成m列,m列里面哪一行变成x需要的代价最小
复杂度是nlogn别想成平方了
然后看题目范围最多2e5 所以分成1000列,肯定有多的一列只有一个数,只要把当前列变成k就行
所以直接枚举1000即可
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
G:
首先除法根据费马小定理除x=qmi(x,mod-2,mod)
逆元那部分知识
然后就枚举当前有多少个数,然后其实就没了...记忆化搜索
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include