0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

ABC386Eを解いた【二項係数】

Posted at

筆者はレート800前後の茶~緑コーダ

ABC386当日にACできなかったE問題を解いていく

実装コード

二項係数が10^6以下というのはK>N-Kの場合もあるようでそのときは総XORから、該当しない項をサイドXORして取り除く必要があったみたい。

main.py
from bisect import bisect_left, bisect_right, insort_left, insort_right
from collections import defaultdict, Counter, deque
from functools import reduce, lru_cache
from itertools import product, accumulate, groupby, combinations
import sys
def rI(): return int(sys.stdin.readline().rstrip())
def rLI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def rI1(): return (int(sys.stdin.readline().rstrip())-1)
def rLI1(): return list(map(lambda a:int(a)-1,sys.stdin.readline().rstrip().split()))
def rS(): return sys.stdin.readline().rstrip()
def rLS(): return list(sys.stdin.readline().rstrip().split())
def err(*args): print(*args, file=sys.stderr)

def main():
    N, K = rLI()
    A = rLI()
    ret0 = 0
    if K>N-K:
        ret0 = reduce(lambda a,b:a^b,A)
        K=N-K
    print(max(reduce(lambda a,b:a^b, c,initial=ret0) for c in combinations(A,K)))
if __name__ == '__main__':
    main()

まとめ

XORの処理を軽量化するのがメインかと思もっていたが
二項係数の特殊な場合を考慮するのが本丸だった。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?