結果

問題 No.3777 Train Seats
コンテスト
ユーザー yantaro
提出日時 2026-10-23 22:27:55
言語 C++17
(gcc 15.3.0 + boost 1.92.0 + ACL)
コンパイル:
g++-15 -O2 -lm -std=c++17 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 5 ms / 2,000 ms
+ 444µs
コード長 2,332 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 4,032 ms
コンパイル使用メモリ 279,596 KB
実行使用メモリ 9,916 KB
最終ジャッジ日時 2026-10-23 22:28:15
合計ジャッジ時間 6,974 ms
ジャッジサーバーID
(参考情報)
judge4_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 50
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include<bits/stdc++.h>
#include<atcoder/all>
using namespace std;
using namespace atcoder;
//python3 expander.py main.cpp
//export CPLUS_INCLUDE_PATH="/home/yantaro/kyopro/ac-library-master"

//https://github.com/yantaro-yanchan/kyopro-library/tree/master/library

using ll = long long;
using ull = unsigned long long;
using ld = long double;
using lll = __int128_t;
using ulll = __uint128_t;

//using mint = modint; //mint::set_mod(M);
using mint = modint998244353;
//using mint = modint1000000007;

template<class T> using pq = priority_queue<T>; //大きい順
template<class T> using pq_g = priority_queue<T, vector<T>, greater<T>>; //小さい順

#define vec_unique(v) v.erase(unique(v.begin(), v.end()), v.end()) //重複削除
#define vec_iota(v) iota(v.begin(), v.end(), 0) //0, 1, 2, 3, ..., n - 1にセット
#define concat(a, b) a.insert(a.end(), b.begin(), b.end())
#define debug(x) cerr << #x << " = " << x << endl
#define maxvalue(array) *max_element(array.begin(), array.end())
#define minvalue(array) *min_element(array.begin(), array.end())
#define sumvalue(array) accumulate(array.begin(), array.end(), 0ll)
#define popcount(x) __builtin_popcountll(x)
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//uniform_int_distribution<int> dist(1, N);
//dist(rng);

int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};
//int dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
//int dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};

#define INF 2e18
#define INF2 2e9

void solve() {
    int n;
    cin >> n;
    const int N = n + 10;
    vector<vector<mint>> com(N, vector<mint>(N));
    com[0][0] = 1;
    for(int i = 1; i < N; i++) {
        com[i][0] = 1;
        for(int j = 1; j < N; j++) {
            com[i][j] = com[i - 1][j - 1] + com[i - 1][j];
        }
    }

    vector<mint> fac(N);
    fac[0] = 1;
    for(int i = 1; i < N; i++) {
        fac[i] = fac[i - 1] * i;
    }

    mint ans = 0;
    for(int k = 0; k <= n; k++) {
        if(k + 1 < n - (k + k - 1)) continue;
        if(n - (k + k - 1) < 0) continue;
        ans += com[k + 1][n - (k + k - 1)] * fac[k] * fac[n - k];
    }

    cout << ans.val() << endl;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int t = 1;
    while(t--) {
        solve();
    }
    //cout << fixed << setprecision(15) << << endl;
    return 0;
}
0