結果
問題 | No.1426 Got a Covered OR |
ユーザー | LyricalMaestro |
提出日時 | 2024-02-04 04:11:29 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 197 ms / 2,000 ms |
コード長 | 2,944 bytes |
コンパイル時間 | 167 ms |
コンパイル使用メモリ | 82,048 KB |
実行使用メモリ | 94,592 KB |
最終ジャッジ日時 | 2024-09-28 11:09:10 |
合計ジャッジ時間 | 4,173 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 43 ms
52,224 KB |
testcase_01 | AC | 42 ms
51,840 KB |
testcase_02 | AC | 39 ms
52,352 KB |
testcase_03 | AC | 39 ms
52,352 KB |
testcase_04 | AC | 38 ms
51,968 KB |
testcase_05 | AC | 40 ms
52,352 KB |
testcase_06 | AC | 39 ms
52,096 KB |
testcase_07 | AC | 39 ms
52,096 KB |
testcase_08 | AC | 40 ms
52,224 KB |
testcase_09 | AC | 43 ms
52,352 KB |
testcase_10 | AC | 41 ms
52,352 KB |
testcase_11 | AC | 41 ms
52,480 KB |
testcase_12 | AC | 99 ms
76,544 KB |
testcase_13 | AC | 105 ms
79,488 KB |
testcase_14 | AC | 93 ms
75,264 KB |
testcase_15 | AC | 98 ms
75,264 KB |
testcase_16 | AC | 65 ms
65,152 KB |
testcase_17 | AC | 97 ms
76,800 KB |
testcase_18 | AC | 146 ms
87,808 KB |
testcase_19 | AC | 148 ms
87,936 KB |
testcase_20 | AC | 112 ms
79,488 KB |
testcase_21 | AC | 121 ms
82,432 KB |
testcase_22 | AC | 141 ms
87,424 KB |
testcase_23 | AC | 183 ms
94,592 KB |
testcase_24 | AC | 197 ms
93,184 KB |
testcase_25 | AC | 172 ms
93,440 KB |
testcase_26 | AC | 179 ms
93,312 KB |
ソースコード
## https://yukicoder.me/problems/no/1426 MOD = 10 ** 9 + 7 class CombinationCalculator: """ modを考慮したPermutation, Combinationを計算するためのクラス """ def __init__(self, size, mod): self.mod = mod self.factorial = [0] * (size + 1) self.factorial[0] = 1 for i in range(1, size + 1): self.factorial[i] = (i * self.factorial[i - 1]) % self.mod self.inv_factorial = [0] * (size + 1) self.inv_factorial[size] = pow(self.factorial[size], self.mod - 2, self.mod) for i in reversed(range(size)): self.inv_factorial[i] = ((i + 1) * self.inv_factorial[i + 1]) % self.mod def calc_combination(self, n, r): if n < 0 or n < r: return 0 if r == 0 or n == r: return 1 ans = self.inv_factorial[n - r] * self.inv_factorial[r] ans %= self.mod ans *= self.factorial[n] ans %= self.mod return ans def calc_permutation(self, n, r): if n < 0 or n < r: return 0 ans = self.inv_factorial[n - r] ans *= self.factorial[n] ans %= self.mod return ans def main(): N = int(input()) B = list(map(int, input().split())) # あらかじめ必要な項は計算しておく combi = CombinationCalculator(N, MOD) f_array = [0] * (N + 1) f = 1 f_array[0] = 1 for i in range(1, N + 1): f *= 2 f %= MOD f_array[i] = f g_array = [0] * (N + 1) for i in range(1, N + 1): g_array[i] = (f_array[i] - 1) % MOD # 本計算 array = [0] * 30 prev = -1 answer = 1 for i in range(N): if B[i] != -1: new_array = [0] * 30 for j in range(30): if B[i] & (1 << j): new_array[j] += 1 ans = 1 # 長さ i0 = i - prev f_num = 0 g_num = 0 for j in range(30): if new_array[j] > 0 and array[j] == 0: g_num += 1 elif new_array[j] == 0 and array[j] > 0: ans = 0 elif new_array[j] > 0 and array[j] > 0: f_num += 1 a = 0 for j in range(i0 + 1): s = pow(-1, j, MOD) s *= combi.calc_combination(i0, j) s %= MOD s *= pow(f_array[i0 - j], f_num, MOD) s %= MOD s *= pow(g_array[i0 - j], g_num, MOD) s %= MOD a += s a %= MOD ans *= a ans %= MOD answer *= ans answer %= MOD for j in range(30): array[j] |= new_array[j] prev = i print(answer) if __name__ == "__main__": main()