結果

問題 No.389 ロジックパズルの組み合わせ
ユーザー FF256grhy
提出日時 2016-07-08 23:19:46
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 93 ms / 2,000 ms
コード長 596 bytes
コンパイル時間 142 ms
コンパイル使用メモリ 22,784 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-10-13 06:50:28
合計ジャッジ時間 3,384 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 99
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:21:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   21 |         scanf("%d", &m);
      |         ~~~~~^~~~~~~~~~

ソースコード

diff #

#include <stdio.h>

#define MOD 1000000007

int m, h, k, sum;

long long int inv(long long int n) {
	long long int ans = 1;
	int b = MOD - 2;
	
	while(b) {
		if(b % 2) { ans *= n; ans %= MOD; }
		n *= n; n %= MOD;
		b /= 2;
	}
	
	return ans;
}

int main() {
	scanf("%d", &m);
	while( scanf("%d", &h) == 1 ) { sum += h; k++; }
	
	int a = m - sum - (k - 1);
	long long int ans = 1;
	
	if(0 <= a) {
		if(sum != 0) {
			for(int i = 0; i < a; i++) {
				ans *= (k + 1) + i; ans %= MOD;
				ans *= inv(i + 1); ans %= MOD;
			}
		}
		printf("%lld\n", ans);
	} else {
		printf("NA\n");
	}
	
	return 0;
}
0