結果

問題 No.243 出席番号(2)
ユーザー KumaTachiRenKumaTachiRen
提出日時 2023-10-23 16:30:01
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 28 ms / 2,000 ms
コード長 1,293 bytes
コンパイル時間 11,058 ms
コンパイル使用メモリ 264,264 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-23 16:37:19
合計ジャッジ時間 11,478 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 3 ms
4,348 KB
testcase_04 AC 3 ms
4,348 KB
testcase_05 AC 3 ms
4,348 KB
testcase_06 AC 3 ms
4,348 KB
testcase_07 AC 3 ms
4,348 KB
testcase_08 AC 6 ms
4,348 KB
testcase_09 AC 7 ms
4,348 KB
testcase_10 AC 6 ms
4,348 KB
testcase_11 AC 6 ms
4,348 KB
testcase_12 AC 6 ms
4,348 KB
testcase_13 AC 11 ms
4,348 KB
testcase_14 AC 12 ms
4,348 KB
testcase_15 AC 12 ms
4,348 KB
testcase_16 AC 11 ms
4,348 KB
testcase_17 AC 11 ms
4,348 KB
testcase_18 AC 19 ms
4,348 KB
testcase_19 AC 18 ms
4,348 KB
testcase_20 AC 19 ms
4,348 KB
testcase_21 AC 18 ms
4,348 KB
testcase_22 AC 19 ms
4,348 KB
testcase_23 AC 27 ms
4,348 KB
testcase_24 AC 27 ms
4,348 KB
testcase_25 AC 27 ms
4,348 KB
testcase_26 AC 27 ms
4,348 KB
testcase_27 AC 28 ms
4,348 KB
testcase_28 AC 2 ms
4,348 KB
testcase_29 AC 2 ms
4,348 KB
testcase_30 AC 2 ms
4,348 KB
testcase_31 AC 2 ms
4,348 KB
testcase_32 AC 2 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>

using namespace std;
using namespace atcoder;

struct Fast {
  Fast() {
    std::cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << setprecision(10);
  }
} fast;

#define all(a) (a).begin(), (a).end()
#define contains(a, x) ((a).find(x) != (a).end())
#define rep(i, a, b) for (int i = (a); i < (int)(b); i++)
#define rrep(i, a, b) for (int i = (int)(b)-1; i >= (a); i--)
#define writejoin(s, a) rep(_i, 0, (a).size()) cout << (a)[_i] << (_i + 1 < (int)(a).size() ? s : "\n");
#define YN(b) cout << ((b) ? "YES" : "NO") << "\n";
#define Yn(b) cout << ((b) ? "Yes" : "No") << "\n";
#define yn(b) cout << ((b) ? "yes" : "no") << "\n";

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using mint = modint998244353;
using vm = vector<mint>;

void solve() {
  int n;
  cin >> n;
  vi c(n, 0);
  rep(i, 0, n) {
    int a;
    cin >> a;
    if (a < n) c[a]++;
  }
  vector<modint1000000007> dp(n + 1, 0);
  dp[0] = 1;
  rep(i, 0, n) rrep(j, 0, i + 1) dp[j + 1] += dp[j] * c[i];
  modint1000000007 ans = 0, f = 1;
  for (int i = n; i >= 0; i--, f *= n - i)
    ans += (1 - (i & 1) * 2) * dp[i] * f;
  cout << ans.val() << endl;
}

int main() {
  int t = 1;
  // cin >> t;
  while (t--) solve();
}
0