結果

問題 No.243 出席番号(2)
ユーザー 0w10w1
提出日時 2017-03-16 15:45:02
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 66 ms / 2,000 ms
コード長 842 bytes
コンパイル時間 1,225 ms
コンパイル使用メモリ 165,972 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-17 05:13:44
合計ジャッジ時間 3,423 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 4 ms
4,380 KB
testcase_04 AC 4 ms
4,380 KB
testcase_05 AC 4 ms
4,376 KB
testcase_06 AC 4 ms
4,376 KB
testcase_07 AC 4 ms
4,380 KB
testcase_08 AC 12 ms
4,380 KB
testcase_09 AC 12 ms
4,376 KB
testcase_10 AC 13 ms
4,380 KB
testcase_11 AC 13 ms
4,376 KB
testcase_12 AC 12 ms
4,380 KB
testcase_13 AC 24 ms
4,376 KB
testcase_14 AC 25 ms
4,376 KB
testcase_15 AC 24 ms
4,376 KB
testcase_16 AC 23 ms
4,376 KB
testcase_17 AC 24 ms
4,380 KB
testcase_18 AC 42 ms
4,376 KB
testcase_19 AC 42 ms
4,380 KB
testcase_20 AC 41 ms
4,376 KB
testcase_21 AC 41 ms
4,376 KB
testcase_22 AC 41 ms
4,376 KB
testcase_23 AC 65 ms
4,384 KB
testcase_24 AC 63 ms
4,380 KB
testcase_25 AC 66 ms
4,376 KB
testcase_26 AC 64 ms
4,380 KB
testcase_27 AC 64 ms
4,376 KB
testcase_28 AC 1 ms
4,376 KB
testcase_29 AC 1 ms
4,376 KB
testcase_30 AC 1 ms
4,376 KB
testcase_31 AC 1 ms
4,380 KB
testcase_32 AC 2 ms
4,384 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 ]; // i bad pairs -> combination, not considering other

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 ] = 1;
  for( int i = 0; i < N; ++i ){
    for( int j = N - 1; j >= 0; --j ){
      ( dp[ j + 1 ] += 1LL * cnt[ i ] * dp[ j ] % MOD ) %= MOD;
    }
  }
  int ans = 0;
  for( int i = 0; i <= N; ++i ){
    ( ans += 1LL * ( i & 1 ? - 1 : 1 ) * dp[ i ] * fact[ N - i ] % MOD ) %= MOD;
  }
  if( ans < 0 ) ans += MOD;
  cout << ans << endl;
  return 0;
}
0