C - Attack Survival
遍历
D - Powerful Discount Tickets
堆贪心,每次操作都在最大的那一个,然后重新插入
# -*- coding: utf-8 -*-
# @time : 2023/6/2 13:30
# @author : yhdu@tongwoo.cn
# @desc :
# @file : atcoder.py
# @software : PyCharm
import bisect
import copy
import sys
from sortedcontainers import SortedList
from collections import defaultdict, Counter, deque
from functools import lru_cache, cmp_to_key
import heapq
import math
sys.setrecursionlimit(50005)
def main():
items = sys.version.split()
if items[0] == '3.10.6':
fp = open("in.txt")
else:
fp = sys.stdin
n, m = map(int, fp.readline().split())
a = list(map(int, fp.readline().split()))
qu = [-x for x in a]
heapq.heapify(qu)
while qu and m:
x = -heapq.heappop(qu)
heapq.heappush(qu, -(x >> 1))
m -= 1
ans = 0
for x in qu:
ans -= x
print(ans)
if __name__ == "__main__":
main()
E - Who Says a Pun?
字符串hash
C++提交了几次都没有过,反而是pypy一次通过
# -*- coding: utf-8 -*-
# @time : 2023/6/2 13:30
# @author : yhdu@tongwoo.cn
# @desc :
# @file : atcoder.py
# @software : PyCharm
import bisect
import copy
import sys
from sortedcontainers import SortedList
from collections import defaultdict, Counter, deque
from functools import lru_cache, cmp_to_key
import heapq
import math
sys.setrecursionlimit(5005)
def check(s, t, n):
for i in range(n):
if s[i] != t[i]:
return False
return True
def main():
items = sys.version.split()
if items[0] == '3.10.6':
fp = open("in.txt")
else:
fp = sys.stdin
def dig(c):
return ord(c) - ord('a') + 1
n = int(fp.readline())
s = fp.readline().strip()
mod = 10 ** 9 + 7
p = 131
hp = 1
ans = 0
for l in range(1, n // 2 + 1):
temp = 0
pos_dict = dict()
for i in range(l):
temp = (temp * p + dig(s[i])) % mod
pos_dict[temp] = l - 1
for i in range(l, n):
temp = (temp - hp * dig(s[i - l])) % mod
temp = (temp * p + dig(s[i])) % mod
if temp in pos_dict:
last = pos_dict[temp]
if last < i - l + 1 and check(s[last - l + 1: last + 1], s[i - l + 1: i + 1], l):
ans = max(ans, l)
break
else:
pos_dict[temp] = i
hp = hp * p % mod
print(ans)
if __name__ == "__main__":
main()
F - Xor Sum 3
线性基
不能在线性基中贪心地选取最大异或和
# -*- coding: utf-8 -*-
# @time : 2023/6/2 13:30
# @author : yhdu@tongwoo.cn
# @desc :
# @file : atcoder.py
# @software : PyCharm
import bisect
import copy
import sys
from sortedcontainers import SortedList
from collections import defaultdict, Counter, deque
from functools import lru_cache, cmp_to_key
import heapq
import math
sys.setrecursionlimit(5005)
def main():
items = sys.version.split()
if items[0] == '3.10.6':
fp = open("in.txt")
else:
fp = sys.stdin
p = [0] * 64
n = int(fp.readline())
a = list(map(int, fp.readline().split()))
def insert(x):
for i in range(63, -1, -1):
if (x >> i) & 1:
if p[i] == 0:
p[i] = x
return 1
else:
x ^= p[i]
return 0
s = 0
for t in a:
s ^= t
for i in range(64):
if (s >> i) & 1:
for j in range(n):
if (a[j] >> i) & 1:
a[j] ^= 1 << i
for t in a:
insert(t)
ans1 = 0
for i in range(63, -1, -1):
if ans1 ^ p[i] > ans1:
ans1 = ans1 ^ p[i]
ans2 = s ^ ans1
print(ans1 + ans2)
if __name__ == "__main__":
main()