結果
| 問題 |
No.117 組み合わせの数
|
| ユーザー |
kuuso1
|
| 提出日時 | 2015-01-05 00:07:12 |
| 言語 | C#(csc) (csc 3.9.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,327 bytes |
| コンパイル時間 | 870 ms |
| コンパイル使用メモリ | 113,964 KB |
| 実行使用メモリ | 59,080 KB |
| 最終ジャッジ日時 | 2024-06-13 02:31:02 |
| 合計ジャッジ時間 | 2,682 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | WA * 1 |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
using System;
using System.Collections;
using System.Collections.Generic;
class TEST{
static void Main(){
Sol mySol =new Sol();
mySol.Solve();
}
}
class Sol{
public void Solve(){
for(int t=0;t<T;t++){
char typ=In[t][0];
var d=Array.ConvertAll(In[t].Substring(2,In[t].Length-3).Split(','),e=>long.Parse(e));
long N=d[0];long K=d[1];
if(typ=='C'){
Console.WriteLine(cal_nCrMod(N,K));
continue;
}
if(typ=='P'){
long x=cal_nCrMod(N,K)*FactorialMod(K);
Console.WriteLine(x%mod);
continue;
}
if(typ=='H'){
Console.WriteLine(cal_nCrMod(N+K-1,K));
continue;
}
}
}
long Max;
long mod;
String[] In;
int T;
public Sol(){
mod=(long)(1e9+7);
Max=(int)3e6;
FM=new long[Max];
FM[0]=1;
for(int i=1;i<Max;i++){
FM[i]=(FM[i-1]*i)%mod;
}
T=ri();
In=new String[T];
for(int i=0;i<T;i++)In[i]=rs();
}
long cal_nCrMod(long n,long r){
if(n==0||r==n||r==0)return 1;
if(n<r)return 0;
if(n<0)return 0;
if(r<0)return 0;
long a=FactorialMod(n);
long b=InvMod(FactorialMod(r));
long c=InvMod(FactorialMod(n-r));
long ans=(((a*b)%mod)*c)%mod;
return ans;
}
long[] FM;
long FactorialMod(long n){
/*
if(n<2)return 1;
long ret=n*FactorialMod(n-1);
ret%=mod;
return ret;
*/
return FM[(int)n];
}
long InvMod(long n){
if(n>mod)n%=mod;
if(n==0)return 0;
//(mod-2)乗を返す
List<long> L=new List<long>();
int idx=0;
while(mod>(0x1<<idx))idx++;
long[] Table=new long[idx];
Table[0]=n;
for(int i=1;i<idx;i++){
Table[i]=Table[i-1]*Table[i-1];
Table[i]%=mod;
}
long ret=1;
for(int i=0;i<idx;i++){
if(( (mod-2)&(0x1<<i)) >0){
ret*=Table[i];
ret%=mod;
}
}
return ret;
}
static String rs(){return Console.ReadLine();}
static int ri(){return int.Parse(Console.ReadLine());}
static long rl(){return long.Parse(Console.ReadLine());}
static double rd(){return double.Parse(Console.ReadLine());}
static String[] rsa(){return Console.ReadLine().Split(' ');}
static int[] ria(){return Array.ConvertAll(Console.ReadLine().Split(' '),e=>int.Parse(e));}
static long[] rla(){return Array.ConvertAll(Console.ReadLine().Split(' '),e=>long.Parse(e));}
static double[] rda(){return Array.ConvertAll(Console.ReadLine().Split(' '),e=>double.Parse(e));}
}
kuuso1