結果
| 問題 | No.2281 K → K-1 01 Flip | 
| コンテスト | |
| ユーザー |  miscalc | 
| 提出日時 | 2023-04-20 23:40:41 | 
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                WA
                                 
                             | 
| 実行時間 | - | 
| コード長 | 948 bytes | 
| コンパイル時間 | 1,921 ms | 
| コンパイル使用メモリ | 195,824 KB | 
| 最終ジャッジ日時 | 2025-02-12 10:39:00 | 
| ジャッジサーバーID (参考情報) | judge5 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 1 | 
| other | WA * 50 TLE * 6 | 
ソースコード
#include <bits/stdc++.h>
using namespace std;
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; 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;
  }
}
            
            
            
        