結果

問題 No.117 組み合わせの数
ユーザー FF256grhyFF256grhy
提出日時 2017-06-21 04:30:07
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 118 ms / 5,000 ms
コード長 2,364 bytes
コンパイル時間 1,480 ms
コンパイル使用メモリ 159,932 KB
実行使用メモリ 19,044 KB
最終ジャッジ日時 2024-04-10 06:41:19
合計ジャッジ時間 2,212 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 118 ms
19,044 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:65:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   65 |         scanf("%d\n", &t);
      |         ~~~~~^~~~~~~~~~~~
main.cpp:67:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   67 |                 scanf("%c(%d,%d)\n", &c, &n, &k);
      |                 ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

typedef long long   signed int LL;
typedef long long unsigned int LU;

#define incID(i, l, r) for(int i = (l)    ; i <  (r); i++)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); i++)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); i--)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); i--)
#define  inc(i, n) incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define  dec(i, n) decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)

#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))

#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define UB upper_bound
#define LB lower_bound
#define PQ priority_queue

#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
#define  FOR(it, v) for(auto it =  v.begin(); it !=  v.end(); ++it)
#define RFOR(it, v) for(auto it = v.rbegin(); it != v.rend(); ++it)

template<typename T> bool   setmin(T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool   setmax(T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

// ---- ----

int t, n, k;
char c;
LL p[2000000], MOD = 1e9 + 7;

LL ex_gcd(LL a, LL b, LL & x, LL & y) {
	LL d = a;
	if(b != 0) {
		d = ex_gcd(b, a % b, y, x);
		y -= (a / b) * x;
	} else { x = 1; y = 0; }
	return d;
}
LL divmod(LL x, LL y, LL MOD) {
	LL inv, m;
	ex_gcd(y, MOD, inv, m);
	if(inv < 0) { inv += MOD; }
	return x * inv % MOD;
}

int main() {
	p[0] = 1;
	incID(i, 1, 2000000) { p[i] = p[i - 1] * i % MOD; }
	
	scanf("%d\n", &t);
	inc(i, t) {
		scanf("%c(%d,%d)\n", &c, &n, &k);
		
		LL ans = 1;
		if(c == 'P') {
			ans = (k > n ? 0 : divmod(p[n], p[n - k], MOD));
		}
		if(c == 'C') {
			ans = (k > n ? 0 : divmod(p[n], p[n - k] * p[k], MOD));
		}
		if(c == 'H') {
			ans = (k == 0 ? 1 : (n == 0 ? 0 : divmod(p[n + k - 1], p[n - 1] * p[k], MOD)));
		}
		cout << ans << "\n";
	}
	
	return 0;
}
0