# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1168421 | 12345678 | Telefoni (COCI17_telefoni) | C++20 | 10 ms | 2700 KiB |
#include <bits/stdc++.h>
using namespace std;
const int nx=3e5+5;
int n, d, dp[nx], v[nx];
deque<int> dq;
int main()
{
cin.tie(NULL)->sync_with_stdio(false);
cin>>n>>d;
for (int i=1; i<=n; i++) cin>>v[i];
dq.push_back(1);
for (int i=2; i<=n; i++)
{
while (!dq.empty()&&i-dq.front()>d) dq.pop_front();
dp[i]=dp[dq.front()]+!v[i];
while (!dq.empty()&&dp[dq.back()]>=dp[i]) dq.pop_back();
dq.push_back(i);
}
cout<<dp[n];
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |