結果

問題 No.3777 Train Seats
コンテスト
ユーザー toppo57
提出日時 2026-10-29 11:23:01
言語 C++23(gcc16)
(gcc 16.2.0 + boost 1.92.0 + ACL)
コンパイル:
g++-16 -O2 -fplugin=/usr/lib/yukicoder/noavx512-gcc16.so -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 1 ms / 2,000 ms
+ 718µs
コード長 1,952 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 2,345 ms
コンパイル使用メモリ 173,444 KB
実行使用メモリ 9,924 KB
最終ジャッジ日時 2026-10-29 11:23:31
合計ジャッジ時間 4,752 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 50
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <iostream>
#include <vector>
using namespace std;
using ll = long long;


const int mod = 998244353, MAX = 1010;
class mint {
    long long x;
public:
    mint(long long x=0) : x((x%mod+mod)%mod) {}
    mint operator-() const { 
      return mint(-x);
    }
    mint& operator+=(const mint& a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint& a) {
        if ((x += mod-a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const  mint& a) {
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint& a) const {
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint& a) const {
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint& a) const {
        mint res(*this);
        return res*=a;
    }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    
    mint inv() const {
        return pow(mod-2);
    }
    mint& operator/=(const mint& a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint& a) const {
        mint res(*this);
        return res/=a;
    }

    friend ostream& operator<<(ostream& os, const mint& m){
        os << m.x;
        return os;
    }
};

vector<mint> fact(MAX), finv(MAX);

void init_nCr() {
    fact[0] = 1;
    for (int i = 1; i < MAX; i++) {
        fact[i] = fact[i - 1] * i;
    }
    
    finv[MAX - 1] = fact[MAX - 1].inv();
    
    for (int i = MAX - 1; i > 0; i--) {
        finv[i - 1] = finv[i] * i;
    }
}

mint combi(int n, int k) {
    if (n < k || n < 0 || k < 0) return 0;
    return fact[n] * finv[k] * finv[n - k];
}

int main(){
    int N; cin>>N;
    init_nCr();
    mint ans;
    for (int k=(N+2)/3;k<=(N+1)/2;k++){
        ans += combi(k+1, N+1-2*k)*fact[k]*fact[N-k];
    }
    cout << ans << "\n";
}


0