結果

問題 No.243 出席番号(2)
ユーザー 0w10w1
提出日時 2017-03-16 15:48:52
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
MLE  
実行時間 -
コード長 872 bytes
コンパイル時間 1,425 ms
コンパイル使用メモリ 166,308 KB
実行使用メモリ 70,576 KB
最終ジャッジ日時 2023-09-17 05:13:50
合計ジャッジ時間 4,106 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 10 ms
9,564 KB
testcase_04 AC 11 ms
9,368 KB
testcase_05 AC 11 ms
9,372 KB
testcase_06 AC 10 ms
9,364 KB
testcase_07 AC 10 ms
9,528 KB
testcase_08 AC 28 ms
19,376 KB
testcase_09 AC 27 ms
19,192 KB
testcase_10 AC 27 ms
19,232 KB
testcase_11 AC 27 ms
19,300 KB
testcase_12 AC 27 ms
19,428 KB
testcase_13 AC 52 ms
33,000 KB
testcase_14 AC 53 ms
33,104 KB
testcase_15 AC 53 ms
33,012 KB
testcase_16 AC 53 ms
33,152 KB
testcase_17 AC 52 ms
33,024 KB
testcase_18 AC 85 ms
50,640 KB
testcase_19 AC 85 ms
50,672 KB
testcase_20 AC 84 ms
50,700 KB
testcase_21 AC 86 ms
50,848 KB
testcase_22 AC 84 ms
50,760 KB
testcase_23 MLE -
testcase_24 MLE -
testcase_25 MLE -
testcase_26 MLE -
testcase_27 MLE -
testcase_28 AC 1 ms
4,376 KB
testcase_29 AC 2 ms
4,376 KB
testcase_30 AC 1 ms
4,380 KB
testcase_31 AC 2 ms
4,380 KB
testcase_32 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

const int MOD = ( int ) 1e9 + 7;
const int MAXN = 5000;

int fact[ MAXN + 1 ];
int N;
int A[ MAXN ];
int cnt[ MAXN ];
int dp[ MAXN + 1 ][ MAXN + 1 ];

signed main(){
  {
    for( int i = fact[ 0 ] = 1; i <= MAXN; ++i ){
      fact[ i ] = 1LL * fact[ i - 1 ] * i % MOD;
    }
  }
  ios::sync_with_stdio( 0 );
  cin >> N;
  for( int i = 0; i < N; ++i ){
    cin >> A[ i ];
    ++cnt[ A[ i ] ];
  }
  dp[ 0 ][ 0 ] = 1;
  for( int i = 0; i < N; ++i ){
    for( int j = 0; j <= i; ++j ){
      ( dp[ i + 1 ][ j ] += dp[ i ][ j ] ) %= MOD;
      ( dp[ i + 1 ][ j + 1 ] += 1LL * cnt[ i ] * dp[ i ][ j ] % MOD ) %= MOD;
    }
  }
  int ans = 0;
  for( int i = 0; i <= N; ++i ){
    ( ans += 1LL * ( i & 1 ? - 1 : 1 ) * dp[ N ][ i ] * fact[ N - i ] % MOD ) %= MOD;
  }
  if( ans < 0 ) ans += MOD;
  cout << ans << endl;
  return 0;
}
0