Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Problem 313B
- #include <bits/stdc++.h>
- using namespace std;
- #define ll long long
- int main()
- {
- string s;
- cin>>s;
- ll n=s.length();
- ll dp[n+1][n+1]={0};
- for (int i=1; i<=n-1; i++){
- if (s[i]==s[i-1]) dp[i][i+1]=1;
- else dp[i][i+1]=0;
- for (int j=i+2; j<=n; j++){
- if (s[j-1]==s[j-2]) dp[i][j]=dp[i][j-1]+1;
- else dp[i][j]=dp[i][j-1];
- }
- }
- /*
- for (int i=1; i<=n-1; i++){
- for (int j=i+1; j<=n; j++){
- cout<<"dp["<<i<<"]["<<j<<"] = "<<dp[i][j]<<"\n";
- }
- }
- */
- ll m;
- cin>>m;
- while(m--){
- ll x,y;
- cin>>x>>y;
- cout<<dp[x][y]<<"\n";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement