結果

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

ソースコード

diff #

#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
using namespace std;

tuple<int, int, int> solve(const string& s, int eat, int hit)
{
    int n = s.size();
    int buy = 0;
    for(int i=0; i<n; ++i){
        if(eat == 0)
            break;
        if(hit > 0)
            -- hit;
        else
            ++ buy;
        hit += s[i] - '0';
        -- eat;
    }
    return make_tuple(buy, eat, hit);
}

int main()
{
    int n, eat;
    string s;
    cin >> n >> eat >> s;

    int ret = 0;
    int buy, hit;
    tie(buy, eat, hit) = solve(s, eat, 0);
    ret += buy;
    tie(buy, eat, hit) = solve(s, eat, hit);
    ret += buy;

    int x = eat / n;
    ret += x * buy;
    eat -= x * n;

    tie(buy, eat, hit) = solve(s, eat, hit);
    ret += buy;
    cout << ret << endl;

    return 0;
}
0