Advertisement
fooker

Problem 313B

Dec 22nd, 2022
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.70 KB | None | 0 0
  1. // Problem 313B
  2. #include <bits/stdc++.h>
  3. using namespace std;
  4. #define ll long long
  5. int main()
  6. {
  7.     string s;
  8.     cin>>s;
  9.     ll n=s.length();
  10.     ll dp[n+1][n+1]={0};
  11.     for (int i=1; i<=n-1; i++){
  12.         if (s[i]==s[i-1]) dp[i][i+1]=1;
  13.         else dp[i][i+1]=0;
  14.         for (int j=i+2; j<=n; j++){
  15.             if (s[j-1]==s[j-2]) dp[i][j]=dp[i][j-1]+1;
  16.             else dp[i][j]=dp[i][j-1];
  17.         }
  18.     }
  19.     /*
  20.     for (int i=1; i<=n-1; i++){
  21.         for (int j=i+1; j<=n; j++){
  22.             cout<<"dp["<<i<<"]["<<j<<"] = "<<dp[i][j]<<"\n";
  23.         }
  24.     }
  25.     */
  26.     ll m;
  27.     cin>>m;
  28.     while(m--){
  29.         ll x,y;
  30.         cin>>x>>y;
  31.         cout<<dp[x][y]<<"\n";
  32.     }
  33. }
  34.  
  35.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement