結果

問題 No.2281 K → K-1 01 Flip
ユーザー miscalcmiscalc
提出日時 2023-04-19 01:16:55
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
(最新)
AC  
(最初)
実行時間 -
コード長 714 bytes
コンパイル時間 2,309 ms
コンパイル使用メモリ 195,776 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-23 10:42:43
合計ジャッジ時間 6,592 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 WA -
testcase_15 WA -
testcase_16 RE -
testcase_17 RE -
testcase_18 WA -
testcase_19 RE -
testcase_20 RE -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 RE -
testcase_25 WA -
testcase_26 RE -
testcase_27 WA -
testcase_28 WA -
testcase_29 RE -
testcase_30 WA -
testcase_31 RE -
testcase_32 RE -
testcase_33 WA -
testcase_34 WA -
testcase_35 RE -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 RE -
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 WA -
testcase_44 WA -
testcase_45 WA -
testcase_46 WA -
testcase_47 WA -
testcase_48 WA -
testcase_49 WA -
testcase_50 WA -
testcase_51 WA -
testcase_52 WA -
testcase_53 WA -
testcase_54 WA -
testcase_55 WA -
testcase_56 WA -
権限があれば一括ダウンロードができます

ソースコード

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;
  while (true)
  {
    if (x < y)
      swap(x, y);
    if (x < K)
      break;

    ll z = x / K;
    x -= z * K;
    y += z * (K - 1);
  }
  cout << x + y << endl;
}
0