結果

問題 No.389 ロジックパズルの組み合わせ
ユーザー snteasntea
提出日時 2016-07-08 22:51:05
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 28 ms / 2,000 ms
コード長 2,177 bytes
コンパイル時間 1,134 ms
コンパイル使用メモリ 147,292 KB
実行使用メモリ 5,208 KB
最終ジャッジ日時 2023-08-03 08:48:03
合計ジャッジ時間 4,781 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 15 ms
4,376 KB
testcase_05 AC 3 ms
4,380 KB
testcase_06 AC 9 ms
4,380 KB
testcase_07 AC 21 ms
4,376 KB
testcase_08 AC 10 ms
4,380 KB
testcase_09 AC 17 ms
4,380 KB
testcase_10 AC 4 ms
4,380 KB
testcase_11 AC 17 ms
4,376 KB
testcase_12 AC 3 ms
4,380 KB
testcase_13 AC 12 ms
4,376 KB
testcase_14 AC 5 ms
4,380 KB
testcase_15 AC 5 ms
4,380 KB
testcase_16 AC 8 ms
4,380 KB
testcase_17 AC 13 ms
4,376 KB
testcase_18 AC 20 ms
5,168 KB
testcase_19 AC 1 ms
4,376 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 1 ms
4,376 KB
testcase_23 AC 1 ms
4,376 KB
testcase_24 AC 1 ms
4,376 KB
testcase_25 AC 1 ms
4,380 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 1 ms
4,380 KB
testcase_28 AC 2 ms
4,376 KB
testcase_29 AC 1 ms
4,380 KB
testcase_30 AC 1 ms
4,380 KB
testcase_31 AC 2 ms
4,380 KB
testcase_32 AC 1 ms
4,380 KB
testcase_33 AC 1 ms
4,376 KB
testcase_34 AC 1 ms
4,376 KB
testcase_35 AC 2 ms
4,376 KB
testcase_36 AC 2 ms
4,380 KB
testcase_37 AC 2 ms
4,376 KB
testcase_38 AC 2 ms
4,380 KB
testcase_39 AC 1 ms
4,376 KB
testcase_40 AC 2 ms
4,376 KB
testcase_41 AC 2 ms
4,380 KB
testcase_42 AC 2 ms
4,376 KB
testcase_43 AC 2 ms
4,376 KB
testcase_44 AC 2 ms
4,376 KB
testcase_45 AC 1 ms
4,376 KB
testcase_46 AC 1 ms
4,376 KB
testcase_47 AC 1 ms
4,380 KB
testcase_48 AC 2 ms
4,380 KB
testcase_49 AC 22 ms
5,052 KB
testcase_50 AC 3 ms
4,380 KB
testcase_51 AC 2 ms
4,380 KB
testcase_52 AC 5 ms
4,376 KB
testcase_53 AC 3 ms
4,376 KB
testcase_54 AC 6 ms
4,380 KB
testcase_55 AC 2 ms
4,376 KB
testcase_56 AC 3 ms
4,376 KB
testcase_57 AC 11 ms
4,380 KB
testcase_58 AC 18 ms
5,136 KB
testcase_59 AC 14 ms
4,376 KB
testcase_60 AC 7 ms
4,376 KB
testcase_61 AC 28 ms
5,208 KB
testcase_62 AC 7 ms
4,380 KB
testcase_63 AC 19 ms
5,168 KB
testcase_64 AC 6 ms
4,380 KB
testcase_65 AC 4 ms
4,380 KB
testcase_66 AC 6 ms
4,376 KB
testcase_67 AC 7 ms
4,380 KB
testcase_68 AC 6 ms
4,380 KB
testcase_69 AC 9 ms
4,380 KB
testcase_70 AC 5 ms
4,380 KB
testcase_71 AC 7 ms
4,380 KB
testcase_72 AC 4 ms
4,376 KB
testcase_73 AC 5 ms
4,376 KB
testcase_74 AC 7 ms
4,376 KB
testcase_75 AC 6 ms
4,376 KB
testcase_76 AC 3 ms
4,384 KB
testcase_77 AC 11 ms
4,376 KB
testcase_78 AC 2 ms
4,376 KB
testcase_79 AC 2 ms
4,380 KB
testcase_80 AC 1 ms
4,376 KB
testcase_81 AC 1 ms
4,380 KB
testcase_82 AC 2 ms
4,380 KB
testcase_83 AC 2 ms
4,376 KB
testcase_84 AC 2 ms
4,380 KB
testcase_85 AC 1 ms
4,380 KB
testcase_86 AC 1 ms
4,376 KB
testcase_87 AC 1 ms
4,380 KB
testcase_88 AC 2 ms
4,376 KB
testcase_89 AC 8 ms
4,376 KB
testcase_90 AC 12 ms
4,376 KB
testcase_91 AC 21 ms
5,180 KB
testcase_92 AC 5 ms
4,380 KB
testcase_93 AC 13 ms
4,380 KB
testcase_94 AC 2 ms
4,376 KB
testcase_95 AC 15 ms
4,376 KB
testcase_96 AC 11 ms
4,376 KB
testcase_97 AC 11 ms
4,380 KB
testcase_98 AC 6 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#ifdef LOCAL111
#else
	#define NDEBUG
