Codeforces Round 340 (Div. 2) 617B. Chocolate Solution


 

 Problem Link :  https://codeforces.com/problemset/problem/617/B

Solution in C++:

  1. /// Author : AH_Tonmoy
  2. #include <bits/stdc++.h>
  3. using namespace std;
  4. int32_t main() {
  5. ios_base::sync_with_stdio(0);
  6. cin.tie(0);
  7. int n ;
  8. cin >> n ;
  9. std::vector<int> a(n+1);
  10. int cnt_one = 0 ;
  11. for (int i = 1 ; i <= n ; i++){
  12. cin >> a[i];
  13. }
  14. int pre_value = - 1 ;
  15. long long ans = 1 ;
  16. for ( int i = 1 ; i <= n ; i++){
  17. if (a[i] == 1){
  18. if (pre_value != -1){
  19. ans *= (i - pre_value) ;
  20. }
  21. pre_value = i ;
  22. }
  23. }
  24. if (pre_value == -1)cout <<"0\n";
  25. else
  26. cout << ans <<'\n';
  27. return 0 ;
  28. }

No comments

Most View Post

Recent post

Codeforces Round 971 (Div. 4) 2009C. The Legend of Freya the Frog Solution

  Problem Link    https://codeforces.com/contest/2009/problem/C S olution in C++: /// Author : AH_Tonmoy #include < bits / stdc ++. h ...

Powered by Blogger.