結果
問題 | No.389 ロジックパズルの組み合わせ |
ユーザー |
![]() |
提出日時 | 2023-05-23 18:17:04 |
言語 | C++17(clang) (17.0.6 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 114 ms / 2,000 ms |
コード長 | 1,655 bytes |
コンパイル時間 | 4,098 ms |
コンパイル使用メモリ | 161,180 KB |
実行使用メモリ | 7,504 KB |
最終ジャッジ日時 | 2024-12-23 05:02:16 |
合計ジャッジ時間 | 7,948 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 99 |
ソースコード
#include <iostream> #include <vector> #include <set> #include <queue> #include <stack> #include <math.h> #include <cassert> #include <bitset> #include <map> #include <algorithm> #include <iterator> #include <string> #include <utility> #include <numeric> #include <regex> #include <complex> #include <atcoder/all> using namespace atcoder; using namespace std; using ll=long long; using ull=unsigned long long; using P=pair<ll,ll>; template<typename T>using minque=priority_queue<T,vector<T>,greater<T>>; template<typename T>bool chmax(T &a,const T &b){return (a<b?(a=b,true):false);} template<typename T>bool chmin(T &a,const T &b){return (a>b?(a=b,true):false);} template<typename T1,typename T2> ostream &operator<<(ostream &os,const pair<T1,T2>&p){ os<<p.first<<" "<<p.second; return os; } template<typename T1,typename T2> istream &operator>>(istream &is,pair<T1,T2>&p){ is>>p.first>>p.second; return is; } template<typename T> istream &operator>>(istream &is,vector<T> &a){ for(auto &i:a)is>>i; return is; } #define reps(i,a,n) for(int i=(a);i<(n);i++) #define rep(i,n) reps(i,0,n) #define all(x) x.begin(),x.end() ll myceil(ll a,ll b){return (a+b-1)/b;} using mint=modint1000000007; mint comb(int x,int y){ mint ret=1; rep(i,x)ret*=i+1; rep(i,y)ret/=i+1; rep(i,x-y)ret/=i+1; return ret; } int main(){ //FILE *in=freopen("input.text","r",stdin); int m; cin>>m; vector<ll>h; ll x,sum=0; while(cin>>x){ h.push_back(x); sum+=x; } int n=h.size(); if(n==1&&h[0]==0)cout<<1<<endl; else if(sum+n-1>m)cout<<"NA"<<endl; else{ m-=sum; m-=n-1; mint ans=comb(n+m,m); cout<<ans.val()<<endl; } }