結果
| 問題 | No.389 ロジックパズルの組み合わせ | 
| コンテスト | |
| ユーザー |  kuuso1 | 
| 提出日時 | 2016-07-08 22:37:29 | 
| 言語 | C#(csc) (csc 3.9.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 147 ms / 2,000 ms | 
| コード長 | 2,165 bytes | 
| コンパイル時間 | 2,971 ms | 
| コンパイル使用メモリ | 115,080 KB | 
| 実行使用メモリ | 52,268 KB | 
| 最終ジャッジ日時 | 2024-10-13 04:36:50 | 
| 合計ジャッジ時間 | 7,393 ms | 
| ジャッジサーバーID (参考情報) | judge2 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 99 | 
コンパイルメッセージ
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;
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);
	}
	
}
            
            
            
        