結果
| 問題 | No.3450 Permutation of Even Scores |
| コンテスト | |
| ユーザー |
👑 potato167
|
| 提出日時 | 2026-01-31 12:59:47 |
| 言語 | C++17 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 392 ms / 2,000 ms |
| コード長 | 1,210 bytes |
| 記録 | |
| コンパイル時間 | 3,772 ms |
| コンパイル使用メモリ | 259,668 KB |
| 実行使用メモリ | 13,684 KB |
| 最終ジャッジ日時 | 2026-02-20 20:53:21 |
| 合計ジャッジ時間 | 19,075 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 46 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
#include <atcoder/convolution>
using mint = atcoder::modint998244353;
#define rep(i, a, b) for (int i = a; i < b; i++)
mint solve(int N, vector<int> A){
vector<mint> fact(N + 1, 1);
rep(i, 1, N + 1) fact[i] = fact[i - 1] * i;
vector<int> p(N);
vector<mint> dp(N);
for (auto x : A) p[x - 1] = 1;
mint ans = 0;
auto f = [&](auto self, int l, int r) -> void {
if (l + 1 == r){
dp[l] += fact[l + 1];
if (p[l]) dp[l] *= -2;
else dp[l] = 0;
ans += dp[l] * fact[N - l];
return;
}
int m = (l + r) / 2;
self(self, l, m);
vector<mint> Y(r - l);
rep(i, 0, r - l) Y[i] = fact[i + 1];
vector<mint> X(m - l);
rep(i, l, m) X[i - l] = dp[i];
auto Z = atcoder::convolution(X, Y);
rep(i, m, r) dp[i] += Z[i - l];
self(self, m, r);
};
f(f, 0, N);
ans /= 2;
ans += fact[N];
return ans;
}
int main(){
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int N, M;
cin >> N >> M;
vector<int> A(M);
rep(i, 0, M) cin >> A[i];
cout << solve(N, A).val() << "\n";
}
potato167