結果
問題 |
No.151 セグメントフィッシング
|
ユーザー |
![]() |
提出日時 | 2025-03-20 20:46:53 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,524 bytes |
コンパイル時間 | 194 ms |
コンパイル使用メモリ | 82,704 KB |
実行使用メモリ | 85,096 KB |
最終ジャッジ日時 | 2025-03-20 20:47:13 |
合計ジャッジ時間 | 18,213 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 5 |
other | AC * 18 WA * 1 |
ソースコード
def main(): import sys input = sys.stdin.read().split() ptr = 0 N = int(input[ptr]) ptr += 1 Q = int(input[ptr]) ptr += 1 groups_right = [] groups_left = [] cycle = N - 1 for q in range(1, Q + 1): x = input[ptr] ptr += 1 if x == 'L' or x == 'R': y = int(input[ptr]) ptr += 1 z = int(input[ptr]) ptr += 1 if x == 'R': groups_right.append((q, y, z)) else: groups_left.append((q, y, z)) else: y = int(input[ptr]) ptr += 1 z = int(input[ptr]) ptr += 1 total = 0 current_t = q # Process right-facing groups for s, y_pos, cnt in groups_right: delta = current_t - s if delta < 0: continue max_steps = (N - 1) - y_pos if delta <= max_steps: pos = y_pos + delta else: delta -= max_steps delta -= 1 # Reverse direction to left if delta < 0: pos = N - 1 else: full_cycles = delta // cycle rem = delta % cycle if full_cycles % 2 == 0: pos = (N - 1) - rem else: pos = rem if y <= pos < z: total += cnt # Process left-facing groups for s, y_pos, cnt in groups_left: delta = current_t - s if delta < 0: continue max_steps = y_pos if delta <= max_steps: pos = y_pos - delta else: delta -= max_steps delta -= 1 # Reverse direction to right if delta < 0: pos = 0 else: full_cycles = delta // cycle rem = delta % cycle if full_cycles % 2 == 0: pos = rem else: pos = (N - 1) - rem if y <= pos < z: total += cnt print(total) if __name__ == "__main__": main()