답안 #19927

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
19927 2016-02-25T07:20:46 Z xhae 흑백 (kriii4_G) C++14
6 / 100
2000 ms 5640 KB
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <algorithm>
#include <cmath>
#include <iostream>
#include <sstream>
#include <set>
using namespace std;

const int max_n = 1000;
const int mmod = 1000000007;

int pw2[max_n*max_n+1];
int fac[max_n+1];
int inv_fac[max_n+1];

	int inv_mod(int a, int b) {
		if (a == 1) return b;
		int div = mmod / a + 1;
		return inv_mod((a * (long long)div) % mmod, (b * (long long)div) % mmod);
	}

int combi(int a, int b) {
  return (1LL * fac[a] * inv_fac[b] % mmod * inv_fac[a-b]) % mmod;
}

int main()
{
  int h, w;
  cin >> h >> w;

  pw2[0] = 1;
  for (int i=0; i<h*w; i++)
    pw2[i+1] = (pw2[i] * 2LL) % mmod;
  fac[0] = inv_fac[0] = 1;
  for (int i=1; i<=max_n; i++) {
    fac[i] = (fac[i-1] * 1LL * i) % mmod;
    inv_fac[i] = inv_mod(fac[i], 1);
  }

  int res = 0;
  for (int x1=1; x1<=h; x1++)
    for (int x2=1; x1+x2<=h; x2++)
      for (int y1=1; y1<=w; y1++)
        for (int y2=1; y1+y2<=w; y2++) {
          res = (res + 1LL * combi(h, x1) * combi(h-x1, x2) % mmod * combi(w, y1) % mmod * combi(w-y1, y2) % mmod * pw2[h*w-x1*y1-x2*y2]) % mmod;
          }
  for (int x1=1; x1<=h; x1++)
    for (int y1=1; y1<=w; y1++)
      for (int x_common=1; x_common<=x1; x_common++)
        for (int x2=x_common; x1+x2<=h+x_common; x2++)
          for (int y2=1; y1+y2<=w; y2++) {
            res = (res + 1LL * combi(h, x1) * combi(x1, x_common) % mmod * combi(h-x1, x2-x_common) % mmod * combi(w, y1) % mmod * combi(w-y1, y2) % mmod * pw2[h*w-x1*y1-x2*y2]) % mmod;
          }
  for (int x1=1; x1<=h; x1++)
    for (int y1=1; y1<=w; y1++)
      for (int y_common=1; y_common<=y1; y_common++)
        for (int y2=y_common; y1+y2<=w+y_common; y2++)
          for (int x2=1; x1+x2<=h; x2++) {
            res = (res + 1LL * combi(h, x1) * combi(h-x1, x2) % mmod * combi(w, y1) % mmod * combi(y1, y_common) % mmod * combi(w-y1, y2-y_common) % mmod * pw2[h*w-x1*y1-x2*y2]) % mmod;
          }

  res = (res * 1LL * inv_mod(pw2[h*w], 1)) % mmod;
  printf("%d\n", res);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 5640 KB Output is correct
2 Correct 0 ms 5640 KB Output is correct
3 Correct 0 ms 5640 KB Output is correct
4 Correct 0 ms 5640 KB Output is correct
5 Correct 0 ms 5640 KB Output is correct
6 Correct 0 ms 5640 KB Output is correct
7 Correct 0 ms 5640 KB Output is correct
8 Correct 0 ms 5640 KB Output is correct
9 Correct 0 ms 5640 KB Output is correct
10 Correct 0 ms 5640 KB Output is correct
11 Correct 0 ms 5640 KB Output is correct
12 Correct 0 ms 5640 KB Output is correct
13 Correct 0 ms 5640 KB Output is correct
14 Correct 0 ms 5640 KB Output is correct
15 Correct 0 ms 5640 KB Output is correct
16 Correct 0 ms 5640 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2000 ms 5636 KB Program timed out
2 Halted 0 ms 0 KB -