結果

問題 No.767 配られたジャパリまん
ユーザー chocoruskchocorusk
提出日時 2018-12-15 00:31:26
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 1,544 ms / 2,000 ms
コード長 1,728 bytes
コンパイル時間 1,085 ms
コンパイル使用メモリ 105,116 KB
実行使用メモリ 14,796 KB
最終ジャッジ日時 2023-10-25 10:31:43
合計ジャッジ時間 4,246 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 11 ms
14,792 KB
testcase_01 AC 10 ms
14,792 KB
testcase_02 AC 11 ms
14,792 KB
testcase_03 AC 11 ms
14,792 KB
testcase_04 AC 12 ms
14,796 KB
testcase_05 AC 109 ms
14,796 KB
testcase_06 AC 10 ms
14,792 KB
testcase_07 AC 11 ms
14,792 KB
testcase_08 AC 10 ms
14,792 KB
testcase_09 AC 13 ms
14,796 KB
testcase_10 AC 56 ms
14,796 KB
testcase_11 AC 14 ms
14,796 KB
testcase_12 AC 14 ms
14,796 KB
testcase_13 AC 56 ms
14,796 KB
testcase_14 AC 12 ms
14,796 KB
testcase_15 AC 10 ms
14,792 KB
testcase_16 AC 13 ms
14,796 KB
testcase_17 AC 10 ms
14,792 KB
testcase_18 AC 11 ms
14,792 KB
testcase_19 AC 17 ms
14,796 KB
testcase_20 AC 1,544 ms
14,796 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
const ll MOD=1e8+7;
ll powmod(ll a, ll k){
    ll ap=a, ans=1;
    while(k>0){
        if(k%2==1){
            ans*=ap;
            ans%=MOD;
        }
        ap=ap*ap;
        ap%=MOD;
        k/=2;
    }
    return ans;
}
ll inv(ll a){
	return powmod(a, MOD-2);
}
int main()
{
	ll f[200001]; f[0]=1;
	for(ll i=1; i<=200000; i++) f[i]=f[i-1]*i%MOD;
	ll invf[200001];
	invf[200000]=inv(f[200000]);
	for(ll i=200000-1; i>=0; i--) invf[i]=invf[i+1]*(i+1)%MOD;
	int h, w, k;
	cin>>h>>w>>k;
	int a[20], b[20];
	for(int i=0; i<k; i++) cin>>a[i]>>b[i];
	ll c[1<<20];
	c[0]=f[h+w]*invf[h]%MOD*invf[w]%MOD;
	for(int i=1; i<(1<<k); i++){
		vector<P> v;
		for(int j=0; j<k; j++){
			if(i&(1<<j)) v.push_back({a[j], b[j]});
		}
		sort(v.begin(), v.end());
		v.push_back({h, w});
		P pr=P(0, 0);
		c[i]=1;
		for(auto p:v){
			if(p.first>=pr.first && p.second>=pr.second){
				c[i]*=(f[p.first-pr.first+p.second-pr.second]*invf[p.first-pr.first]%MOD*invf[p.second-pr.second]%MOD);
				c[i]%=MOD;
				pr=p;
			}else{
				c[i]=0;
				break;
			}
		}
	}
	for(int i=0; i<k; i++){
		for(int j=0; j<(1<<k); j++){
			if(j&(1<<i)){
			    c[j]-=c[j^(1<<i)];
			    c[j]=(c[j]+MOD)%MOD;
			}
		}
	}
	for(int i=0; i<(1<<k); i++){
	    int ct=0;
	    for(int j=0; j<k; j++) if(i&(1<<j)) ct++;
	    if(ct&1) cout<<(MOD-c[i])%MOD<<endl;
	    else cout<<c[i]<<endl;
	}
	return 0;
}
0