結果
問題 | No.389 ロジックパズルの組み合わせ |
ユーザー |
|
提出日時 | 2024-09-22 20:21:15 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 105 ms / 2,000 ms |
コード長 | 636 bytes |
コンパイル時間 | 1,710 ms |
コンパイル使用メモリ | 169,308 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-09-22 20:21:21 |
合計ジャッジ時間 | 6,206 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 99 |
ソースコード
#include<bits/stdc++.h> using namespace std; #define ll long long int n; const int p=1e9+7; int qmi(int a,int k){ int res=1; while(k){ if(k&1)res=(ll)res*a%p; a=(ll)a*a%p; k>>=1; } return res; } int C(int a,int b){ int res=1; for(int i=1,j=a;i<=b;i++,j--){ res=(ll)res*j%p; res=(ll)res*qmi(i,p-2)%p; } return res; } int lucas(ll a,ll b){ if(a<p&&b<p)return C(a,b); return (ll)C(a%p,b%p)*lucas(a/p,b/p)%p; } const int N=1e6+5; int a[N]; ll sum;int idx; int main(){ cin>>n;int a; while(cin>>a)idx++,sum+=a; if(sum==0){cout<<1;return 0;} if(n-sum<idx-1){cout<<"NA";return 0;} cout<<lucas(n-sum+1,idx); return 0; }