結果
問題 | No.243 出席番号(2) |
ユーザー |
![]() |
提出日時 | 2015-12-26 01:01:19 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 257 ms / 2,000 ms |
コード長 | 592 bytes |
コンパイル時間 | 208 ms |
コンパイル使用メモリ | 34,512 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-09-19 00:07:40 |
合計ジャッジ時間 | 4,341 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 30 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:14:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 14 | scanf("%d",&a); | ~~~~~^~~~~~~~~ main.cpp:16:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 16 | scanf("%d",b+i); | ~~~~~^~~~~~~~~~
ソースコード
#include<stdio.h>#include<algorithm>using namespace std;long long mod=1000000007;int b[5100];int c[5100];long long dp[5100];long long fact[5100];int main(){int M=5100;fact[0]=1;for(int i=1;i<M;i++)fact[i]=fact[i-1]*i%mod;int a;scanf("%d",&a);for(int i=0;i<a;i++){scanf("%d",b+i);c[b[i]]++;}dp[0]=1;for(int i=0;i<a;i++){for(int j=a-1;j>=0;j--){dp[j+1]=(dp[j+1]+dp[j]*c[i])%mod;}}long long ret=0;for(int i=0;i<=a;i++){if(i%2){ret=(ret+mod-dp[i]*fact[a-i]%mod)%mod;}else{ret=(ret+dp[i]*fact[a-i])%mod;}}printf("%lld\n",ret);}