제출 #1247937

#제출 시각아이디문제언어결과실행 시간메모리
1247937shiori_chan마스코트 (JOI13_mascots)C++17
100 / 100
1100 ms207520 KiB
#include <iostream>
#include <vector>
#include <random>
#include <algorithm>
#include <chrono>
#define all(x) x.begin(), x.end()
#define fi first
#define se second 
#define compact(v) v.erase(unique(all(v)) , v.end())
#define pi pair<int , int>
#define vi vector<int>
#define FOR(i , l , r) for(int i = l; i <= r; ++ i)

using namespace std;
typedef long long ll;
#define int long long

const int nd = 3001 , mod = 1e9 + 7;
int mul(int a , int b) {return (a * b) % mod;}
int add(int a , int b) {return (a + b) % mod;}

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
uniform_int_distribution<int> dist(1 , (int)2e9);

int f[nd * 3000] , div_f[nd * 3000];	
int dp[nd][nd];

int xpow(int a, int b){
    int ans = 1;
    for(; b; b >>= 1, a = mul(a, a)){
        if(b & 1) ans = mul(ans, a);
    }
    return ans;
}

int nCk(int n , int k){
	if(!k) return 1;
	return mul(f[n] , mul(div_f[k] , div_f[n - k]));
}

void solve(){
	int r , c; cin >> r >> c;

	int n; cin >> n;
	int xn = 1e9 , yn = 1e9 , xx = 0 , yx = 0;
	
	FOR(i , 1 , n){
		int x , y; cin >> x >> y;
		xn = min(xn , x) , xx = max(xx , x);
		yn = min(yn , y) , yx = max(yx , y);
	}

	int x = xx - xn + 1 , y = yx - yn + 1;
	dp[x][y] = f[x * y - n];

	FOR(i , x , r){
		FOR(j , y , c){
			if(i == x && j == y) continue;
			dp[i][j] = add(mul(dp[i - 1][j] , f[j]) , mul(dp[i][j - 1] , f[i]));
		}
	}

	cout << mul(dp[r][c] , mul(nCk(r - x , xn - 1) , nCk(c - y , yn - 1)));
}

signed main() {
   ios_base::sync_with_stdio(false);
   cin.tie(0);

	#define task "task" 
	if(fopen(task".inp", "r")) {
		freopen(task".inp", "r", stdin);
		freopen(task".out", "w", stdout);
	}

	f[0] = 1;
	div_f[0] = 1;
	for(int i = 1; i < nd * 3000; ++ i){
		f[i] = mul(i , f[i - 1]);
		div_f[i] = mul(div_f[i - 1] , xpow(i , mod - 2));
	}
	solve();

	return 0;
}

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

mascots.cpp: In function 'int main()':
mascots.cpp:72:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   72 |                 freopen(task".inp", "r", stdin);
      |                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
mascots.cpp:73:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   73 |                 freopen(task".out", "w", stdout);
      |                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...