結果

問題 No.1443 Andd
ユーザー 👑 tamatotamato
提出日時 2021-03-26 22:17:55
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,168 ms / 2,000 ms
コード長 1,068 bytes
コンパイル時間 681 ms
コンパイル使用メモリ 87,176 KB
実行使用メモリ 401,992 KB
最終ジャッジ日時 2023-08-19 08:44:42
合計ジャッジ時間 10,880 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 78 ms
76,200 KB
testcase_01 AC 77 ms
75,996 KB
testcase_02 AC 79 ms
75,920 KB
testcase_03 AC 119 ms
86,388 KB
testcase_04 AC 135 ms
91,660 KB
testcase_05 AC 122 ms
86,896 KB
testcase_06 AC 117 ms
85,628 KB
testcase_07 AC 134 ms
90,960 KB
testcase_08 AC 136 ms
89,712 KB
testcase_09 AC 113 ms
76,000 KB
testcase_10 AC 142 ms
92,908 KB
testcase_11 AC 134 ms
92,104 KB
testcase_12 AC 135 ms
91,800 KB
testcase_13 AC 331 ms
158,684 KB
testcase_14 AC 327 ms
158,504 KB
testcase_15 AC 330 ms
158,620 KB
testcase_16 AC 328 ms
158,652 KB
testcase_17 AC 328 ms
158,568 KB
testcase_18 AC 1,104 ms
401,552 KB
testcase_19 AC 1,168 ms
401,564 KB
testcase_20 AC 1,167 ms
401,992 KB
testcase_21 AC 1,042 ms
401,704 KB
testcase_22 AC 1,099 ms
401,896 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

mod = 1000000007
eps = 10**-9
mask = 1023


def main():
    import sys
    input = sys.stdin.readline

    N = int(input())
    A = list(map(int, input().split()))

    dp = [[0] * (1 << 10) for _ in range(N+1)]
    dp_over = [[0] * (1 << 10) for _ in range(N+1)]
    dp[0][0] = 1
    for i, a in enumerate(A):
        for state in range(1 << 10):
            # and
            state_new_and = state & a
            if dp[i][state] or dp_over[i][state]:
                dp[i+1][state_new_and] = 1
            # add
            state_new_add = state + a
            state_new_add_masked = state_new_add & mask
            if dp[i][state]:
                if state_new_add != state_new_add_masked:
                    dp_over[i+1][state_new_add_masked] += 1
                else:
                    dp[i+1][state_new_add_masked] = 1
            dp_over[i+1][state_new_add_masked] += dp_over[i][state]
        ans = 0
        for state in range(1 << 10):
            ans += dp[i+1][state] + dp_over[i+1][state]
        print(ans)


if __name__ == '__main__':
    main()
0