結果

問題 No.78 クジ付きアイスバー
ユーザー le_panda_noirle_panda_noir
提出日時 2020-07-25 11:18:26
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,580 bytes
コンパイル時間 921 ms
コンパイル使用メモリ 92,772 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-09 07:41:21
合計ジャッジ時間 2,487 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,384 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 1 ms
4,380 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 1 ms
4,380 KB
testcase_24 AC 2 ms
4,380 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 1 ms
4,376 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 AC 1 ms
4,376 KB
testcase_31 WA -
testcase_32 AC 1 ms
4,376 KB
testcase_33 WA -
testcase_34 WA -
testcase_35 AC 1 ms
4,380 KB
testcase_36 WA -
testcase_37 AC 1 ms
4,376 KB
testcase_38 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <queue>
#include <set>

using namespace std;
using ll = long long;
using vi = vector<int>;

#define rep(i,n) for(int i=0,_i=(n);i<_i;++i)

int main() {
  int N, K; cin >> N >> K;
  string S; cin >> S;

  vi G(N, 0);
  rep(i, N) {
    if (S[i] == '0') {
      G[i] = (i+1) % N;
      continue;
    }
    int atari = S[i] - '0';
    int j = 0;
    while (atari > 0) {
      --atari;
      ++j;
      atari += S[(i+j)%N] - '0';
      if (j > N)
        break;
    }
    if (j > N)
      G[i] = N;
    else
      G[i] = (i+j+1) % N;
  }
  if (G[0] == N) {
    cout << 1 << endl;
    return 0;
  }
  set<int> st;
  queue<int> q;
  q.push(0);
  vector<pair<int, int>> v;
  int ans = 0;
  while (true) {
    int p = q.front(); q.pop();
    if (p == N) {
      cout << ans << endl;
      return 0;
    }
    q.push(G[p]);
    ++ans;
    int distance = (G[p] > p ? G[p] - p : N + (G[p] - p));
    K -= distance;
    if (K <= 0) {
      cout << ans << endl;
      return 0;
    }
    if (st.find(p) == st.end()) {
      v.emplace_back(p, distance);
      st.insert(p);
      continue;
    }
    vi circle;
    ll sum = 0;
    rep(i, v.size()) {
      if (v[i].first == p) {
        while(i < (int)v.size()) {
          circle.push_back(v[i].second);
          sum += v[i].second;
          ++i;
        }
        break;
      }
    }
    ans += (K / sum) * circle.size();
    K %= sum;
    rep(i, circle.size()) {
      if (K <= 0)
        break;
      K -= circle[i];
      ++ans;
    }
    cout << ans << endl;
    break;
  }

  return 0;
}
0