結果

問題 No.269 見栄っ張りの募金活動
ユーザー 37zigen37zigen
提出日時 2016-03-26 16:11:40
言語 Java21
(openjdk 21)
結果
AC  
実行時間 155 ms / 5,000 ms
コード長 840 bytes
コンパイル時間 2,743 ms
コンパイル使用メモリ 72,084 KB
実行使用メモリ 56,272 KB
最終ジャッジ日時 2023-09-23 01:16:24
合計ジャッジ時間 7,311 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 123 ms
55,396 KB
testcase_01 AC 125 ms
55,728 KB
testcase_02 AC 124 ms
55,768 KB
testcase_03 AC 129 ms
55,312 KB
testcase_04 AC 142 ms
55,980 KB
testcase_05 AC 126 ms
55,812 KB
testcase_06 AC 122 ms
55,800 KB
testcase_07 AC 155 ms
55,532 KB
testcase_08 AC 125 ms
55,756 KB
testcase_09 AC 124 ms
55,624 KB
testcase_10 AC 123 ms
55,844 KB
testcase_11 AC 131 ms
55,796 KB
testcase_12 AC 124 ms
56,000 KB
testcase_13 AC 131 ms
56,272 KB
testcase_14 AC 124 ms
55,832 KB
testcase_15 AC 134 ms
56,056 KB
testcase_16 AC 124 ms
55,904 KB
testcase_17 AC 124 ms
56,052 KB
testcase_18 AC 136 ms
55,524 KB
testcase_19 AC 135 ms
55,808 KB
testcase_20 AC 124 ms
56,128 KB
testcase_21 AC 125 ms
55,352 KB
testcase_22 AC 133 ms
55,804 KB
testcase_23 AC 123 ms
55,708 KB
testcase_24 AC 127 ms
56,212 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package yukicoder269;
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();//n人寄付
		int s=sc.nextInt();//ちょうどs円寄付しなければならない
		int k=sc.nextInt();//一つ前の生徒よりk円高い募金を
		//可能な寄付の仕方の組み合わせの数を10^9+1で割ったあまりを求める。
		sc.close();
		int mod=1000000007;
		s-=k*n*(n-1)*1/2;
		if(s<0){
			System.out.println(0);
			return;
		}else{
			int dp[]=new int[s+1];//dp[x]x円寄付する組み合わせ数
			dp[0]=1;
			for(int i=1;i<=n;i++){//i人目の寄付について
				for(int j=0;j+n-i+1<=s;j++){
					dp[j+(n-i+1)]+=dp[j];
					while(dp[j+(n-i+1)]>mod){
						dp[j+(n-i+1)]-=mod;
					}
				}
			}
			System.out.println(dp[s]);
		}
	}
}
0