Source code for submission s632

fq.cpp

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. int Way[2000][2000];
  6. char Input[2000];
  7.  
  8. int main()
  9. {
  10. while(fgets(Input, 2000, stdin))
  11. {
  12. memset(Way, 0, sizeof(Way));
  13. Way[0][0] = 1;
  14.  
  15. int n = strlen(Input) - 1; //newline!
  16. //puts(Input);
  17.  
  18. for(int i = 0; i < n; i++)
  19. {
  20. for(int j = 0; j <= i + 1; j++)
  21. {
  22. if(Input[i] != ')')
  23. {
  24. if(j)
  25. {
  26. Way[i + 1][j] += Way[i][j - 1];
  27. Way[i + 1][j] %= 1000000;
  28.  
  29. /*if(Way[i][j - 1])
  30. {
  31. printf("A\n");
  32. }*/
  33. }
  34. }
  35.  
  36. if(Input[i] != '(')
  37. {
  38. Way[i + 1][j] += Way[i][j + 1];
  39. Way[i + 1][j] %= 1000000;
  40. }
  41. }
  42. }
  43.  
  44. printf("%d\n", Way[n][0]);
  45. }
  46.  
  47. return 0;
  48. }
  49.