結果
| 問題 |
No.117 組み合わせの数
|
| ユーザー |
TAISA_
|
| 提出日時 | 2018-06-05 22:26:22 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,154 bytes |
| コンパイル時間 | 1,325 ms |
| コンパイル使用メモリ | 159,588 KB |
| 実行使用メモリ | 34,784 KB |
| 最終ジャッジ日時 | 2024-06-30 10:07:45 |
| 合計ジャッジ時間 | 2,078 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | WA * 1 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:51:20: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
51 | int q;scanf("%d",&q);
| ~~~~~^~~~~~~~~
main.cpp:55:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
55 | scanf("%*c%c(%lld,%lld)",&c,&n,&k);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ソースコード
#include<bits/stdc++.h>
#define all(vec) vec.begin(),vec.end()
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
const ll MOD=1000000007;
const ll INF=1000000010;
const ll LINF=4000000000000000010LL;
const int MAX=310;
const double EPS=1e-9;
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};
ll f[2000010],fi[2000010];
ll mod_pow(ll x,ll n,ll mod){
ll ret=1;
while(n>0){
if(n&1){
ret=ret*x%mod;
}
x=x*x%mod;
n>>=1;
}
return ret;
}
void fact(ll n){
f[0]=1;
for(ll i=1;i<=n;i++){
f[i]=f[i-1]*i%MOD;
}
fi[n]=mod_pow(f[n],MOD-2,MOD);
for(ll i=n-1;i>=0;i--){
fi[i]=fi[i+1]*(i+1)%MOD;
}
}
ll nck(ll n,ll k){
if(n<k)return 0;
if(k==0){
return 1;
}else{
return f[n]*fi[k]%MOD*fi[n-k]%MOD;
}
}
ll hck(ll n,ll k){
if(n<k)return 0;
return f[n+k-1]*fi[k]%MOD*fi[n-1]%MOD;
}
int main(){
int q;scanf("%d",&q);
fact(2000001);
while(q--){
char c;ll n,k;
scanf("%*c%c(%lld,%lld)",&c,&n,&k);
if(c=='C'){
cout<<nck(n,k)%MOD<<endl;
}else if(c=='P'){
cout<<nck(n,k)*f[k]%MOD<<endl;
}else if(c=='H'){
cout<<hck(n,k)%MOD<<endl;
}
}
return 0;
}
TAISA_