fork(2) 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[9];
  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 < 9; i++) {
  27. pai[i] -= 2;
  28. ments(4, 0);
  29. pai[i] += 2;
  30. }
  31. }
  32.  
  33. static void ments(int rem, int p) {
  34. if (rem == 0) {
  35. count++;
  36. StringBuilder sb = new StringBuilder();
  37. for (int i = 0; i < 9; i++) sb.append(pai[i]);
  38. set.add(sb.toString());
  39. return;
  40. }
  41. for (int i = p; i < 9; i++) {
  42. if (pai[i] < 4) continue;
  43. pai[i] -= 3;
  44. ments(rem - 1, i);
  45. pai[i] += 3;
  46. }
  47. for (int i = p; i < 7; i++) {
  48. if (pai[i] == 0) continue;
  49. if (pai[i+1] == 0) continue;
  50. if (pai[i+2] == 0) continue;
  51. pai[i]--;
  52. pai[i+1]--;
  53. pai[i+2]--;
  54. ments(rem - 1, i);
  55. pai[i]++;
  56. pai[i+1]++;
  57. pai[i+2]++;
  58. }
  59. }
  60. }
Success #stdin #stdout 0.23s 62392KB
stdin
Standard input is empty
stdout
8682
7719