結果
問題 |
No.2281 K → K-1 01 Flip
|
ユーザー |
![]() |
提出日時 | 2023-04-20 23:43:38 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,044 bytes |
コンパイル時間 | 2,261 ms |
コンパイル使用メモリ | 200,024 KB |
最終ジャッジ日時 | 2025-02-12 10:42:44 |
ジャッジサーバーID (参考情報) |
judge2 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | WA * 50 TLE * 6 |
ソースコード
#include <bits/stdc++.h> using namespace std; #pragma GCC target("avx2") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") int main() { int N, Q; string S; cin >> N >> Q >> S; vector<int> cum0(N + 1, 0), cum1(N + 1, 0); for (int i = 0; i < N; i++) { cum0.at(i + 1) = cum0.at(i); cum1.at(i + 1) = cum1.at(i); if (S.at(i) == '0') cum0.at(i + 1)++; else cum1.at(i + 1)++; } while (Q--) { int L, R, K; cin >> L >> R >> K; L--, R--; bool ok = false; int len = 1; for (int i = L + 1; i <= R; i++) { if (S[i - 1] != S[i]) len = 1; else { len++; if (len >= K) { ok = true; break; } } } if (!ok) { cout << R - L + 1 << endl; return 0; } int x = cum0.at(R + 1) - cum0.at(L); int y = cum1.at(R + 1) - cum1.at(L); int z = (x - y) % (2 * K - 1); if (z < 0) z += 2 * K - 1; cout << max(z - 1, 2 * K - 2 - z) << endl; } }