結果

問題 No.2792 Security Cameras on Young Diagram
ユーザー shinchanshinchan
提出日時 2024-06-21 21:45:25
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 197 ms / 2,000 ms
コード長 4,122 bytes
コンパイル時間 2,585 ms
コンパイル使用メモリ 207,560 KB
実行使用メモリ 75,008 KB
最終ジャッジ日時 2024-06-24 18:44:45
合計ジャッジ時間 7,597 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 172 ms
73,532 KB
testcase_01 AC 186 ms
73,628 KB
testcase_02 AC 183 ms
73,596 KB
testcase_03 AC 190 ms
73,428 KB
testcase_04 AC 185 ms
73,600 KB
testcase_05 AC 180 ms
73,600 KB
testcase_06 AC 187 ms
73,564 KB
testcase_07 AC 182 ms
73,628 KB
testcase_08 AC 180 ms
73,516 KB
testcase_09 AC 177 ms
73,524 KB
testcase_10 AC 181 ms
73,700 KB
testcase_11 AC 187 ms
73,556 KB
testcase_12 AC 189 ms
74,240 KB
testcase_13 AC 195 ms
73,844 KB
testcase_14 AC 186 ms
74,240 KB
testcase_15 AC 176 ms
73,848 KB
testcase_16 AC 193 ms
74,216 KB
testcase_17 AC 186 ms
74,484 KB
testcase_18 AC 185 ms
73,648 KB
testcase_19 AC 182 ms
73,728 KB
testcase_20 AC 185 ms
73,816 KB
testcase_21 AC 182 ms
73,536 KB
testcase_22 AC 176 ms
73,580 KB
testcase_23 AC 197 ms
75,008 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define all(v) (v).begin(),(v).end()
#define pb(a) push_back(a)
#define rep(i, n) for(int i=0;i<n;i++)
#define foa(e, v) for(auto& e : v)
using ll = long long;
const ll MOD7 = 1000000007, MOD998 = 998244353, INF = (1LL << 60);
#define dout(a) cout<<fixed<<setprecision(10)<<a<<endl;

template<int MOD> struct Modint {
    long long val;
    constexpr Modint(long long v = 0) noexcept : val(v % MOD) { if (val < 0) val += MOD; }
    constexpr int mod() const { return MOD; }
    constexpr long long value() const { return val; }
    constexpr Modint operator - () const noexcept { return val ? MOD - val : 0; }
    constexpr Modint operator + (const Modint& r) const noexcept { return Modint(*this) += r; }
    constexpr Modint operator - (const Modint& r) const noexcept { return Modint(*this) -= r; }
    constexpr Modint operator * (const Modint& r) const noexcept { return Modint(*this) *= r; }
    constexpr Modint operator / (const Modint& r) const noexcept { return Modint(*this) /= r; }
    constexpr Modint& operator += (const Modint& r) noexcept {
        val += r.val;
        if (val >= MOD) val -= MOD;
        return *this;
    }
    constexpr Modint& operator -= (const Modint& r) noexcept {
        val -= r.val;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr Modint& operator *= (const Modint& r) noexcept {
        val = val * r.val % MOD;
        return *this;
    }
    constexpr Modint& operator /= (const Modint& r) noexcept {
        long long a = r.val, b = MOD, u = 1, v = 0;
        while (b) {
            long long t = a / b;
            a -= t * b, swap(a, b);
            u -= t * v, swap(u, v);
        }
        val = val * u % MOD;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr bool operator == (const Modint& r) const noexcept { return this->val == r.val; }
    constexpr bool operator != (const Modint& r) const noexcept { return this->val != r.val; }
    friend constexpr istream& operator >> (istream& is, Modint<MOD>& x) noexcept {
        is >> x.val;
        x.val %= MOD;
        if (x.val < 0) x.val += MOD;
        return is;
    }
    friend constexpr ostream& operator << (ostream& os, const Modint<MOD>& x) noexcept {
        return os << x.val;
    }
    constexpr Modint<MOD> pow(long long n) noexcept {
        if (n == 0) return 1;
        if (n < 0) return this->pow(-n).inv();
        Modint<MOD> ret = pow(n >> 1);
        ret *= ret;
        if (n & 1) ret *= *this;
        return ret;
    }
    constexpr Modint<MOD> inv() const noexcept {
        long long a = this->val, b = MOD, u = 1, v = 0;
        while (b) {
            long long t = a / b;
            a -= t * b, swap(a, b);
            u -= t * v, swap(u, v);
        }
        return Modint<MOD>(u);
    }
};

const int MOD = MOD998;
using mint = Modint<MOD>;

struct Combination {
    long long C_MOD;
    vector<long long> fac, finv, inv;
    Combination(long long n, long long mod) noexcept : C_MOD(mod) {
        n = max(n, 2LL);
        fac.resize(n, 0);
        finv.resize(n, 0);
        inv.resize(n, 0);
        fac[0] = fac[1] = finv[0] = finv[1] = inv[1] = 1;
        for(int i = 2; i < n; i ++) {
            fac[i] = fac[i - 1] * i % mod;
            inv[i] = mod - inv[mod % i] * (mod / i) % mod;
            finv[i] = finv[i - 1] * inv[i] % mod;
        }
    }
    long long com(long long n, long long k) {
        if(n < k || n < 0 || k < 0) return 0;
        return fac[n] * (finv[k] * finv[n - k] % C_MOD) % C_MOD;
    }
};
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    Combination C(3000000, MOD998);
    ll n;
    cin >> n;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];
    mint ans = 0;
    a.pb(0);
    for(ll i = 0; i < n; i ++) {
        if(a[i] > a[i + 1]) {
            ans += mint(C.com(i + a[i] - 1, i) * 2);
            for(ll j = a[i] - 1; j > a[i + 1]; j --) {
                ans += mint(C.com(i + j - 1, i));
            }
        } else {
            ans += mint(C.com(i + a[i] - 1, i));
        }
    }
    cout << ans << endl;
    return 0;
}
0