結果

問題 No.78 クジ付きアイスバー
ユーザー Aimee PetrescuAimee Petrescu
提出日時 2022-11-27 21:26:58
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 877 bytes
コンパイル時間 1,695 ms
コンパイル使用メモリ 166,780 KB
実行使用メモリ 6,824 KB
最終ジャッジ日時 2024-10-04 12:22:56
合計ジャッジ時間 2,778 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 27 WA * 8
権限があれば一括ダウンロードができます

ソースコード

diff #

// unsolved
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll INF = 1LL << 60;

int main() {
  ll n, k;
  cin >> n >> k;
  string s;
  cin >> s;
  int cnt = 0, prev = 0;
  for (int i = 0; i < n; i++) {
    if (prev > 0)
      prev--;
    else
      cnt++;
    if (s[i] == '1')
      prev += 1;
    else if (s[i] == '2')
      prev += 2;
    if (i >= k) {
      cout << cnt << endl;
      return 0;
    }
  }
  if (prev >= cnt) {
    cout << cnt << endl;
    return 0;
  }
  ll ans = ((k - cnt) / n) * (cnt - prev) + cnt;
  cnt = (k / n) * n;
  if (cnt >= k) {
    cout << ans << endl;
    return 0;
  }
  for (int i = 0; i < n; i++) {
    cnt++;
    if (prev > 0)
      prev--;
    else
      ans++;
    if (s[i] == '1')
      prev += 1;
    else if (s[i] == '2')
      prev += 2;
    if (cnt >= k) {
      cout << ans << endl;
      return 0;
    }
  }
}
0