Source code for submission s718

four.cpp

  1. #include <algorithm>
  2. #include <cctype>
  3. #include <cmath>
  4. #include <cstdio>
  5. #include <cstring>
  6. #include <iostream>
  7. #include <list>
  8. #include <map>
  9. #include <queue>
  10. #include <set>
  11. #include <sstream>
  12. #include <stack>
  13. #include <string>
  14. #include <utility>
  15. #include <vector>
  16. using namespace std;
  17.  
  18. #define DEBUG(x) cerr << ">> " << #x << ": " << x << endl;
  19. #define REP(i,a) for (int i =0; i < (a);++i)
  20. #define FOR(i,a,b) for (int i = (a); i <= (b); ++i)
  21.  
  22. long tabulka[1000][1000];
  23.  
  24. int main() {
  25. string s;
  26. while (getline(cin, s, '\n'))
  27. {
  28. if (s[0] == ')')
  29. {
  30. printf("0\n");
  31. continue;
  32. }
  33. int len = s.length();
  34. for (int column = 0; column < len; column++)
  35. {
  36. for (int row = 0; row < len; row++)
  37. {
  38. tabulka[row][column] = 0;
  39. }
  40. }
  41. tabulka[0][0] = 0;
  42. tabulka[0][1] = 1;
  43. for (int row = 1; row < len; row++)
  44. {
  45. for (int column = 0; column < row+2 && column < len/2+1; column++)
  46. {
  47. if (column == 0)
  48. {
  49. if (s[row] != '(')
  50. {
  51. tabulka[row][column] = tabulka[row-1][column+1] % 1000000;
  52. } else tabulka[row][column] = 0;
  53. }
  54. else
  55. {
  56. tabulka[row][column] =
  57. (
  58. (s[row] != ')' ? tabulka[row-1][column-1] : 0) +
  59. (s[row] != '(' ? tabulka[row-1][column+1] : 0)
  60. )
  61. % 1000000;
  62. }
  63. }
  64. }
  65. printf("%ld\n", tabulka[len-1][0]);
  66. }
  67. return 0;
  68. }