# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
102347 | jwvg0425 | 마스코트 (JOI13_mascots) | C++17 | 58 ms | 71368 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 <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[3005][3005];
int r, c, n;
i64 facto[9000005];
int lx = 3001, rx = 0, ly = 3001, ry = 0;
i64 wmove[3005];
i64 hmove[3005];
i64 solve(int w, int h)
{
if (w > r || h > c)
return 0;
if (w == r && h == c)
return 1;
if (table[w][h] != -1)
return table[w][h];
auto& res = table[w][h];
res = 0;
i64 wm = wmove[w];
i64 hm = hmove[h];
wm = (wm * solve(w + 1, h)) % MOD;
wm = (wm * facto[h]) % MOD;
hm = (hm * solve(w, h + 1)) % MOD;
hm = (hm * facto[w]) % MOD;
res = (wm + hm) % MOD;
return res;
}
int main()
{
memset(table, -1, sizeof(table));
scanf("%d %d %d", &r, &c, &n);
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;
for (int w = (rx - lx + 1); w <= r; w++)
{
for (int x = 1; x <= r; x++)
{
if (x + w - 1 < rx)
continue;
if (x + w - 1 > r)
break;
if (x == 1 || x + w - 1 == r)
wmove[w]++;
else
wmove[w] += 2;
}
}
for (int h = (ry - ly + 1); h <= c; h++)
{
for (int y = 1; y <= c; y++)
{
if (y + h - 1 < ry)
continue;
if (y + h - 1 > c)
break;
if (y == 1 || y + h - 1 == c)
hmove[h]++;
else
hmove[h] += 2;
}
}
printf("%lld\n", (facto[count] * solve(rx - lx + 1, ry - ly + 1)) % MOD);
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |