The great pan
Time Limit: 2000/1000 MS (Java/others) memory limit: 65536/65536 K (Java/Others)
Total submission (s): 1035 accepted submission (s): 355
Problem descriptionas a programming contest addict, waybl is always happy to take part in various competitive programming contests. one day, he was competing at a Regional Contest of inventing crappy problems Contest (ICPC ). he tried really hard to solve a "Geometry" task without success.
After the contest, he found that the problem statement is ambiguous! He immediately complained to jury. But problem setter, the great pan, told him "there are only four possibilities, why don't you just try all of them and get accepted? ".
Waybl was really shocked. It is the first time he learned that enumerating problem statement is as useful as trying to solve some ternary search problem by enumerating a subset of possible angle!
Three years later, while chatting with ceybl, waybl was told that some problem "setters" (Yeah, other than the great pan) cocould even change the whole problem 30 minutes before the contest end! He was again shocked.
Now, for a given problem statement, waybl wants to know how many ways there are to understand it.
A problem statement contains only newlines and printable ASCII characters (32 ≤ their ASCII code ≤ 127) cannot '{', '}', '|' and '$ '.
Waybl has already marked all ambiguity in the following two formats:
1. {A | B | c | d |...} indicates this part cocould be understand as A or B or C or D or ....
2. $ blah $ indicates this part is printed in proportional fonts, it is impossible to determine how character space characters there are.
Note that a, B, c, d won't be duplicate, but cocould be empty. (indicate edevil problem setters addedclarified it later .)
Also note that N consecutive spaces lead to n + 1 different ways of understanding, not 2n ways.
It is impossible to escape from "$" and "{}" markups even with newlines. there won't be nested markups, I. e. something like "$ {A | B} $" or "{$ A $ | B}" or "{A | B} | c}" is prohibited. all markups will be properly matched.
Inputinput contains several test cases, please process till EOF.
For each test case, the first line contains an integer N, indicating the line count of this statement. Next n lines is the problem statement.
1 ≤ n ≤1000, size of the input file will not exceed 1024kb.
Outputfor each test case print the number of ways to understand this statement, or "Doge" If your answer is more
105.
Sample input9i'll shoot the magic arrow several times on the ground, and of course the arrow will leave some holes on the ground. when you connect three holes with three line segments, you may get a triangle. {| it is hole! Common sense! | No response, read Problem Statement | don't you know what a triangle is ?} 1 case $1: =>$ 5 $/* this is my code printed in proportional font, isn' t it cool? */Printf ("definitely it is cooooooooool % d \ n ", 4*4*4*4*4*4*4*4*4*4*4*4*4*4*4*4*4*4 ); $2 $ two space $ and {Blue | red} color!
Sample output44doge6 name: Initialize ans = 1 and give a string with N rows. If {} contains N | characters, ANS * = (n + 1 ), in $, a number of consecutive spaces with a length of N is met, ANS * = (n + 1 ). If ans> 10 ^ 5, output Doge; otherwise, output ans thinking: a typical paper tiger question can scare people to death, use a variety of online translations to understand =). Just simulate it. Code:
1 # include <cstdio> 2 # include <cstring> 3 # include <algorithm> 4 # include <iostream> 5 using namespace STD; 6 7 char a [1000005]; 8 int N; 9 Main () 10 {11 _ int64 flag1, flag2, ans; 12 INT maxh = 100000, I, J, K; 13 _ int64 num1, num2; 14 int Len, flag3; 15 while (scanf ("% d", & n) = 1) {16 ans = 1; 17 flag3 = 0; 18 num1 = num2 = 0; 19 flag1 = flag2 = 0; 20 getchar (); 21 22 while (n --) {23 gets (); 24 Len = strlen (a); 25 for (I = 0; I <le N; I ++) {26 if (a [I] = '{') {27 flag1 = 1; 28} 29 else if (a [I] = '}') {30 flag1 = 0; 31 ans * = (num1 + 1); 32 num1 = 0; 33} 34 else if (a [I] = '$' & flag2 = 0) {35 flag2 = 1; 36} 37 Else if (a [I] = '$' & flag2 = 1) {38 flag2 = 0; 39} 40 else if (a [I] = '|' & flag1) {41 num1 ++; 42} 43 else if (a [I] = ''& flag2) {44 num2 ++; 45} 46 else {47 num2 = 0; 48} 49 if (a [I] = ''& A [I + 1]! = ''& Flag2) {50 ans * = (num2 + 1); 51 num2 = 0; 52} 53 If (ANS> maxh) flag3 = 1; // when this step is completed, it will be wa, because the ANS may exceed the long range 54} 55} 56 If (ANS> maxh | flag3) during the process) printf ("Doge \ n"); 57 else printf ("% i64d \ n", ANS); 58} 59}