結果

問題 No.117 組み合わせの数
ユーザー tubo28tubo28
提出日時 2015-01-05 02:06:50
言語 C++11
(gcc 13.3.0)
結果
AC  
実行時間 258 ms / 5,000 ms
コード長 2,330 bytes
コンパイル時間 716 ms
コンパイル使用メモリ 67,612 KB
実行使用メモリ 26,880 KB
最終ジャッジ日時 2024-06-13 02:39:18
合計ジャッジ時間 1,613 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 1
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:100:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
  100 |         scanf("\n%c(%d,%d)",&c,&N,&K);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~

ソースコード

diff #
プレゼンテーションモードにする

#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <sstream>
#include <utility>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
#define all(c) (c).begin(), (c).end()
#define loop(i,a,b) for(ll i=a; i<ll(b); i++)
#define rep(i,b) loop(i,0,b)
#define each(e,c) for(auto&e:c)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define lb lower_bound
#define ub upper_bound
#ifdef DEBUG
#define dump(...) (cerr<<#__VA_ARGS__<<" = "<<(DUMP(),__VA_ARGS__).str()<<" ["<<__LINE__<<"]"<<endl)
struct DUMP:ostringstream{template<class T>DUMP &operator,(const T&t){if(this->tellp())*this<<", ";*this<<t;return *this;}};
#else
#define dump(...)
#endif
template<class T> ostream& operator<<(ostream& os, vector<T> const& v){
rep(i,v.size()) os << v[i] << (i+1==v.size()?"":" ");
return os;
}
ll const mod = 1000000007;
int const MAX_N = 3000000;
// ll inv[MAX_N+1];
// void build_inverse(){
// inv[1] = 1;
// for(int i = 2; i <= MAX_N; i++){
// inv[i] = inv[mod%i]*(mod-mod/i)%mod;
// }
// }
ll fact[MAX_N+1];
void build_factrial(){
fact[0] = fact[1] = 1;
for(ll i = 1; i < MAX_N; i++){
fact[i+1] = fact[i]*(i+1)%mod;
}
}
ll extgcd(ll a, ll b, ll& x, ll& y) {
ll d = a;
if(b != 0){
d = extgcd(b,a%b,y,x);
y -= (a/b)*x;
} else {
x=1; y=0;
}
return d;
}
ll mod_inverse(ll n, ll m) {
ll x, y;
extgcd(n, m, x, y);
return (m+x%m) % m;
}
ll inv(ll n){
return mod_inverse(n,mod);
}
ll nPr(ll n, ll r){
if(r < 0 || n < r) return 0;
return fact[n] * inv(fact[n-r]) % mod;
}
ll nCr(ll n, ll r){
if(r < 0 || n < r) return 0;
return nPr(n,r) * inv(fact[r]) % mod;
}
ll nHr(ll n, ll r){
if(n==0 && r==0) return 1;
return nCr(n+r-1,r);
}
int main(){
// build_inverse();
build_factrial();
int T;
while(cin >> T){
rep(i,T){
char c; int N, K;
dump(c,N,K);
scanf("\n%c(%d,%d)",&c,&N,&K);
if(c=='C') cout << nCr(N,K);
if(c=='P') cout << nPr(N,K);
if(c=='H') cout << nHr(N,K);
cout << endl;
}
}
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0