結果

問題 No.1493 隣接xor
ユーザー 草苺奶昔草苺奶昔
提出日時 2024-02-16 01:22:43
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 172 ms / 2,000 ms
コード長 809 bytes
コンパイル時間 419 ms
コンパイル使用メモリ 81,572 KB
実行使用メモリ 141,572 KB
最終ジャッジ日時 2024-02-16 01:22:51
合計ジャッジ時間 7,898 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 57 ms
68,232 KB
testcase_01 AC 57 ms
68,232 KB
testcase_02 AC 58 ms
68,232 KB
testcase_03 AC 167 ms
141,560 KB
testcase_04 AC 153 ms
141,556 KB
testcase_05 AC 154 ms
141,564 KB
testcase_06 AC 154 ms
141,556 KB
testcase_07 AC 153 ms
141,556 KB
testcase_08 AC 164 ms
141,564 KB
testcase_09 AC 154 ms
141,560 KB
testcase_10 AC 153 ms
141,572 KB
testcase_11 AC 152 ms
141,560 KB
testcase_12 AC 151 ms
141,568 KB
testcase_13 AC 115 ms
110,304 KB
testcase_14 AC 110 ms
103,244 KB
testcase_15 AC 57 ms
68,232 KB
testcase_16 AC 56 ms
68,232 KB
testcase_17 AC 56 ms
68,232 KB
testcase_18 AC 57 ms
68,232 KB
testcase_19 AC 57 ms
68,232 KB
testcase_20 AC 112 ms
109,536 KB
testcase_21 AC 118 ms
114,140 KB
testcase_22 AC 106 ms
100,980 KB
testcase_23 AC 118 ms
109,612 KB
testcase_24 AC 153 ms
141,484 KB
testcase_25 AC 100 ms
98,636 KB
testcase_26 AC 121 ms
114,540 KB
testcase_27 AC 88 ms
86,908 KB
testcase_28 AC 172 ms
134,564 KB
testcase_29 AC 121 ms
114,564 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from typing import Any, Sequence


def countSubSequence(seq: Sequence[Any], mod=int(1e9 + 7)) -> int:
    n = len(seq)
    dp = [0] * (n + 1)
    dp[0] = 1
    last = dict()
    for i, c in enumerate(seq):
        dp[i + 1] = 2 * dp[i] % mod
        if c in last:
            dp[i + 1] -= dp[last[c]]
        last[c] = i
    return (dp[n] - 1) % mod


if __name__ == "__main__":
    # https://yukicoder.me/problems/no/1493
    # 给定一个长度为n的数组,每次可以将相邻的两个数换成xor
    # 问可以得到的数组的个数模1e9+7
    MOD = int(1e9 + 7)
    n = int(input())
    nums = list(map(int, input().split()))
    for i in range(n - 1):
        nums[i + 1] ^= nums[i]
    nums = nums[:-1]
    res = countSubSequence(nums, MOD)
    res = (res + 1) % MOD  # 空集
    print(res)
0