fork(2) download
  1. public class BearDestroysDiv2 {
  2.  
  3. int mod;
  4.  
  5. public class Pair {
  6. public long sum;
  7. public long times;
  8. public Pair(long sum, long times) {
  9. this.sum = sum;
  10. this.times = times;
  11. }
  12. public void modulo() {
  13. sum %= mod;
  14. times %= mod;
  15. }
  16. }
  17.  
  18. public int sumUp(int W, int H, int mod_tmp) {
  19. mod = mod_tmp;
  20. final int M = 1 << (W + 1);
  21. Pair dp[] = new Pair[M];
  22. Pair old[] = new Pair[M];
  23. for(int i = 0; i < M; ++i) dp[i] = new Pair(0L,0L);
  24. dp[0] = new Pair(0L, 1L);
  25. int x = 0, y = 0;
  26. while(true) {
  27. for(int mask = 0; mask < M; ++mask) {
  28. old[mask] = new Pair(dp[mask].sum, dp[mask].times);
  29. dp[mask] = new Pair(0L, 0L);
  30. }
  31. for(int mask = 0; mask < M; ++mask) {
  32. Pair me = old[mask];
  33. Boolean right = (0 == (mask & 2) && x != W-1);
  34. Boolean down = (0 == (mask & (1 << W)) && y != H-1);
  35. if(0 != (mask & 1) || (!right && !down)) {
  36. int m = mask / 2;
  37. dp[m].sum += 2 * me.sum;
  38. dp[m].times += 2 * me.times;
  39. dp[m].modulo();
  40. continue;
  41. }
  42. Boolean prefer = false;
  43. for(int hack = 0; hack < 2; ++hack) {
  44. int m;
  45.  
  46. if(right && (prefer || !down))
  47. m = mask / 2 + 1;
  48. else
  49. m = mask / 2 + (1 << (W - 1));
  50. dp[m].sum += me.sum + me.times;
  51. dp[m].times += me.times;
  52. dp[m].modulo();
  53. prefer = true;
  54. }
  55. }
  56. ++x;
  57. if(x == W) {
  58. x = 0;
  59. ++y;
  60. }
  61. if(y == H) return (int) dp[0].sum;
  62. }
  63. }
  64. }
  65.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:1: error: class BearDestroysDiv2 is public, should be declared in a file named BearDestroysDiv2.java
public class BearDestroysDiv2 {
       ^
1 error
stdout
Standard output is empty