結果

問題 No.78 クジ付きアイスバー
ユーザー fine
提出日時 2016-06-07 00:37:39
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 3 ms / 5,000 ms
コード長 671 bytes
コンパイル時間 1,573 ms
コンパイル使用メモリ 165,652 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-11-08 01:45:22
合計ジャッジ時間 2,771 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 35
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

int n, k;
string s;

int solve(int& ans, int& rest, int& stock) {
    int tmp = 0;
    for (int i = 0; i < n; i++) {
        if (rest) rest--;
        else {
            ans += tmp;
            return tmp;
        }
        if (stock) stock--;
        else tmp++;
        stock += s[i] - '0';
    }
    ans += tmp;
    return tmp;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n >> k;
    cin >> s;
    int ans = 0, stock = 0;
    solve(ans, k, stock);
    int tmp = solve(ans, k, stock);
    ans += (k / n) * tmp;
    k %= n;
    solve(ans, k, stock);
    cout << ans << "\n";
    return 0;
}
0