結果
| 問題 | No.3450 Permutation of Even Scores |
| コンテスト | |
| ユーザー |
👑 potato167
|
| 提出日時 | 2025-07-20 06:50:54 |
| 言語 | C++17 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 383 ms / 2,000 ms |
| コード長 | 1,371 bytes |
| 記録 | |
| コンパイル時間 | 3,619 ms |
| コンパイル使用メモリ | 259,644 KB |
| 実行使用メモリ | 13,812 KB |
| 最終ジャッジ日時 | 2026-02-20 20:50:34 |
| 合計ジャッジ時間 | 18,738 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| 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;
if (N <= 2){
if ((int)A.size() & 1) return 0;
return fact[N];
}
vector<int> p(N);
int c = 1;
for (auto x : A){
p[x - 1] = 1;
if (x == 1 || x == N) c *= -1;
}
vector<mint> dp(N);
p[0] = 1, p[N - 1] = 1;
dp[0] = 1;
auto f = [&](auto self, int l, int r) -> void {
if (l + 1 == r){
if (p[l]) dp[l] *= -2;
else dp[l] = 0;
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);
mint ans = (fact[N] + dp[N - 1] / 4) / 2;
if (c == -1) ans = fact[N] - ans;
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