結果
問題 |
No.2281 K → K-1 01 Flip
|
ユーザー |
![]() |
提出日時 | 2025-04-16 00:34:51 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,063 bytes |
コンパイル時間 | 276 ms |
コンパイル使用メモリ | 81,536 KB |
実行使用メモリ | 139,520 KB |
最終ジャッジ日時 | 2025-04-16 00:36:20 |
合計ジャッジ時間 | 13,583 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | WA * 56 |
ソースコード
import sys def main(): input = sys.stdin.read().split() ptr = 0 N, Q = int(input[ptr]), int(input[ptr+1]) ptr += 2 S = input[ptr] ptr += 1 # Precompute transitions trans = [0] * (N-1) for i in range(N-1): if S[i] != S[i+1]: trans[i] = 1 # Prefix sum array for transitions prefix = [0] * (N) for i in range(1, N): prefix[i] = prefix[i-1] + (trans[i-1] if i-1 < len(trans) else 0) for _ in range(Q): L = int(input[ptr]) R = int(input[ptr+1]) K = int(input[ptr+2]) ptr += 3 # Convert to 0-based indices L0 = L - 1 R0 = R - 1 if L0 >= R0: print(1) continue # Number of transitions between L0 and R0-1 (inclusive) if L0 == 0: cnt = prefix[R0] else: cnt = prefix[R0] - prefix[L0] runs = cnt + 1 answer = (R0 - L0 + 1) - runs print(answer) if __name__ == "__main__": main()