結果
問題 |
No.1004 サイコロの実装 (2)
|
ユーザー |
![]() |
提出日時 | 2025-06-12 18:57:26 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,453 bytes |
コンパイル時間 | 321 ms |
コンパイル使用メモリ | 82,284 KB |
実行使用メモリ | 54,436 KB |
最終ジャッジ日時 | 2025-06-12 18:57:30 |
合計ジャッジ時間 | 3,104 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 6 WA * 32 |
ソースコード
def main(): import sys a, b, x0, N = map(int, sys.stdin.readline().split()) if N == 0: print(0, 0) return # Step 1: Compute the mod6 sequence and its cycle a_mod6 = a % 6 b_mod6 = b % 6 current = x0 % 6 seen = {} sequence_mod6 = [] index = 0 while current not in seen: seen[current] = index sequence_mod6.append(current) current = (a_mod6 * current + b_mod6) % 6 index += 1 cycle_start = seen[current] cycle_length = index - cycle_start # Since the entire sequence is periodic after cycle_start (which is 0 for LCG) # So we can consider the cycle part only T = cycle_length parity_list = [ ( (x % 2) ^ 1 ) for x in sequence_mod6 ] # Step 2: Generate takahashi and aoki's parity lists # Determine their cycle lengths if T % 2 == 0: T_h = T // 2 T_a = T // 2 else: T_h = T T_a = T # Generate the parity lists for each player's cycle takahashi_parity = [] for i in range(T_h): idx = (i * 2) % T takahashi_parity.append(parity_list[idx]) aoki_parity = [] for i in range(T_a): idx = (i * 2 + 1) % T aoki_parity.append(parity_list[idx]) # Step 3: Compute cumulative sum mod2 and count of 1s for each cycle def compute_ones(parity, cycle_len): cum = 0 res = [] count = 0 for p in parity[:cycle_len]: cum = (cum + p) % 2 res.append(cum) if cum == 1: count += 1 return res, count # For Takahashi takahashi_cum, takahashi_cycle_ones = compute_ones(takahashi_parity, T_h) # For Aoki aoki_cum, aoki_cycle_ones = compute_ones(aoki_parity, T_a) # Step 4: Compute the total number of 1s (black stones) for each player # Takahashi's turn q_t, r_t = divmod(N, T_h) total_t_black = q_t * takahashi_cycle_ones for i in range(r_t): if takahashi_cum[i] == 1: total_t_black += 1 # Aoki's turn q_a, r_a = divmod(N, T_a) total_a_black = q_a * aoki_cycle_ones for i in range(r_a): if aoki_cum[i] == 1: total_a_black += 1 # Calculate scores t_white = N - total_t_black a_white = N - total_a_black score_t = min(total_t_black, t_white) score_a = min(total_a_black, a_white) print(score_t, score_a) if __name__ == "__main__": main()