結果
| 問題 | No.767 配られたジャパリまん | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2020-03-06 06:01:20 | 
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 644 ms / 2,000 ms | 
| コード長 | 1,080 bytes | 
| コンパイル時間 | 756 ms | 
| コンパイル使用メモリ | 78,272 KB | 
| 実行使用メモリ | 15,616 KB | 
| 最終ジャッジ日時 | 2024-10-14 02:35:18 | 
| 合計ジャッジ時間 | 2,971 ms | 
| ジャッジサーバーID (参考情報) | judge5 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 6 | 
| other | AC * 15 | 
コンパイルメッセージ
main.cpp:12:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   12 | main()
      | ^~~~
            
            ソースコード
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
long mod=1e8+7;
long power(long a,long b){return b?power(a*a%mod,b/2)*(b%2?a:1)%mod:1;}
long F[2<<17],I[2<<17];
long C(int N,int K){return F[N]*I[N-K]%mod*I[K]%mod;}
int H,W,K;
int a[20],b[20];
long A[1<<20];
main()
{
	F[0]=1;
	for(int i=1;i<2<<17;i++)F[i]=F[i-1]*i%mod;
	I[(2<<17)-1]=power(F[(2<<17)-1],mod-2);
	for(int i=(2<<17)-1;i--;)I[i]=I[i+1]*(i+1)%mod;
	cin>>H>>W>>K;
	for(int i=0;i<K;i++)cin>>a[i]>>b[i];
	for(int i=0;i<1<<K;i++)
	{
		int nx=0,ny=0;
		long ans=1;
		vector<pair<int,int> >AB;
		for(int j=0;j<K;j++)if(i>>j&1)AB.push_back(make_pair(a[j],b[j]));
		sort(AB.begin(),AB.end());
		for(pair<int,int>ab:AB)
		{
			if(nx<=ab.first&&ny<=ab.second)
			{
				int dx=ab.first-nx,dy=ab.second-ny;
				ans=ans*C(dx+dy,dx)%mod;
				nx=ab.first;
				ny=ab.second;
			}
			else ans=0;
		}
		int dx=H-nx,dy=W-ny;
		ans=ans*C(dx+dy,dx)%mod;
		A[i]=AB.size()%2?mod-ans:ans;
	}
	for(int i=0;i<K;i++)for(int j=0;j<1<<K;j++)if(j>>i&1)(A[j]+=A[j^1<<i])%=mod;
	for(int i=0;i<1<<K;i++)cout<<A[i]<<"\n";
}
            
            
            
        