結果

問題 No.129 お年玉(2)
ユーザー 37zigen37zigen
提出日時 2016-05-04 11:54:09
言語 Java21
(openjdk 21)
結果
MLE  
実行時間 -
コード長 1,713 bytes
コンパイル時間 2,948 ms
コンパイル使用メモリ 78,824 KB
実行使用メモリ 745,876 KB
最終ジャッジ日時 2024-04-15 11:14:27
合計ジャッジ時間 33,956 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 200 ms
83,816 KB
testcase_01 MLE -
testcase_02 AC 562 ms
53,820 KB
testcase_03 AC 226 ms
54,020 KB
testcase_04 AC 137 ms
41,444 KB
testcase_05 AC 611 ms
454,072 KB
testcase_06 MLE -
testcase_07 MLE -
testcase_08 AC 651 ms
476,528 KB
testcase_09 MLE -
testcase_10 MLE -
testcase_11 AC 624 ms
458,732 KB
testcase_12 MLE -
testcase_13 MLE -
testcase_14 MLE -
testcase_15 AC 672 ms
493,896 KB
testcase_16 MLE -
testcase_17 MLE -
testcase_18 MLE -
testcase_19 MLE -
testcase_20 MLE -
testcase_21 MLE -
testcase_22 AC 655 ms
480,296 KB
testcase_23 MLE -
testcase_24 MLE -
testcase_25 AC 636 ms
460,268 KB
testcase_26 AC 642 ms
470,748 KB
testcase_27 AC 644 ms
457,896 KB
testcase_28 MLE -
testcase_29 AC 136 ms
54,232 KB
testcase_30 AC 137 ms
54,296 KB
testcase_31 AC 138 ms
54,020 KB
testcase_32 AC 140 ms
53,872 KB
testcase_33 AC 154 ms
58,728 KB
testcase_34 AC 143 ms
56,080 KB
testcase_35 AC 153 ms
58,700 KB
testcase_36 AC 156 ms
58,956 KB
testcase_37 AC 156 ms
58,940 KB
testcase_38 AC 252 ms
136,496 KB
testcase_39 AC 296 ms
192,688 KB
testcase_40 AC 615 ms
455,644 KB
testcase_41 AC 442 ms
363,876 KB
testcase_42 AC 260 ms
148,628 KB
testcase_43 AC 259 ms
147,000 KB
testcase_44 MLE -
testcase_45 AC 212 ms
115,392 KB
testcase_46 AC 355 ms
233,996 KB
testcase_47 MLE -
testcase_48 AC 680 ms
499,368 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package yukicoder;
import java.math.BigInteger;
import java.util.Arrays;
import java.util.Scanner;
public class Main{
	public static void main(String[] args)throws Exception{
		new Main().solve();
	}
	final int mod=1_000_000_000;
	void solve(){
		Scanner sc=new Scanner(System.in);
		long n=sc.nextLong();
		int m=sc.nextInt();
		n=n%(m*1000);
		n=n/1000;
//		
//		BigInteger ans=nCk(m,(int)n);
//		//n個の●をm人に配分する。
//		System.out.println(ans);
		long[][] test=Pascal_triangle((int)m);
		System.out.println(test[m][(int)n]);
		
	}
	void tr(Object...o){System.out.println(Arrays.deepToString(o));}
	
	
	long[] fact;
	long[] inv_fact;
	//1~nの数字からk個取る方法の数
	BigInteger nCk(int n,int k){
		if(n<k)return BigInteger.ZERO;
		else{
			return fact_big(n).divide( fact_big(n-k).multiply(fact_big(k))).remainder(BigInteger.valueOf(mod));
		}
	}
	long fact(int n){
		long ans=1;
		for(int i=1;i<=n;i++)ans*=i;
		return ans;
	}
	BigInteger fact_big(int n){
		BigInteger ans=BigInteger.ONE;
		for(int i=1;i<=n;i++)ans=ans.multiply(BigInteger.valueOf(i));
		return ans;
	}
	
	//パスカルの三角形のn行目を求める。
	/**
	 *0行目       1
	 *1行目     1 1
	 *2行目    1 2 1
	 *3行目   1 3 3 1
	 *4行目  1 4 6 4 1
	 * 
	 * O(n^2)
	 * 
	 * n行目は nCn,nCn,nCn,...
	 * 
	 * 返り値は
	 * long[i行目-1][左からi番目]
	 * つまり
	 * nCk=long[n][k]
	 * 
	 */
	long[][] Pascal_triangle(int n){
		long[][] ans=new long[n+1][n+1];
		for(int i=0;i<=n;i++){
			for(int j=0;j<i+1;j++){
				if(j==0)ans[i][j]=1;
				else if(j==i)ans[i][j]=1;
				else{
					ans[i][j]=ans[i-1][j-1]+ans[i-1][j];
					ans[i][j]=ans[i][j]%mod;
				}
			}
		}
		return ans;
	}
}
0