제출 #202930

#제출 시각아이디문제언어결과실행 시간메모리
202930arnold518마스코트 (JOI13_mascots)C++14
100 / 100
257 ms137440 KiB
#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[M-X+j]%MOD)%MOD;
		if(j) dp[i][j]=(dp[i][j]+dp[i][j-1]*fact[N-Y+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]);
}

컴파일 시 표준 에러 (stderr) 메시지

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);
   ~~~~~^~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...