結果

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

ソースコード

diff #

#include <iostream>
#include <queue>
#include <vector>
#include <cmath>

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    
    int n, k;
    std::cin >> n >> k;
    std::vector<int> s(n);
    int buyNum = 0;
    int freeNum = 0;
    int ans = 0;
    for(int i=0; i<n; ++i){
        char input;
        std::cin >> input;
        s[i] = input - '0';
    }
    for(int i=0; i<k && i<n; ++i){
        if(freeNum == 0){
            ++buyNum;
        }else{
            --freeNum;
        }
        freeNum += s[i];
    }
    if(n>=k){
        ans = buyNum;
    }else{
        ans += buyNum + std::max((buyNum-freeNum)*(k/n-1), 0);
        for(int i=0; i<(k%n); ++i){
            if(freeNum == 0){
                ++ans;
            }else{
                --freeNum;
            }
            freeNum += s[i];
        }
    }
    std::cout << ans << "\n";   
    return 0;
}
0