結果

問題 No.1444 !Andd
ユーザー 👑 tamatotamato
提出日時 2021-03-26 22:21:50
言語 PyPy3
(7.3.13)
結果
AC  
実行時間 1,172 ms / 2,000 ms
コード長 1,179 bytes
コンパイル時間 909 ms
コンパイル使用メモリ 87,196 KB
実行使用メモリ 401,856 KB
最終ジャッジ日時 2023-08-19 08:51:46
合計ジャッジ時間 15,418 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 81 ms
76,124 KB
testcase_01 AC 80 ms
76,120 KB
testcase_02 AC 81 ms
75,728 KB
testcase_03 AC 284 ms
150,960 KB
testcase_04 AC 238 ms
113,288 KB
testcase_05 AC 494 ms
223,072 KB
testcase_06 AC 298 ms
131,816 KB
testcase_07 AC 213 ms
113,560 KB
testcase_08 AC 431 ms
204,236 KB
testcase_09 AC 331 ms
153,600 KB
testcase_10 AC 294 ms
158,700 KB
testcase_11 AC 342 ms
181,460 KB
testcase_12 AC 499 ms
227,016 KB
testcase_13 AC 712 ms
302,204 KB
testcase_14 AC 684 ms
249,816 KB
testcase_15 AC 800 ms
292,864 KB
testcase_16 AC 1,172 ms
399,052 KB
testcase_17 AC 1,069 ms
401,152 KB
testcase_18 AC 1,167 ms
401,368 KB
testcase_19 AC 969 ms
401,584 KB
testcase_20 AC 963 ms
401,588 KB
testcase_21 AC 959 ms
401,656 KB
testcase_22 AC 960 ms
401,856 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][1] = 1
    for i, a in enumerate(A):
        if 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]
        else:
            dp[i+1][0] = 1
        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