結果

問題 No.1493 隣接xor
ユーザー 草苺奶昔草苺奶昔
提出日時 2023-03-14 09:14:09
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 189 ms / 2,000 ms
コード長 590 bytes
コンパイル時間 1,347 ms
コンパイル使用メモリ 81,588 KB
実行使用メモリ 153,564 KB
最終ジャッジ日時 2023-10-18 11:30:18
合計ジャッジ時間 9,402 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 64 ms
68,176 KB
testcase_01 AC 62 ms
68,176 KB
testcase_02 AC 62 ms
68,176 KB
testcase_03 AC 189 ms
153,352 KB
testcase_04 AC 177 ms
153,400 KB
testcase_05 AC 176 ms
153,560 KB
testcase_06 AC 179 ms
153,564 KB
testcase_07 AC 176 ms
153,564 KB
testcase_08 AC 178 ms
153,552 KB
testcase_09 AC 176 ms
153,564 KB
testcase_10 AC 175 ms
153,564 KB
testcase_11 AC 174 ms
153,564 KB
testcase_12 AC 176 ms
153,560 KB
testcase_13 AC 134 ms
122,276 KB
testcase_14 AC 126 ms
115,048 KB
testcase_15 AC 63 ms
68,172 KB
testcase_16 AC 64 ms
68,172 KB
testcase_17 AC 64 ms
68,172 KB
testcase_18 AC 62 ms
68,172 KB
testcase_19 AC 62 ms
68,172 KB
testcase_20 AC 126 ms
115,096 KB
testcase_21 AC 132 ms
121,280 KB
testcase_22 AC 116 ms
105,584 KB
testcase_23 AC 128 ms
115,740 KB
testcase_24 AC 175 ms
153,428 KB
testcase_25 AC 112 ms
102,640 KB
testcase_26 AC 134 ms
121,680 KB
testcase_27 AC 96 ms
89,536 KB
testcase_28 AC 163 ms
145,160 KB
testcase_29 AC 136 ms
121,696 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from itertools import accumulate
from typing import Any, Sequence


MOD = int(1e9 + 7)


def countSubseq(s: Sequence[Any]) -> int:
    """O(n)求不同子序列个数(非空)"""
    n = len(s)
    dp = [0] * (n + 1)
    dp[0] = 1
    last = dict()
    for i, char in enumerate(s):
        dp[i + 1] = 2 * dp[i] % MOD
        if char in last:
            dp[i + 1] -= dp[last[char]]
        last[char] = i
    return (dp[n] - 1) % MOD


n = int(input())
nums = list(map(int, input().split()))

nums = list(accumulate(nums, lambda x, y: x ^ y))
nums.pop()
print((countSubseq(nums) + 1) % MOD)
0