Source code for submission s934

Fq.java

  1.  
  2. import java.util.ArrayList;
  3. import java.util.LinkedList;
  4. import java.util.Scanner;
  5.  
  6. /*
  7.  * To change this template, choose Tools | Templates
  8.  * and open the template in the editor.
  9.  */
  10. /**
  11.  *
  12.  * @author cteam92
  13.  */
  14. public class Fq {
  15.  
  16. /**
  17.   * @param args the command line arguments
  18.   */
  19. public static void main(String[] args) {
  20. Scanner sc = new Scanner(System.in);
  21. while (true) {
  22. if (!sc.hasNext()) {
  23. break;
  24. }
  25. String line = sc.nextLine();
  26. int n = line.length();
  27. int[][] array = new int[n + 1][(n / 2) + 1];
  28. array[0][0] = 1;
  29.  
  30. int m = (n / 2) + 1;
  31. for (int l = 1; l <= n; l++) {
  32. for (int p = 0; p < m; p++) {
  33. int count1 = 0;
  34. int count2 = 0;
  35. if (p - 1 >= 0) {
  36. count1 = array[l - 1][p - 1];
  37. }
  38. if (p + 1 < m) {
  39. count2 = array[l - 1][p + 1];
  40. }
  41. if (line.charAt(l - 1) == '.') {
  42. array[l][p] = (count1 + count2) % 1000000;
  43. } else if (line.charAt(l - 1) == '(') {
  44. array[l][p] = count1;
  45. } else {
  46. array[l][p] = count2;
  47. }
  48. }
  49. }
  50. System.out.println(array[n][0]);
  51. }
  52. }
  53. }
  54.