結果

問題 No.2137 Stairs of Permutation
ユーザー sapphire__15sapphire__15
提出日時 2022-11-26 01:36:17
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 731 ms / 2,000 ms
コード長 4,522 bytes
コンパイル時間 2,100 ms
コンパイル使用メモリ 199,676 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-10 05:52:44
合計ジャッジ時間 11,197 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 1 ms
6,940 KB
testcase_02 AC 124 ms
6,944 KB
testcase_03 AC 512 ms
6,940 KB
testcase_04 AC 426 ms
6,940 KB
testcase_05 AC 328 ms
6,944 KB
testcase_06 AC 697 ms
6,940 KB
testcase_07 AC 719 ms
6,944 KB
testcase_08 AC 78 ms
6,944 KB
testcase_09 AC 37 ms
6,940 KB
testcase_10 AC 106 ms
6,940 KB
testcase_11 AC 653 ms
6,944 KB
testcase_12 AC 246 ms
6,940 KB
testcase_13 AC 350 ms
6,944 KB
testcase_14 AC 524 ms
6,944 KB
testcase_15 AC 723 ms
6,940 KB
testcase_16 AC 237 ms
6,940 KB
testcase_17 AC 209 ms
6,944 KB
testcase_18 AC 322 ms
6,940 KB
testcase_19 AC 268 ms
6,940 KB
testcase_20 AC 178 ms
6,940 KB
testcase_21 AC 704 ms
6,940 KB
testcase_22 AC 2 ms
6,940 KB
testcase_23 AC 731 ms
6,940 KB
testcase_24 AC 2 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define per(i, n) for (int i = (n)NOP; 0 <= i; i--)
#define rep2(i, l, r) for (int i = (l); i < int(r); i++)
#define per2(i, l, r) for (int i = (r)NOP; int(l) <= i; i--)
#define MM << " " <<
#define pb push_back
#define eb emplace_back
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define sz(x) (int)x.size()

template<typename T>
void print(const vector<T> &v, T x = 0) {
    int n = v.size();
    for (int i = 0; i < n; i++) cout << v[i] + x << (i == n - 1 ? '\n' : ' ');
    if (v.empty()) cout << '\n';
}

template<class T>
using MaxHeap = priority_queue<T>;
template<class T>
using MinHeap = priority_queue<T, vector<T>, greater<T>>;

using ll  = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

template<typename T>
bool chmax(T &x, const T &y) {
    return (x < y) ? (x = y, true) : false;
}

template<typename T>
bool chmin(T &x, const T &y) {
    return (x > y) ? (x = y, true) : false;
}

struct modint {
    long long num;
    const static long long p = 998244353;
    constexpr static long long pow(long long n, long long k) {//n^k(mod p)
        n %= p;
        long long ret = 1;
        while(k) {
            if(k&1) ret = ret * n % p;
            n = n * n % p;
            k >>= 1;
        }
        return ret;
    }
    // a*A + b*B = 1
    constexpr static void euclid(long long &a, long long &b) { // a>=b A*b+B*(a-a/b*b)=1
        if (a == 1) {
            a = 1;
        }
        else {
            long long A = b, B = a % b;
            euclid(A, B);
            b = (A - (p + a / b) % p * B % p + p) % p;
            a = B;
        }
    }
    constexpr static long long rev(const long long n) {// n*x-p*y=1
        //long long q = p;
        //euclid(p, n, p);
        //return n % q;
        return pow(n,p-2);
    }
    constexpr modint() : num(0) {}
    constexpr modint(long long x) : num(x%p < 0 ? x%p+p : x%p) {}
    constexpr modint inv() const {return rev(num);}
    modint operator-() const {return modint(p-num);}
    modint& operator+=(const modint &other){
        num = (num + other.num) % p;
        return *this;
    }
    modint& operator-=(const modint &other){
        num = (num - other.num + p) % p;
        return *this;
    }
    modint& operator*=(const modint &other){
        num = (num * other.num) % p;
        if(num < 0) num += p;
        return *this;
    }
    modint& operator/=(const modint &other){
        (*this) *= other.inv();
        return *this;
    }
    modint& operator+=(const long long &other){
        num = (num + other) % p;
        return *this;
    }
    modint& operator-=(const long long &other){
        num = (num - other + p) % p;
        return *this;
    }
    modint& operator*=(const long long &other){
        num = (num * (other % p)) % p;
        return *this;
    }
    modint& operator/=(const long long &other){
        (*this) *= rev(other);
        return *this;
    }
    modint& operator++(){return *this += 1;}
    modint& operator--(){return *this -= 1;}
    modint& operator=(const long long &other){return (*this) = modint(other);}
    modint operator+(const modint &other) const{return modint(*this) += other;}
    modint operator-(const modint &other) const{return modint(*this) -= other;}
    modint operator*(const modint &other) const{return modint(*this) *= other;}
    modint operator/(const modint &other) const{return modint(*this) /= other;}
    modint operator+(const long long &other) const{return modint(*this) += other;}
    modint operator-(const long long &other) const{return modint(*this) -= other;}
    modint operator*(const long long &other) const{return modint(*this) *= other;}
    modint operator/(const long long &other) const{return modint(*this) /= other;}
    bool operator==(const modint &other) const{return num == other.num;}
};
std::istream& operator>>(std::istream &is, modint x) {
    is >> x.num;
    return is;
}
std::ostream& operator<<(std::ostream &os, const modint &x){
    os << x.num;
    return os;
}

// ((n-1) + e^t)
int main() {
    ll n; cin >> n;
    vector<modint> dp(4);
    vector<modint> poly(4);
    poly[0] += 1;
    poly[1] += modint(1).inv();
    poly[2] += modint(2).inv();
    poly[3] += modint(6).inv();
    dp[0] += 1;
    rep(i,n) {
        vector<modint> tmp(4), now = poly;
        now[0] += i;
        rep(j,4) rep(k,j+1) tmp[j] += dp[k] * now[j - k];
        swap(dp, tmp);
    }
    cout << dp.back() * 6 << endl;
}
0