제출 #1087056

#제출 시각아이디문제언어결과실행 시간메모리
1087056toast12Telefoni (COCI17_telefoni)C++14
80 / 80
28 ms2140 KiB
#include <bits/stdc++.h>
using namespace std;

int main() {
    int n, d;
    cin >> n >> d;
    vector<int> telephones(n+1);
    for (int i = 1; i <= n; i++) {
        cin >> telephones[i];
    }
    int ans = 0;
    int last = 1;
    int i = last;
    while (i < n) {
        int x = last;
        for (int j = i; j <= min(n, i + d); j++) {
            if (telephones[j])
                x = j;
        }
        if (x == last) {
            ans++;
            last += d;
            i = last;
        }
        else {
            i = x;
            last = x;
        }
    }
    cout << ans << '\n';
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...