My issue
Solution Failed on following Input
1
a
Your Output
0
Expected Output
1
My code
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int ll
#define now(x) cout<<#x<<" : "<<x<<'\n';
#define fv(v) cout<<#v<<" : "; for(auto it:v) cout<<it<<" "; cout<<'\n';
#define pm(m) cout<<#m<<" : "; for(auto it:m) cout<<it.first<<" "<<it.second<<'\n';
const int modd = 1000000007;
void solve()
{
string w; cin >> w;
int m = w.length();
int pq_p = 0, pq_q = 0, p_p = 0;
for(int i = 0; i < m;++i)
{
if(w[i] == 'p') {
pq_p = (pq_q + pq_p) % modd;
p_p = (2 * p_p) % modd;
p_p = (p_p + 1) % modd;
}
else{
pq_q = (pq_q + p_p + pq_p) % modd;
}
}
cout << (p_p + pq_q) % modd << '\n';
}
int32_t main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int vk = 1;
cin >> vk;
while (vk--) {
solve();
}
}
Problem Link: Is it uniquely decodable Practice Coding Problem - CodeChef