# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|
20029 | | xdoju | 흑백 (kriii4_G) | C++14 | | 0 ms | 1084 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <cstdio>
using namespace std;
const int MOD = 1000000007ll;
int modpow(int r, int n) {
int ret = 1;
while (n > 0) {
if (n % 2 > 0) {
ret = ((long long)ret * r) % MOD;
}
r = ((long long)r * r) % MOD;
n /= 2;
}
return ret;
}
inline int modinv(int n) {
return modpow(n, MOD - 2);
}
inline int modprod(int a, int b) {
a = a % MOD;
b = b % MOD;
return ((long long)a * b) % MOD;
}
inline int modprod(int a, int b, int c) {
c = c % MOD;
return (modprod(a, b) * (long long)c) % MOD;
}
inline int moddiv(int a, int b) {
return ((long long)a * modinv(b)) % MOD;
}
int board[10][10];
int n, m;
bool check(int i, int j, int k, int l, int color) {
for (int l0 = i; l0 <= j; ++l0) {
for (int l1 = k; l1 <= l; ++l1) {
if (board[l0][l1] != color) {
return false;
}
}
}
return true;
}
int ans, allCnt;
void rec(int h, int w) {
if (h == n) {
++allCnt;
int bcnt = 0, wcnt = 0;
for (int i = 0; i < n; ++i) {
for (int j = i; j < n; ++j) {
for (int k = 0; k < m; ++k) {
for (int l = k; l < m; ++l) {
if (board[i][k] == 0) {
bcnt += check(i, j, k, l, board[i][k]) ? 1 : 0;
}
else {
wcnt += check(i, j, k, l, board[i][k]) ? 1 : 0;
}
}
}
}
}
ans = (ans + modprod(bcnt, wcnt)) % MOD;
return;
}
board[h][w] = 0;
if (w == m - 1) {
rec(h + 1, 0);
}
else {
rec(h, w + 1);
}
board[h][w] = 1;
if (w == m - 1) {
rec(h + 1, 0);
}
else {
rec(h, w + 1);
}
}
void proc() {
scanf("%d %d", &n, &m);
ans = 0;
rec(0, 0);
ans = moddiv(ans, allCnt);
printf("%d", ans);
}
int main() {
proc();
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |