結果

問題 No.2281 K → K-1 01 Flip
ユーザー miscalc
提出日時 2023-04-19 02:39:51
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
RE  
(最新)
AC  
(最初)
実行時間 -
コード長 658 bytes
コンパイル時間 1,885 ms
コンパイル使用メモリ 193,784 KB
最終ジャッジ日時 2025-02-12 10:06:25
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample RE * 1
other WA * 42 RE * 14
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main()
{
  ll N, K, L;
  string S;
  cin >> N >> K >> L >> S;
  
  // 1 回は操作できるか判定
  string T = S + S;
  bool ok = false;
  {
    int len = 1;
    for (int i = 1; i < min(L * N, 2 * N); i++)
    {
      if (T.at(i - 1) == T.at(i))
        len++;
      else
        len = 1;
      if (len >= K)
        ok = true;
    }
  }
  if (!ok)
  {
    cout << L * N << endl;
    return 0;
  }

  ll x = count(S.begin(), S.end(), '0'), y = N - x;
  x *= L, y *= L;
  ll z = (x - y) % (2 * K - 1);
  if (z < 0)
    z += 2 * K - 1;
  cout << max(z - 1, 2 * K - 2 - z) << endl;
}
0