Submission #102346

# Submission time Handle Problem Language Result Execution time Memory
102346 2019-03-24T12:40:26 Z jwvg0425 마스코트 (JOI13_mascots) C++17
0 / 100
68 ms 71384 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[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 + 1];
	i64 hm = hmove[h + 1];

	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

mascots.cpp: In function 'int main()':
mascots.cpp:70: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:80: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 Incorrect 57 ms 71032 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 61 ms 71004 KB Output is correct
2 Correct 60 ms 70968 KB Output is correct
3 Incorrect 68 ms 71032 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 58 ms 71384 KB Output isn't correct
2 Halted 0 ms 0 KB -