fork download
  1. public class Mutalisk {
  2.  
  3.  
  4. int n;
  5. int[] hp;
  6. int[][][] dp;
  7.  
  8. boolean check(int limit)
  9. {
  10. dp = new int[n+1][limit+1][limit+1];
  11. for(int i = 0; i <= n; i++)
  12. for(int j = 0; j <= limit; j++)
  13. for(int k = 0; k <= limit; k++)
  14. dp[i][j][k] = -1;
  15. dp[0][limit][limit] = limit;
  16. for(int i = 0; i < n; i++)
  17. for(int j = 0; j <= limit; j++)
  18. for(int k = 0; k <= limit; k++)
  19. if(dp[i][j][k] >= 0)
  20. {
  21. int n9 = j;
  22. int n3 = k;
  23. int n1 = dp[i][j][k];
  24. //System.out.println(i + " -> " + n9 + " " + n3 + " " + n1);
  25. for(int useN9 = 0; useN9 <= n9; useN9 ++)
  26. {
  27. if((useN9-1) * 9 >= hp[i]) break;
  28. for(int useN3 = 0; useN3 <= n3; useN3 ++)
  29. {
  30. if(useN3 > 0 && useN9*9 + (useN3-1)*3 >= hp[i]) break;
  31. if(useN3 + useN9 > limit) break;
  32. int useN1 = Math.max(0, hp[i] - useN9*9 - useN3*3);
  33. if(useN1 > n1) continue;
  34. if(useN1 + useN3 + useN9 > limit) continue;
  35.  
  36.  
  37.  
  38. dp[i+1][n9-useN9][n3-useN3] = Math.max(dp[i+1][n9-useN9][n3-useN3], n1 - useN1);
  39. if(i+1 == n)
  40. return true;
  41. }
  42. }
  43. }
  44. return false;
  45. }
  46.  
  47. public int minimalAttacks(int[] x)
  48. {
  49. n = x.length;
  50. hp = x;
  51. int L = 0, R = 7 * x.length, M;
  52. while(R-L > 1)
  53. {
  54. M = (L+R) / 2;
  55. if(check(M))
  56. R = M;
  57. else
  58. L = M;
  59. }
  60. return R;
  61. }
  62.  
  63. }
  64.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:1: error: class Mutalisk is public, should be declared in a file named Mutalisk.java
public class Mutalisk {
       ^
1 error
stdout
Standard output is empty