結果

問題 No.767 配られたジャパリまん
ユーザー kotatsugamekotatsugame
提出日時 2020-03-06 06:01:20
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 606 ms / 2,000 ms
コード長 1,080 bytes
コンパイル時間 687 ms
コンパイル使用メモリ 78,776 KB
実行使用メモリ 15,944 KB
最終ジャッジ日時 2024-04-22 03:42:44
合計ジャッジ時間 2,675 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 10 ms
7,964 KB
testcase_01 AC 10 ms
7,924 KB
testcase_02 AC 10 ms
7,632 KB
testcase_03 AC 10 ms
8,632 KB
testcase_04 AC 12 ms
7,960 KB
testcase_05 AC 46 ms
8,436 KB
testcase_06 AC 11 ms
8,160 KB
testcase_07 AC 11 ms
8,104 KB
testcase_08 AC 12 ms
8,048 KB
testcase_09 AC 12 ms
8,164 KB
testcase_10 AC 29 ms
8,420 KB
testcase_11 AC 12 ms
7,636 KB
testcase_12 AC 13 ms
8,732 KB
testcase_13 AC 30 ms
8,104 KB
testcase_14 AC 12 ms
8,916 KB
testcase_15 AC 11 ms
8,836 KB
testcase_16 AC 11 ms
8,148 KB
testcase_17 AC 11 ms
9,368 KB
testcase_18 AC 12 ms
8,028 KB
testcase_19 AC 14 ms
9,212 KB
testcase_20 AC 606 ms
15,944 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:12:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   12 | main()
      | ^~~~

ソースコード

diff #

#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";
}
0