結果

問題 No.243 出席番号(2)
ユーザー kriii
提出日時 2018-04-12 01:04:24
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 17 ms / 2,000 ms
コード長 502 bytes
コンパイル時間 192 ms
コンパイル使用メモリ 23,892 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-06-26 21:18:36
合計ジャッジ時間 1,325 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 30
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:10:15: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   10 |         scanf ("%d",&N);
      |         ~~~~~~^~~~~~~~~
main.cpp:12:30: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   12 |                 int x; scanf ("%d",&x);
      |                        ~~~~~~^~~~~~~~~

ソースコード

diff #

#include <stdio.h>

const long long mod = 1000000007;

int main()
{
	int N,C[5050] = {0,};
	long long D[5050] = {1,};
	
	scanf ("%d",&N);
	for (int i=0;i<N;i++){
		int x; scanf ("%d",&x);
		C[x]++;
	}

	for (int k=0,c=0;k<N;k++) if (C[k]){
		for (int i=c;i>=0;i--){
			D[i+1] = (D[i+1] + mod - D[i] * C[k] % mod) % mod;
		}
		c++;
	}

	long long ans = 0, fact = 1;
	for (int i=N;i>=0;i--){
		ans = (ans + D[i] * fact) % mod;
		fact = fact * (N - i + 1) % mod;
	}

	printf ("%lld\n",ans);

	return 0;
}
0