#endif
#include <bits/stdc++.h>
const int INF = 1e8;
using namespace std;

#define endl '\n'
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) int((a).size())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define RBP(i,a) for(auto& i : a)
#ifdef LOCAL111
	#define DEBUG(x) cout<<#x<<": "<<(x)<<endl
#else
	#define DEBUG(x) true
#endif
#define F first
#define S second
#define SNP string::npos
#define WRC(hoge) cout << "Case #" << (hoge)+1 << ": "
#define rangej(a,b,c) ((a) <= (c) and (c) < (b))
#define rrangej(b,c) rangej(0,b,c)
template<typename T> void pite(T a, T b){ for(T ite = a; ite != b; ite++) cout << (ite == a ? "" : " ") << *ite; cout << endl;}
template<typename T> bool chmax(T& a, T b){if(a < b){a = b; return true;} return false;}
template<typename T> bool chmin(T& a, T b){if(a > b){a = b; return true;} return false;}

typedef pair<int,int> P;
typedef long long int LL;
typedef unsigned long long ULL;
typedef pair<LL,LL> LP;

void ios_init(){
	//cout.setf(ios::fixed);
	//cout.precision(12);
#ifdef LOCAL111
	return;
#endif
	ios::sync_with_stdio(false); cin.tie(0);	
}

const LL mod = 1e9+7;
//res.first*a+res.second*b == 1 となるresを返す (a,bは互いに素)
pair<long long, long long> extgcd(long long a,long long b)
{
	if(b==1){
		return pair<long long, long long>(0,1);
	}
	pair<long long, long long> t=extgcd(b,a%b);
	return pair<long long, long long>(t.second,t.first-a/b*t.second);
}

//modの逆元を返す
long long inverse(long long mod,long long a)
{
	return (extgcd(mod,a).second+mod)%mod;
}

//xCyを返す
long long Cinv(const long long mod, long long x, long long y){
	long long n = 1 ,r = 1;
	for(int i = 0; i < y; i++){
		n = n*(i+1)%mod;
		r = r*(x-i)%mod;
	}
	return r*inverse(mod,n)%mod;
}

int main()
{
	ios_init();
	int m;
	cin >> m;
	int sum = 0;
	std::vector<int> h;
	int in;
	while(cin >> in) if(in != 0) h.push_back(in),sum += in;
	int k = SZ(h);
	if(m-sum-k+1 < 0) cout << "NA" << endl;
	else {
		cout << Cinv(mod, m-sum+1, m-sum-k+1) << endl;
	}
	return 0;
}
0