• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
HaibaraAi
博客园    首页    新随笔    联系   管理    订阅  订阅

Codeforce Round #226 Div2 B

   
     
 

            
Sponsored by             
In English             По-русски        
HaibaraAi                 |                  Logout                        
 
 
 
 
 
  • Home
  • Contests
  • Gym
  • Problemset
  • Groups
  • Rating
  • Help
                                     
        
 
 
Codeforces Round #226 (Div. 2)
Finished
Practice
Add to favourites         
 
 
→ Practice            
 
        You are registered for practice. You can solve problems unofficially. Results can be found in the contest status and in the bottom of standings.    
    
 
 
→ Submit?            
 
                                   
Language:                 
Choose file:                 
                                Be careful: there is 50 points penalty for submission which fails the pretests or resubmission (except failure on the first test, denial of judgement or similar verdicts). "Passed pretests" submission verdict doesn't guarantee that the solution is absolutely correct and it will pass system tests.                            
                    
 
 
→ Last submissions            
 
SubmissionTimeVerdict
5794000 01/24/2014 08:52PM Accepted
 
 
→ Problem tags            
 
 
 
 
 
    brute force     
 
 
 
 
    greedy     
 
 
 
 
    implementation     
 
 
 
 
    math     
 
 
 
 
    strings     
No tag edit access    
              
              
                
                
  •  
     
     
  • Problems
  • Submit
  • My submissions
  • Status
  • Hacks
  • Room
  • Standings
  • Custom test
B. Bear and Strings
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

The bear has a string s = s1s2... s|s| (record |s| is the string's length), consisting of lowercase English letters. The bear wants to count the number of such pairs of indices i, j (1 ≤ i ≤ j ≤ |s|), that string x(i, j) = sisi + 1... sj contains at least one string "bear" as a substring.

String x(i, j) contains string "bear", if there is such index k (i ≤ k ≤ j - 3), that sk = b, sk + 1 = e, sk + 2 = a, sk + 3 = r.

Help the bear cope with the given problem.

Input

The first line contains a non-empty string s (1 ≤ |s| ≤ 5000). It is guaranteed that the string only consists of lowercase English letters.

Output

Print a single number — the answer to the problem.

Sample test(s)
Input
bearbtear
Output
6
Input
bearaabearc
Output
20
Note

In the first sample, the following pairs (i, j) match: (1, 4), (1, 5), (1, 6), (1, 7), (1, 8), (1, 9).

In the second sample, the following pairs (i, j) match: (1,  4), (1,  5), (1,  6), (1,  7), (1,  8), (1,  9), (1,  10), (1,  11), (2,  10), (2,  11), (3,  10), (3,  11), (4,  10), (4,  11), (5,  10), (5,  11), (6,  10), (6,  11), (7,  10), (7,  11).

            

Codeforces (c) Copyright 2010-2014 Mike Mirzayanov
The only programming contests Web 2.0 platform
Server time: 01/26/2014 10:37PM (p1).
 
 
 
 1 #pragma comment(linker,"/STACK:102400000,102400000")
 2 #include <cstdio>
 3 #include <vector>
 4 #include <cmath>
 5 #include <queue>
 6 #include <cstring>
 7 #include <iostream>
 8 #include <algorithm>
 9 using namespace std;
10 #define INF 0x7fffffff 
11 #define mod 1000000007
12 #define ll long long
13 #define maxn 5025
14 #define pi acos(-1.0)
15 int n, m;
16 char s[maxn];
17 int a[maxn][maxn];
18 int main(){
19     scanf("%s", s);
20     n = strlen(s);
21     int x = -1;
22     for (int i = 0; i < n; i++){
23         if (s[i] == 'b'&&s[i + 1] == 'e'&&s[i + 2] == 'a'&&s[i + 3] == 'r'){
24             for (int k = x + 1; k <= i; k++){
25                 for (int j = i + 3; j < n; j++){
26                     a[k][j] = 1;
27                 }
28             }
29             x = i;
30         }
31     }
32     int t = 0;
33     for (int i = 0; i < n;i++)
34     for (int j = i+3; j < n; j++){
35         if (a[i][j])t++;
36     }
37     printf("%d\n", t);
38     return 0;
39 }
View Code
posted @ 2014-01-27 02:37  HaibaraAi  阅读(214)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3