제출 #1168421

#제출 시각아이디문제언어결과실행 시간메모리
116842112345678Telefoni (COCI17_telefoni)C++20
80 / 80
10 ms2700 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 timeMemoryGrader output
Fetching results...