Codeforces Round 340 (Div. 2) 617B. Chocolate Solution
Problem Link : https://codeforces.com/problemset/problem/617/B
Solution in C++:
- /// Author : AH_Tonmoy
- #include <bits/stdc++.h>
- using namespace std;
- int32_t main() {
- ios_base::sync_with_stdio(0);
- cin.tie(0);
- int n ;
- cin >> n ;
- std::vector<int> a(n+1);
- int cnt_one = 0 ;
- for (int i = 1 ; i <= n ; i++){
- cin >> a[i];
- }
- int pre_value = - 1 ;
- long long ans = 1 ;
- for ( int i = 1 ; i <= n ; i++){
- if (a[i] == 1){
- if (pre_value != -1){
- ans *= (i - pre_value) ;
- }
- pre_value = i ;
- }
- }
- if (pre_value == -1)cout <<"0\n";
- else
- cout << ans <<'\n';
- return 0 ;
- }
No comments