結果

問題 No.78 クジ付きアイスバー
ユーザー h_noson
提出日時 2016-02-16 15:46:51
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 509 bytes
コンパイル時間 605 ms
コンパイル使用メモリ 55,384 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-11-08 01:36:31
合計ジャッジ時間 1,560 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 35
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
using namespace std;

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