結果

問題 No.78 クジ付きアイスバー
ユーザー PachicobuePachicobue
提出日時 2017-07-28 20:31:57
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,034 bytes
コンパイル時間 1,771 ms
コンパイル使用メモリ 167,556 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-18 11:48:10
合計ジャッジ時間 2,959 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>

#define show(x) cerr << #x << " = " << x << endl

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

template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v)
{
    os << "sz=" << v.size() << "\n[";
    for (const auto& p : v) {
        os << p << ",";
    }
    os << "]\n";
    return os;
}

template <typename S, typename T>
ostream& operator<<(ostream& os, const pair<S, T>& p)
{
    os << "(" << p.first << "," << p.second
       << ")";
    return os;
}


constexpr ll MOD = 1e9 + 7;

template <typename T>
constexpr T INF = numeric_limits<T>::max() / 100;

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

    if (K <= N) {
        ll rest = 0;
        ll buy = 0;
        for (ll i = 0; i < K; i++) {
            if (rest == 0) {
                buy++;
                rest += S[i] - '0';
            } else {
                rest--;
                rest += S[i] - '0';
            }
        }
        cout << buy << endl;
        return 0;
    }


    ll rest = 0;
    vector<bool> buy(N, false);
    for (ll i = 0; i < N; i++) {
        if (rest == 0) {
            buy[i] = true;
            rest += S[i] - '0';
        } else {
            buy[i] = false;
            rest--;
            rest += S[i] - '0';
        }
    }

    vector<ll> revbuy(N, 0);
    if (buy[N - 1]) {
        revbuy[N - 1] = 1;
    }
    for (ll i = N - 2; i >= 0; i--) {
        revbuy[i] = revbuy[i + 1] + (ll)buy[i];
    }
    const ll first = revbuy[0];
    const ll next = (rest < N) ? revbuy[rest] : 0;
    if (next == 0) {
        cout << first << endl;
        return 0;
    }

    const ll box = K / (ll)(N);
    const ll res = K % (ll)(N);
    ll buybuy = first + next * (box - 1);
    for (ll i = 0; i < res; i++) {
        if (rest == 0) {
            buybuy++;
            rest += S[i] - '0';
        } else {
            rest--;
            rest += S[i] - '0';
        }
    }
    cout << buybuy << endl;

    return 0;
}
0