結果
| 問題 |
No.200 カードファイト!
|
| コンテスト | |
| ユーザー |
qwewe
|
| 提出日時 | 2025-04-24 12:30:54 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,444 bytes |
| コンパイル時間 | 165 ms |
| コンパイル使用メモリ | 82,292 KB |
| 実行使用メモリ | 60,156 KB |
| 最終ジャッジ日時 | 2025-04-24 12:32:18 |
| 合計ジャッジ時間 | 2,237 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 4 WA * 22 |
ソースコード
import math
def main():
n = int(input())
a_size = int(input())
a = list(map(int, input().split()))
c_size = int(input())
c = list(map(int, input().split()))
# Sort A's cards in descending order
a_sorted = sorted(a, reverse=True)
if not a_sorted:
print(0)
return
max_a = a_sorted[0]
# Split C's cards into beatable and unbeatable, then sort each group descending
beatable = [d for d in c if d < max_a]
unbeatable = [d for d in c if d >= max_a]
c_sorted = sorted(beatable, reverse=True) + sorted(unbeatable, reverse=True)
len_a = len(a_sorted)
len_c = len(c_sorted)
if len_c == 0:
print(0)
return
# Calculate LCM of len_a and len_c
def lcm(x, y):
return x * y // math.gcd(x, y) if x and y else 0
lcm_ac = lcm(len_a, len_c)
# Calculate victories per cycle
per_cycle = 0
for i in range(lcm_ac):
a_idx = i % len_a
c_idx = i % len_c
if a_sorted[a_idx] > c_sorted[c_idx]:
per_cycle += 1
full_cycles = n // lcm_ac
remainder = n % lcm_ac
total = full_cycles * per_cycle
# Calculate victories in remainder
for i in range(remainder):
a_idx = i % len_a
c_idx = i % len_c
if a_sorted[a_idx] > c_sorted[c_idx]:
total += 1
print(total)
if __name__ == "__main__":
main()
qwewe