답안 #202929

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
202929 2020-02-18T17:55:29 Z arnold518 마스코트 (JOI13_mascots) C++14
0 / 100
91 ms 70776 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int MAXN = 3000;
const ll MOD = 1e9+7;

int N, M, Q, X, Y;
int xl, xr, yl, yr;

ll fact[MAXN*MAXN+10], dp[MAXN+10][MAXN+10];

ll mypow(ll x, ll y)
{
	if(y==0) return 1;
	if(y%2) return mypow(x, y-1)*x%MOD;
	ll t=mypow(x, y/2);
	return t*t%MOD;
}

ll inv(ll x) { return mypow(x, MOD-2); }

ll comb(ll n, ll r) { return fact[n]*inv(fact[r])%MOD*inv(fact[n-r])%MOD; }

int main()
{
	int i, j;

	scanf("%d%d%d", &N, &M, &Q);
	yr=1; yl=N; xr=1; xl=M;
	for(i=1; i<=Q; i++)
	{
		int y, x;
		scanf("%d%d", &y, &x);
		yl=min(yl, y); yr=max(yr, y);
		xl=min(xl, x); xr=max(xr, x);
	}
	Y=N-(yr-yl+1);
	X=M-(xr-xl+1);

	fact[0]=1;
	for(i=1; i<=MAXN*MAXN; i++) fact[i]=fact[i-1]*i%MOD;

	for(i=0; i<=Y; i++) for(j=0; j<=X; j++)
	{
		if(i==0 && j==0) { dp[i][j]=1; continue; }
		if(i) dp[i][j]=(dp[i][j]+dp[i-1][j]*fact[N-Y+j]%MOD)%MOD;
		if(j) dp[i][j]=(dp[i][j]+dp[i][j-1]*fact[M-X+i]%MOD)%MOD;
	}
	dp[Y][X]=dp[Y][X]*comb(Y, yl-1)%MOD;
	dp[Y][X]=dp[Y][X]*comb(X, xl-1)%MOD;
	dp[Y][X]=dp[Y][X]*fact[(yr-yl+1)*(xr-xl+1)-Q]%MOD;
	printf("%lld\n", dp[Y][X]);
}

Compilation message

mascots.cpp: In function 'int main()':
mascots.cpp:32:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d%d", &N, &M, &Q);
  ~~~~~^~~~~~~~~~~~~~~~~~~~~~
mascots.cpp:37:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d", &y, &x);
   ~~~~~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 91 ms 70776 KB Output is correct
2 Correct 83 ms 70736 KB Output is correct
3 Correct 86 ms 70768 KB Output is correct
4 Correct 86 ms 70752 KB Output is correct
5 Correct 87 ms 70752 KB Output is correct
6 Correct 87 ms 70776 KB Output is correct
7 Incorrect 88 ms 70752 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 88 ms 70764 KB Output is correct
2 Incorrect 86 ms 70776 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 85 ms 70776 KB Output isn't correct
2 Halted 0 ms 0 KB -