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 <stdio.h>
#include <vector>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>
#include <bitset>
#include <map>
#include <set>
#include <tuple>
#include <string.h>
#include <math.h>
#include <random>
#include <functional>
#include <assert.h>
#include <math.h>
#include <iterator>
#include <chrono>
#define MOD 1000000007
#define all(x) (x).begin(), (x).end()
#define xx first
#define yy second
using namespace std;
using i64 = long long int;
using ii = pair<int, int>;
using ii64 = pair<i64, i64>;
using vi = vector<long long int>;
i64 table[55][55][55][55];
int r, c, n;
i64 facto[9000005];
i64 solve(int lx, int ly, int rx, int ry)
{
if (lx < 1 || ly < 1 || rx > r || ry > c)
return 0;
if (lx == 1 && ly == 1 && rx == r && ry == c)
return 1;
if (table[lx][ly][rx][ry] != -1)
return table[lx][ly][rx][ry];
auto& res = table[lx][ly][rx][ry];
res = 0;
i64 l = (facto[ry - ly + 1] * solve(lx - 1, ly, rx, ry)) % MOD;
i64 r = (facto[ry - ly + 1] * solve(lx, ly, rx + 1, ry)) % MOD;
i64 u = (facto[rx - lx + 1] * solve(lx, ly - 1, rx, ry)) % MOD;
i64 d = (facto[rx - lx + 1] * solve(lx, ly, rx, ry + 1)) % MOD;
res = (res + l) % MOD;
res = (res + r) % MOD;
res = (res + u) % MOD;
res = (res + d) % MOD;
return res;
}
int main()
{
memset(table, -1, sizeof(table));
scanf("%d %d %d", &r, &c, &n);
int lx = r, rx = 0, ly = c, ry = 0;
facto[0] = 1;
for (int i = 1; i <= r * c; i++)
facto[i] = (facto[i - 1] * i) % MOD;
for (int i = 0; i < n; i++)
{
int x, y;
scanf("%d %d", &x, &y);
lx = min(lx, x);
rx = max(rx, x);
ly = min(ly, y);
ry = max(ry, y);
}
int count = (rx - lx + 1) * (ry - ly + 1) - n;
printf("%lld\n", (facto[count] * solve(lx, ly, rx, ry)) % MOD);
return 0;
}
Compilation message (stderr)
mascots.cpp: In function 'int main()':
mascots.cpp:66:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d %d", &r, &c, &n);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
mascots.cpp:78:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d", &x, &y);
~~~~~^~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |