結果
| 問題 | No.389 ロジックパズルの組み合わせ | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2020-02-22 19:33:45 | 
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 69 ms / 2,000 ms | 
| コード長 | 406 bytes | 
| コンパイル時間 | 570 ms | 
| コンパイル使用メモリ | 66,696 KB | 
| 実行使用メモリ | 6,824 KB | 
| 最終ジャッジ日時 | 2024-10-09 20:45:16 | 
| 合計ジャッジ時間 | 3,958 ms | 
| ジャッジサーバーID (参考情報) | judge2 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 99 | 
コンパイルメッセージ
main.cpp:5:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
    5 | main()
      | ^~~~
            
            ソースコード
#include<iostream>
using namespace std;
long mod=1e9+7;
long power(long a,long b){return b?power(a*a%mod,b/2)*(b%2?a:1)%mod:1;}
main()
{
	int M;cin>>M;
	int s=0,c=0;
	for(int h;cin>>h;c++)s+=h;
	if(s==0)c=0;
	if(s+c-1>M)
	{
		cout<<"NA"<<endl;
		return 0;
	}
	long a=1,b=1;
	int N=c+1,K=M-(s+c-1);
	N+=K-1;
	for(long i=1;i<=K;i++)
	{
		a=a*(N-i+1)%mod;
		b=b*i%mod;
	}
	cout<<a*power(b,mod-2)%mod<<endl;
}
            
            
            
        