fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10.  
  11. static int[] pai = new int[34];
  12. static int count = 0;
  13. static HashSet<String> set = new HashSet<>();
  14.  
  15. public static void main (String[] args) throws java.lang.Exception
  16. {
  17. // your code goes here
  18. Arrays.fill(pai, 4);
  19. atama();
  20.  
  21. System.out.println(count);
  22. System.out.println(set.size());
  23. }
  24.  
  25. static void atama() {
  26. for (int i = 0; i < 34; i++) {
  27. pai[i] -= 2;
  28. ments(4, 0);
  29. pai[i] += 2;
  30. }
  31. }
  32.  
  33. static StringBuilder sb = new StringBuilder(34);
  34. static void ments(int rem, int p) {
  35. if (rem == 0) {
  36. count++;
  37. // sb.setLength(0);
  38. // for (int i : pai) sb.append(i);
  39. // set.add(sb.toString());
  40. return;
  41. }
  42. for (int i = p; i < 34; i++) {
  43. if (pai[i] < 4) continue;
  44. pai[i] -= 3;
  45. ments(rem - 1, i);
  46. pai[i] += 3;
  47. }
  48. for (int i = p; i < 27; i++) {
  49. if (i % 9 > 6) continue;
  50. if (pai[i] == 0) continue;
  51. if (pai[i+1] == 0) continue;
  52. if (pai[i+2] == 0) continue;
  53. pai[i]--;
  54. pai[i+1]--;
  55. pai[i+2]--;
  56. ments(rem - 1, i);
  57. pai[i]++;
  58. pai[i+1]++;
  59. pai[i+2]++;
  60. }
  61. }
  62. }
Success #stdin #stdout 0.16s 49144KB
stdin
Standard input is empty
stdout
9891369
0