Submission #102343

# Submission time Handle Problem Language Result Execution time Memory
102343 2019-03-24T11:45:45 Z jwvg0425 마스코트 (JOI13_mascots) C++17
40 / 100
74 ms 72312 KB
#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

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
1 Correct 62 ms 71928 KB Output is correct
2 Correct 61 ms 71928 KB Output is correct
3 Correct 58 ms 71928 KB Output is correct
4 Correct 56 ms 71936 KB Output is correct
5 Correct 56 ms 71928 KB Output is correct
6 Correct 65 ms 71928 KB Output is correct
7 Correct 56 ms 71928 KB Output is correct
8 Correct 61 ms 71904 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 66 ms 71928 KB Output is correct
2 Correct 56 ms 71948 KB Output is correct
3 Correct 63 ms 72020 KB Output is correct
4 Correct 63 ms 72000 KB Output is correct
5 Correct 63 ms 72040 KB Output is correct
6 Correct 58 ms 71928 KB Output is correct
7 Correct 65 ms 71928 KB Output is correct
8 Correct 60 ms 71900 KB Output is correct
9 Correct 74 ms 72040 KB Output is correct
10 Correct 62 ms 71900 KB Output is correct
11 Correct 74 ms 72028 KB Output is correct
12 Correct 57 ms 71928 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 69 ms 72312 KB Output isn't correct
2 Halted 0 ms 0 KB -