Source code for submission s1111

Go to diff to previous submission

fq.cpp

  1.  
  2. #include <cstdlib>
  3. #include <cstdio>
  4. #include <cstring>
  5. #include <cmath>
  6.  
  7. using namespace std;
  8.  
  9. char input[1024];
  10. int tlen;
  11. int **reslt;
  12.  
  13. int f(const char *str, int extra, int rem) {
  14. if (!rem)
  15. return !extra;
  16. if (reslt[extra][rem] >= 0)
  17. return reslt[extra][rem];
  18. int total = 0;
  19. if (str[0] != ')' && str[1] != '(') // ab
  20. total += f(str+2, extra, rem-2);
  21. if (str[0] != '(' && str[1] != '(' && extra >= 2) // bb
  22. total += f(str+2, extra-2, rem-2);
  23. if (str[0] != ')' && str[1] != ')') // aa
  24. total += f(str+2, extra+2, rem-2);
  25. if (str[0] != '(' && str[1] != ')' && extra >= 1) // ba
  26. total += f(str+2, extra, rem-2);
  27. total %= 1000000;
  28. reslt[extra][rem] = total;
  29. return total;
  30. }
  31.  
  32. int main() {
  33. int *inner = new int[1024*1024];
  34. reslt = new int *[1024];
  35. for (int i = 0; i < 1024; i++)
  36. reslt[i] = inner+1024*i;
  37.  
  38. do {
  39. char cur = getchar();
  40. if (cur != '.' && cur != '(' && cur != ')') break;
  41. tlen = 0;
  42. while (cur != '\n') {
  43. input[tlen++] = cur;
  44. cur = getchar();
  45. }
  46. if (!tlen) break;
  47. input[tlen] = 0;
  48. // vstup nacten
  49. for (int i = 0; i <= tlen; i++)
  50. for (int j = 0; j <= tlen; j++)
  51. reslt[i][j] = -1;
  52. int result = f(input, 0, tlen);
  53. printf("%d\n", result);
  54.  
  55. } while (true);
  56.  
  57. delete [] inner;
  58. delete [] reslt;
  59.  
  60. return 0;
  61. }
  62.  

Diff to submission s1108

fq.cpp

--- c5.s1108.cteam033.fq.cpp.0.fq.cpp
+++ c5.s1111.cteam033.fq.cpp.0.fq.cpp
@@ -25,5 +25,5 @@
         if (str[0] != '(' && str[1] != ')' && extra >= 1) // ba
                 total += f(str+2, extra, rem-2);
-        total %= 100000;
+        total %= 1000000;
         reslt[extra][rem] = total;
         return total;