The great pan
Time Limit: 2000/1000 MS (Java/others) memory limit: 65536/65536 K (Java/Others)
Total submission (s): 463 accepted submission (s): 179
Problem descriptionAs a programming contest addict, waybl is always happy to take part in varous 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 Input
9I‘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?}1Case $1: = >$5$/*This is my code printed in proportional font, isn‘t it cool?*/printf("Definitely it is cooooooool %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 output
44doge6
Question:
There are two situations in which n lines of articles are given to you:
1. For {A | B | c | d |...}, read the number X of the vertical lines. The value is x + 1.
2. For $ blah $, read the consecutive numbers of spaces Y1 and y2. .. and the value is (Y1 + 1) * (y2 + 1 )*....
Multiply all the values obtained above.
Ideas:
Simulate it once.
Note:
1. Note that the product of Data multiplication may exceed the int32 bit, or even the 64-bit long. Example:
1
$ A a a A $
If there are 63 null rows in a row, long will pop up.
The solution is to change the value to 10 ^ 5 + 1 when the value exceeds 10 ^ 5 and no longer process strings. For details, see the code.
/*************************************** * *********************************> File Name: 1005.cpp> Author: bslin> mail: [email protected]> created time: ******************************** **************************************** /# include <cstdio> # include <string. h> using namespace STD; # define n 3050000 char STR [N]; int main (INT argc, char * argv []) {freopen ("in.txt", "r ", stdin); In T n, Len, I, j, flagk, flag $, Doge; long space, ANS, tmp1, tmp2; char nowk; while (scanf ("% d ", & N )! = EOF) {ans = 1; tmp1 = 1; // number of vertical bars tmp2 = 1; // The total space product of spaces in each segment $ = 1; // number of spaces in each small segment flagk = Flag $ = 0; // whether "{" or "$" Doge = 0; getchar (); for (I = 0; I <n; ++ I) {gets (STR); Len = strlen (STR); If (Doge) continue; For (j = 0; j <Len; ++ J) {If (STR [J] = '{') {flagk = 1;} else if (STR [J] = '}') {ans = ans * tmp1; tmp1 = 1; flagk = 0;} else if (STR [J] = '$') {If (flag $ = 0) {flag $ = 1;} else {If (nowk = '') {tmp2 = tmp2 * space; If (tmp2> 100000) tmp2 = 100001; /// //} ans = ans * tmp2; tmp2 = 1; space = 1; flag $ = 0 ;}} else {If (flagk) {If (STR [J] = '|') {tmp1 ++ ;}} if (flag $) {If (STR [J] = '') {space ++;} else {tmp2 = tmp2 * space; If (tmp2> 100000) tmp2 = 100001; // Space = 1 ;}}} if (ANS> 100000) Doge = 1; nowk = STR [J] ;}} if (Doge) {printf ("Doge \ n ");} else {printf ("% i64d \ n", ANS) ;}} return 0 ;}