Help in problem 1084C

Revision en1, by BanazadehAria, 2019-06-27 07:31:46

Hi,

Problem ==> http://mirror.codeforces.com/problemset/problem/1084/C

My solution gets WA in test case 10 and I think it because overflow but I can't see any overflow problem.

include<bits/stdc++.h>

using namespace std;

const int INF = 1e9+7;

define mp make_pair

define pb push_back

int MOD(int x){ return ((x%INF)+INF)%INF; }

int main()
{
    string n;cin >> n;
    string s;
    for(int i=0;i<n.size();++i){
        if(n[i]=='a' || n[i]=='b') s+=n[i];
    }
    //Get number of all of the contigiuos 'a's
    vector<int> ans;
    int cnt = 0;
    for(int i=0;i<s.size();++i){
        if(s[i]=='a') ++cnt;
        else{
            ans.pb(cnt);cnt=0;
        }
    }ans.push_back(cnt);
    //Calculate the answer
    long long res=1;
    for(auto &i : ans){
        res = MOD(MOD(res) * MOD(i+1));
    }cout << res-1;
}
Tags #implementation, #c++, #problem c, #help

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en3 English BanazadehAria 2019-06-27 07:33:07 20
en2 English BanazadehAria 2019-06-27 07:32:29 53
en1 English BanazadehAria 2019-06-27 07:31:46 910 Initial revision (published)