結果
| 問題 |
No.117 組み合わせの数
|
| ユーザー |
tubo28
|
| 提出日時 | 2015-01-05 02:03:00 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,255 bytes |
| コンパイル時間 | 807 ms |
| コンパイル使用メモリ | 66,860 KB |
| 実行使用メモリ | 26,916 KB |
| 最終ジャッジ日時 | 2024-06-13 02:38:12 |
| 合計ジャッジ時間 | 1,668 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | WA * 1 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:95:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
95 | scanf("\n%c(%d,%d)",&c,&N,&K);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
ソースコード
#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;
}
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 << nCr(N+K-1,K);
cout << endl;
}
}
}
tubo28