답안 #676144

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
676144 2022-12-29T13:36:30 Z LeonaRaging Telefoni (COCI17_telefoni) C++14
56 / 80
18 ms 1620 KB
#include <bits/stdc++.h>
using namespace std;

#define db(val) "[" #val " = " << (val) << "] "

const int maxn = 1e5 + 4;

int n, d, nxt[maxn];
bool a[maxn];

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    cin >> n >> d;
    for (int i = 1; i <= n; i++)
    	cin >> a[i];
    queue<int> q;
    for (int i = n; i >= 1; i--) {
    	while (!q.empty() && q.front() > i + d)
    		q.pop();
    	nxt[i] = (!q.empty() ? q.front() : 0);
    	if (a[i]) q.push(i);
    }
    int cur = 1, res = 0;
    while (cur < n) {
    	if (nxt[cur]) cur = nxt[cur];
    	else res++, cur = cur + d;
    }
    cout << res;
}

# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 320 KB Output is correct
8 Runtime error 18 ms 1588 KB Execution killed with signal 11
9 Runtime error 18 ms 1584 KB Execution killed with signal 11
10 Runtime error 17 ms 1620 KB Execution killed with signal 11