fork download
  1. // Errichto - hard
  2. #include<cstdio>
  3. #include<algorithm>
  4. #include<vector>
  5. #include<cstring>
  6. #include<assert.h>
  7. using namespace std;
  8. #define FOR(i,a,n) for(int i = (a); i <= (n); ++i)
  9. #define FORD(i,a,n) for(int i = (a); i >= (n); --i)
  10. #define REP(i,n) FOR(i,0,(n)-1)
  11. #define RI(i,n) FOR(i,1,(n))
  12. #define pb push_back
  13. #define mp make_pair
  14. #define st first
  15. #define nd second
  16. #define mini(a,b) a=min(a,(b))
  17. #define maxi(a,b) a=max(a,(b))
  18. #define sz(w) (int)w.size()
  19. typedef vector<int> vi;
  20. typedef long long ll;
  21. typedef long double ld;
  22. typedef pair<int,int> pii;
  23. const int inf = 1e9 + 5;
  24. const int nax = 1e6 + 5;
  25. const int mod = 1e9 + 7;
  26.  
  27. int mul(int a, int b) { return (ll) a * b % mod; }
  28. int add(int a, int b) { return (a + b) % mod; }
  29.  
  30. int X, Y;
  31.  
  32. class SubRectangles
  33. {
  34. int power(int a, int b) {
  35. int r = 1;
  36. while(b) {
  37. if(b % 2) r = mul(r, a);
  38. a = mul(a, a);
  39. b /= 2;
  40. }
  41. return r;
  42. }
  43. public : int countWays(int H, int W, int h, int w) {
  44. int bin[5][5];
  45. REP(i, 5) {
  46. REP(j, 5) bin[i][j] = 0;
  47. bin[i][0] = 1;
  48. RI(j, i) bin[i][j] = bin[i-1][j-1] + bin[i-1][j];
  49. }
  50. int n = h * w;
  51. int total = 0;
  52. REP(mask, 1 << n) {
  53. int row[4], col[4];
  54. REP(i, 4) row[i] = col[i] = 0;
  55. REP(i, n) if(mask & (1 << i)) {
  56. row[i/w]++;
  57. col[i%w]++;
  58. }
  59. REP(i, 4) assert(row[i] <= w);
  60. REP(i, 4) assert(col[i] <= h);
  61.  
  62. int one = 1;
  63. REP(i, w) {
  64. int Z = (W-i+w-1) / w;
  65. int x = 0;
  66. FOR(j, 0, col[i])
  67. x = add(x, power(bin[col[i]][j], Z));
  68. one = mul(one, x);
  69. }
  70. int two = 1;
  71. REP(i, h) row[i] = w-row[i];
  72. REP(i, h) {
  73. int Z = (H-i+h-1) / h;
  74. ll x = 0;
  75. if(row[i] == 0) x = 1;
  76. else if(row[i] == 1) x = 0;
  77. else if(row[i] == 2) x = power(2, Z) - 2;
  78. else if(row[i] == 3) x = 2LL * power(3, Z) - 6LL * power(2, Z) + 6;
  79. else if(row[i] == 4) x = power(6, Z) + 2LL * power(4, Z) - 16LL * power(3, Z) + 24LL * power(2, Z) - 14LL;
  80. else assert(false);
  81. while(x < 0) x += mod;
  82. //printf("%d - %lld\n", row[i], x);
  83. two = mul(two, x % mod);
  84. }
  85. total = add(total, mul(one, two));
  86. }
  87. return total;
  88. }
  89. };
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
/usr/lib/gcc/i586-linux-gnu/5/../../../i386-linux-gnu/crt1.o: In function `_start':
(.text+0x18): undefined reference to `main'
collect2: error: ld returned 1 exit status
stdout
Standard output is empty