結果

問題 No.389 ロジックパズルの組み合わせ
ユーザー kuuso1kuuso1
提出日時 2016-07-08 22:37:29
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 191 ms / 2,000 ms
コード長 2,165 bytes
コンパイル時間 4,865 ms
コンパイル使用メモリ 107,380 KB
実行使用メモリ 50,596 KB
最終ジャッジ日時 2023-08-03 07:00:35
合計ジャッジ時間 15,389 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 60 ms
21,240 KB
testcase_01 AC 58 ms
21,420 KB
testcase_02 AC 60 ms
21,324 KB
testcase_03 AC 60 ms
21,252 KB
testcase_04 AC 95 ms
46,848 KB
testcase_05 AC 58 ms
21,252 KB
testcase_06 AC 59 ms
21,424 KB
testcase_07 AC 59 ms
21,244 KB
testcase_08 AC 59 ms
21,492 KB
testcase_09 AC 113 ms
49,384 KB
testcase_10 AC 78 ms
25,752 KB
testcase_11 AC 115 ms
49,492 KB
testcase_12 AC 71 ms
20,236 KB
testcase_13 AC 104 ms
28,104 KB
testcase_14 AC 84 ms
27,252 KB
testcase_15 AC 78 ms
26,312 KB
testcase_16 AC 91 ms
36,312 KB
testcase_17 AC 103 ms
42,932 KB
testcase_18 AC 144 ms
40,728 KB
testcase_19 AC 61 ms
23,284 KB
testcase_20 AC 60 ms
23,432 KB
testcase_21 AC 60 ms
21,460 KB
testcase_22 AC 60 ms
23,448 KB
testcase_23 AC 61 ms
23,344 KB
testcase_24 AC 63 ms
21,368 KB
testcase_25 AC 69 ms
23,400 KB
testcase_26 AC 61 ms
21,312 KB
testcase_27 AC 67 ms
21,504 KB
testcase_28 AC 60 ms
21,316 KB
testcase_29 AC 61 ms
21,304 KB
testcase_30 AC 60 ms
21,388 KB
testcase_31 AC 61 ms
23,356 KB
testcase_32 AC 60 ms
21,320 KB
testcase_33 AC 61 ms
23,376 KB
testcase_34 AC 61 ms
21,368 KB
testcase_35 AC 60 ms
21,400 KB
testcase_36 AC 61 ms
21,380 KB
testcase_37 AC 60 ms
23,280 KB
testcase_38 AC 60 ms
21,392 KB
testcase_39 AC 60 ms
23,472 KB
testcase_40 AC 61 ms
21,272 KB
testcase_41 AC 62 ms
23,464 KB
testcase_42 AC 60 ms
21,308 KB
testcase_43 AC 60 ms
21,316 KB
testcase_44 AC 59 ms
21,372 KB
testcase_45 AC 61 ms
21,320 KB
testcase_46 AC 59 ms
21,308 KB
testcase_47 AC 59 ms
21,432 KB
testcase_48 AC 60 ms
21,400 KB
testcase_49 AC 146 ms
39,248 KB
testcase_50 AC 69 ms
22,148 KB
testcase_51 AC 71 ms
22,024 KB
testcase_52 AC 78 ms
25,364 KB
testcase_53 AC 74 ms
22,524 KB
testcase_54 AC 81 ms
23,632 KB
testcase_55 AC 66 ms
23,652 KB
testcase_56 AC 72 ms
24,412 KB
testcase_57 AC 96 ms
29,476 KB
testcase_58 AC 132 ms
37,584 KB
testcase_59 AC 119 ms
35,316 KB
testcase_60 AC 88 ms
27,980 KB
testcase_61 AC 191 ms
50,596 KB
testcase_62 AC 87 ms
26,192 KB
testcase_63 AC 135 ms
38,060 KB
testcase_64 AC 81 ms
23,576 KB
testcase_65 AC 75 ms
22,452 KB
testcase_66 AC 83 ms
21,788 KB
testcase_67 AC 83 ms
21,536 KB
testcase_68 AC 82 ms
25,612 KB
testcase_69 AC 78 ms
35,112 KB
testcase_70 AC 69 ms
29,672 KB
testcase_71 AC 74 ms
31,464 KB
testcase_72 AC 65 ms
25,416 KB
testcase_73 AC 70 ms
28,812 KB
testcase_74 AC 74 ms
29,980 KB
testcase_75 AC 72 ms
32,792 KB
testcase_76 AC 64 ms
24,700 KB
testcase_77 AC 85 ms
44,060 KB
testcase_78 AC 61 ms
20,308 KB
testcase_79 AC 59 ms
23,360 KB
testcase_80 AC 59 ms
21,328 KB
testcase_81 AC 60 ms
21,492 KB
testcase_82 AC 59 ms
21,340 KB
testcase_83 AC 60 ms
21,328 KB
testcase_84 AC 60 ms
21,352 KB
testcase_85 AC 61 ms
25,432 KB
testcase_86 AC 60 ms
21,384 KB
testcase_87 AC 61 ms
23,424 KB
testcase_88 AC 61 ms
21,336 KB
testcase_89 AC 91 ms
26,288 KB
testcase_90 AC 116 ms
36,668 KB
testcase_91 AC 144 ms
38,724 KB
testcase_92 AC 77 ms
22,496 KB
testcase_93 AC 120 ms
35,072 KB
testcase_94 AC 68 ms
23,688 KB
testcase_95 AC 122 ms
37,564 KB
testcase_96 AC 103 ms
28,052 KB
testcase_97 AC 102 ms
29,800 KB
testcase_98 AC 85 ms
25,584 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){
		
		int N = A.Length ;
		if(A.Length == 1 && A[0] == 0){
			Console.WriteLine(1);
			return;
		}
		
		int sum = A.Sum() + (N-1);
		if(sum > M){
			Console.WriteLine("NA");
			return;
		}
		
		int rest = M - sum;
		
		modComb.Init((int)2e6);
		Console.WriteLine(modComb.nCrMod(rest + N,N));
		
		
		
	}
	int M;
	int[] A;
	public Sol(){
		M = ri();
		A = ria();
	}

	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(char sep=' '){return Console.ReadLine().Split(sep);}
	static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
	static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
	static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
}

class modComb{
	public static long mod=(long)(1e9+7);
	public static long nCrMod(long n,long r){
		if(n<r)return 0;
		if(n<0)return 0;
		if(r<0)return 0;
		if(n==0||r==n||r==0)return 1;
		long a=FactorialMod(n);
		long b=InvMod(FactorialMod(r));
		long c=InvMod(FactorialMod(n-r));
		long ans=(((a*b)%mod)*c)%mod;
		return ans;
	}
	
	public static long[] FM;
	public static void Init(int sz){
		FM = new long[sz];
	}
	
	public static long FactorialMod(long n){
		
		if(FM[(int)n]!=0)return FM[(int)n];

		if(n<2)return FM[(int)n]=1;
		long ret=n*FactorialMod(n-1);
		ret%=mod;
		return FM[(int)n]=ret;
	}
	
	public static long PowMod(long n,long k){
		
		if(k==0)return 1;
		if(n==0)return 0;
		long ret=1;
		long x=n;
		while(k>0){
			if((k&1)==1){ret*=x;ret%=mod;}
			
			x*=x;x%=mod;
			k>>=1;
		}
		return ret;
		
	}

	public static long InvMod(long n){
		//(mod-2)乗を返す
		// modが素数の時だけ!!!!
		return PowMod(n,mod-2);
	}
	

}
0