結果

問題 No.78 クジ付きアイスバー
ユーザー ry0u_ydry0u_yd
提出日時 2015-09-01 22:13:57
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,416 bytes
コンパイル時間 744 ms
コンパイル使用メモリ 69,276 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-16 05:41:28
合計ジャッジ時間 2,823 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 AC 1 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 1 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 AC 2 ms
5,376 KB
testcase_17 AC 2 ms
5,376 KB
testcase_18 AC 2 ms
5,376 KB
testcase_19 AC 161 ms
5,376 KB
testcase_20 AC 228 ms
5,376 KB
testcase_21 WA -
testcase_22 AC 88 ms
5,376 KB
testcase_23 AC 1 ms
5,376 KB
testcase_24 AC 2 ms
5,376 KB
testcase_25 AC 1 ms
5,376 KB
testcase_26 AC 2 ms
5,376 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 AC 2 ms
5,376 KB
testcase_31 AC 2 ms
5,376 KB
testcase_32 WA -
testcase_33 WA -
testcase_34 AC 15 ms
5,376 KB
testcase_35 WA -
testcase_36 AC 134 ms
5,376 KB
testcase_37 AC 113 ms
5,376 KB
testcase_38 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <sstream>
#include <map>
#include <set>

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1<<30
#define pb push_back
#define mp make_pair

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

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

    vector<int> v(n);
    rep(i,n) v[i] = s[i] - '0';

    if(n > k) {
        int ans = 0, cnt = 0;
        rep(i,k) {
            if(cnt > 0) cnt--;
            else ans++;

            cnt += v[i];
        }

        cout << ans << endl;
    } else {
        int res = 0, cnt = 0;
        rep(i,n) {
            if(cnt > 0) cnt--;
            else res++;

            cnt += v[i];
        }

        if(cnt >= res) {
            cout << res << endl;
        } else {
            int m = 0;
            int ans = 0, q = 0;
            while(m + n <= k) {
                m += n;
                if(q >= res) {
                    q -= res;
                    q += cnt;
                } else {
                    ans += res - q;
                    q = cnt;
                }
            }

            rep(i,k%n) {
                if(q > 0) q++;
                else ans++;

                q += v[i];
            }

            cout << ans << endl;
        }

    }
    return 0;
}
0