結果
| 問題 | No.3777 Train Seats |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-10-23 22:13:57 |
| 言語 | C++23 (gcc 15.3.0 + boost 1.92.0 + ACL) |
| 結果 |
AC
不安定
|
| 実行時間 | 70 ms / 2,000 ms |
| + 5µs | |
| コード長 | 5,844 bytes |
| 記録 | |
| コンパイル時間 | 2,653 ms |
| コンパイル使用メモリ | 350,436 KB |
| 実行使用メモリ | 58,112 KB |
| 最終ジャッジ日時 | 2026-10-23 22:14:04 |
| 合計ジャッジ時間 | 6,160 ms |
|
ジャッジサーバーID (参考情報) |
judge5_0 / judge2_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 50 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
template <class F> class y_combinator {
F f;
public:
y_combinator(F&& f) : f(std::forward<F>(f)) {}
template <class... Args> auto operator()(Args&&... args) const { return f(*this, std::forward<Args>(args)...); }
};
using ll = long long;
using u32 = unsigned int;
using u64 = unsigned long long;
using vi = vector<int>;
using vl = vector<ll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template <class T> using vc = vector<T>;
template <class T> using vvc = vector<vc<T>>;
template <class T, class U = std::less<T>> using prique = priority_queue<T, vector<T>, U>;
#define overload(a, b, c, d, e, ...) e
#define len(x) (ll)(x.size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep1(n) for (ll _ = 0; _ < ll(n); _++)
#define rep2(i, n) for (ll i = 0; i < ll(n); i++)
#define rep3(i, a, b) for (ll i = ll(a); i < ll(b); i++)
#define rep4(i, a, b, c) for (ll i = ll(a); i < ll(b); i += ll(c))
#define rep(...) overload(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)
#define rrep(i, n) for (ll i = ll(n) - 1; i >= 0; i--)
template <class T = ll, class U> vector<T> cumsum(const vector<U>& a) { vector<T> res(a.size() + 1); rep(i, a.size()) res[i + 1] = res[i] + a[i]; return res; }
template <class T> void dedup(vector<T>& a) { sort(all(a)), a.erase(unique(all(a)), a.end()); }
template <class T, class S> bool chmax(T& a, const S& b) { return a < static_cast<T>(b) ? a = static_cast<T>(b), 1 : 0; }
template <class T, class S> bool chmin(T& a, const S& b) { return a > static_cast<T>(b) ? a = static_cast<T>(b), 1 : 0; }
namespace cppio {
template <typename T> struct is_tuple_like : false_type {};
template <typename... Ts> struct is_tuple_like<tuple<Ts...>> : true_type {};
template <typename T, typename U> struct is_tuple_like<pair<T, U>> : true_type {};
template <typename T, typename = void> struct is_container : false_type {};
template <typename T> struct is_container<T, void_t<decltype(begin(declval<T&>()))>> : bool_constant<!is_same_v<decay_t<T>, string> && !is_same_v<decay_t<T>, char*> && !is_same_v<decay_t<T>, const char*> && !is_array_v<remove_reference_t<T>>> {};
template <typename T> void _in(T& x) { if constexpr (is_tuple_like<T>::value) apply([](auto&... elems) { (_in(elems), ...); }, x); else if constexpr (is_container<T>::value) { for (auto& e : x) _in(e); } else cin >> x; }
template <typename... Ts> void _in_all(Ts&... args) { (_in(args), ...); }
template <typename T> void _out(const T& x) { bool first = true; if constexpr (is_tuple_like<T>::value) { apply([&](const auto&... elems) { ((cout << (first ? "" : " "), _out(elems), first = false), ...); }, x); } else if constexpr (is_container<T>::value) { for (const auto& e : x) { if (!first) cout << ' '; _out(e), first = false; } } else cout << x; }
template <typename... Ts> void _print(const Ts&... args) { bool first = true; ((cout << (first ? "" : " "), _out(args), first = false), ...); }
template <typename... Ts> void _out_no_el(const Ts&... args) { _print(args...); }
template <typename... Ts> void _out_all(const Ts&... args) { _out_no_el(args...), cout << '\n'; }
} // namespace cppio
#define IN(...) cppio::_in_all(__VA_ARGS__)
#define OUT(...) cppio::_out_all(__VA_ARGS__)
#define INT(...) int __VA_ARGS__; IN(__VA_ARGS__)
#define LL(...) ll __VA_ARGS__; IN(__VA_ARGS__)
#define STR(...) string __VA_ARGS__; IN(__VA_ARGS__)
#define CHR(...) char __VA_ARGS__; IN(__VA_ARGS__)
#define DBL(...) double __VA_ARGS__; IN(__VA_ARGS__)
#define VEC(type, name, size) vector<type> name(size); IN(name)
#define VV(type, name, h, w) vector<vector<type>> name(h, vector<type>(w)); IN(name)
#define RETURN(...) do { __VA_ARGS__; return; } while (0)
bool Yes(bool b = true) { return OUT(b ? "Yes" : "No"), b; }
bool No(bool b = true) { return Yes(!b), b; }
bool YES(bool b = true) { return OUT(b ? "YES" : "NO"), b; }
bool NO(bool b = true) { return YES(!b), b; }
#ifdef ONLINE_JUDGE
#define debug(...) (void(0))
#endif
template <class Mint> struct Binom {
private:
std::vector<Mint> _fact, _ifac;
public:
explicit Binom(size_t N = 0) : _fact(1, 1), _ifac(1, 1) { extend(N); }
void extend(size_t N) {
const size_t a = _fact.size();
if (a > N) return;
_fact.resize(N + 1);
for (size_t i = a; i <= N; i++) _fact[i] = _fact[i - 1] * i;
_ifac.resize(N + 1);
_ifac[N] = Mint{1} / _fact[N];
for (size_t i = N; i > a; i--) _ifac[i - 1] = _ifac[i] * i;
}
Mint fact(size_t x) {
extend(x);
return _fact[x];
}
Mint invfact(size_t x) {
extend(x);
return _ifac[x];
}
Mint perm(size_t N, size_t K) {
if (N < K) return Mint{0};
return this->fact(N) * this->invfact(N - K);
}
Mint comb(size_t N, size_t K) {
if (N < K) return Mint{0};
return this->fact(N) * this->invfact(K) * this->invfact(N - K);
}
Mint homo(size_t N, size_t K) {
if (N == 0) return K == 0 ? Mint{1} : Mint{0};
return comb(N - 1 + K, K);
}
};
#include <atcoder/modint>
using mint = atcoder::modint998244353;
Binom<mint> C;
void run_case() {
INT(N);
vector dp(N + 1, vector(N + 1, vector<mint>(3)));
dp[0][0][1] = 1;
rep(i, N) {
rep(j, N + 1) {
rep(k, 2) {
dp[i + 1][j][k + 1] += dp[i][j][k];
}
if (j + 1 <= N) rep(k, 1, 3) dp[i + 1][j + 1][0] += dp[i][j][k];
}
}
mint ans = 0;
rep(i, N + 1) {
mint t = dp[N][i][0] + dp[N][i][1];
ans += C.fact(i) * C.fact(N - i) * t;
}
OUT(ans.val());
}
int main() {
std::ios_base::sync_with_stdio(false);
std::cin.tie(nullptr);
std::fixed(std::cout).precision(16);
int t = 1;
while (t--) run_case();
}