結果

問題 No.78 クジ付きアイスバー
ユーザー rsk0315rsk0315
提出日時 2019-02-09 01:09:22
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,339 bytes
コンパイル時間 643 ms
コンパイル使用メモリ 80,320 KB
実行使用メモリ 5,316 KB
最終ジャッジ日時 2023-09-14 04:02:24
合計ジャッジ時間 2,508 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <cstdio>
#include <cstdint>
#include <vector>
#include <set>
#include <map>
#include <string>

int main() {
  size_t N;
  intmax_t K;
  char buf[64];
  scanf("%zu %jd %s", &N, &K, buf);
  std::string S = buf;
  std::vector<intmax_t> atari(N);
  for (size_t i = 0; i < N; ++i)
    atari[i] = S[i]-'0';

  if (S == std::string(N, '0'))
    return !printf("%jd\n", K);

  std::vector<intmax_t> tada(N);
  for (size_t i = 0; i < N; ++i) {
    int cur = 1;
    tada[i] = 0;
    for (size_t j = i; cur && tada[i] <= intmax_t(N);) {
      ++tada[i];
      cur += atari[j] - 1;
      ++j %= N;
    }
  }

  intmax_t res = 0;
  std::map<intmax_t, intmax_t> seen;
  intmax_t last = 0;
  intmax_t ice = 0;
  while (true) {
    ++res;
    ice += tada[last];
    if (tada[last] > intmax_t(N))
      return !printf("%jd\n", res);
    if (ice >= K)
      return !printf("%jd\n", res);

    intmax_t next = (last + tada[last]) % N;
    seen.emplace(last, next);
    last = next;
    if (seen.count(last)) break;
  }

  intmax_t unit = 0;
  intmax_t period = 0;
  intmax_t cur = last;
  do {
    unit += tada[cur];
    ++period;
  } while (cur != last);

  res += (K - ice) / unit * period;
  ice += (K - ice) / unit * unit;

  while (ice < K) {
    ++res;
    ice += tada[last];
    last = (last + tada[last]) % N;
  }

  printf("%jd\n", res);
}
0