#include <bits/stdc++.h>
using namespace std;
const int MOD=1e9+7;
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize ("unroll-loops")
//#pragma GCC optimize("Ofast") //only when desperate
//#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") // only when desperate
#define pb emplace_back
#define mp make_pair
#define fi first
#define se second
#define pi pair<int,int>
#define FOR(a,b,i) for (int i=a;i!=b;a>b?i--:i++)
#define F0R(a,i) FOR(0,a,i)
#define sz(a) (int)(a).size()
#define all(a) (a).begin(), (a).end()
#define allr(a) (a), (a)+sizeof(a)/sizeof(a[0])
#define sq(a) (a)*(a)
#define tri(x) (x)*((x)+1)/2
#define ll long long
#define endl '\n'
#define INF 1e9+5
#define LINF 1e18+5
#define read(x) cin >> x;
#define read2(x,y) cin >> x >> y;
#define read3(x,y,z) cin >> x >> y >> z;
#define read4(w,x,y,z) cin >> w >> x >> y >> z;
#define show(x) cerr << #x << " is " << x << endl;
#define show2(x,y) cerr << #x << " is " << x << " " << #y << " is " << y << endl;
#define show3(x,y,z) cerr << #x << " is " << x << " " << #y << " is " << y << " " << #z << " is " << z << endl;
#define show4(w,x,y,z) cerr << #w << " is " << w << " " << #x << " is " << x << " " << #y << " is " << y << " " << #z << " is " << z << endl;
#define fastio ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define YES cout << "YES\n";
#define NO cout << "NO\n";
mt19937 rng(chrono::system_clock::now().time_since_epoch().count());
void solve(){
int n, k, cnt=0, ans=0; read2(n,k);
bool arr[n], flag=false;
vector <int> v;
for (int i=0;i<n;i++){
read(arr[i]);
if (arr[i]){
if (cnt and (!v.empty() or flag)) v.pb(cnt);
cnt=0;
}
else cnt++;
flag=true;
}
for (auto x:v){
ans+=x/k;
}
cout << ans << '\n';
}
int32_t main(){
fastio;
int tc=1; //cin >> tc;
while (tc--) solve();
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
21 ms |
984 KB |
Output is correct |
9 |
Correct |
17 ms |
964 KB |
Output is correct |
10 |
Correct |
18 ms |
964 KB |
Output is correct |