結果

問題 No.1331 Moving Penguin
ユーザー hitonanodehitonanode
提出日時 2021-01-08 22:27:39
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 73 ms / 1,500 ms
コード長 4,041 bytes
コンパイル時間 2,311 ms
コンパイル使用メモリ 205,296 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-11-07 14:49:29
合計ジャッジ時間 5,274 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
5,248 KB
testcase_01 AC 2 ms
5,248 KB
testcase_02 AC 2 ms
5,248 KB
testcase_03 AC 2 ms
5,248 KB
testcase_04 AC 28 ms
5,248 KB
testcase_05 AC 73 ms
5,248 KB
testcase_06 AC 71 ms
5,248 KB
testcase_07 AC 73 ms
5,248 KB
testcase_08 AC 26 ms
5,248 KB
testcase_09 AC 26 ms
5,248 KB
testcase_10 AC 26 ms
5,248 KB
testcase_11 AC 26 ms
5,248 KB
testcase_12 AC 25 ms
5,248 KB
testcase_13 AC 26 ms
5,248 KB
testcase_14 AC 25 ms
5,248 KB
testcase_15 AC 26 ms
5,248 KB
testcase_16 AC 26 ms
5,248 KB
testcase_17 AC 25 ms
5,248 KB
testcase_18 AC 26 ms
5,248 KB
testcase_19 AC 25 ms
5,248 KB
testcase_20 AC 26 ms
5,248 KB
testcase_21 AC 25 ms
5,248 KB
testcase_22 AC 25 ms
5,248 KB
testcase_23 AC 26 ms
5,248 KB
testcase_24 AC 26 ms
5,248 KB
testcase_25 AC 25 ms
5,248 KB
testcase_26 AC 30 ms
5,248 KB
testcase_27 AC 29 ms
5,248 KB
testcase_28 AC 29 ms
5,248 KB
testcase_29 AC 28 ms
5,248 KB
testcase_30 AC 11 ms
5,248 KB
testcase_31 AC 18 ms
5,248 KB
testcase_32 AC 10 ms
5,248 KB
testcase_33 AC 14 ms
5,248 KB
testcase_34 AC 21 ms
5,248 KB
testcase_35 AC 50 ms
5,248 KB
testcase_36 AC 50 ms
5,248 KB
testcase_37 AC 49 ms
5,248 KB
testcase_38 AC 11 ms
5,248 KB
testcase_39 AC 28 ms
5,248 KB
testcase_40 AC 15 ms
5,248 KB
testcase_41 AC 51 ms
5,248 KB
testcase_42 AC 50 ms
5,248 KB
testcase_43 AC 49 ms
5,248 KB
testcase_44 AC 49 ms
5,248 KB
testcase_45 AC 49 ms
5,248 KB
testcase_46 AC 49 ms
5,248 KB
testcase_47 AC 48 ms
5,248 KB
testcase_48 AC 25 ms
5,248 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define REP(i, n) FOR(i,0,n)


template <int mod> struct ModInt {
#if __cplusplus >= 201402L
#define MDCONST constexpr
#else
#define MDCONST
#endif
    using lint = long long;
    int val;
    MDCONST ModInt() : val(0) {}
    MDCONST ModInt &_setval(lint v) { return val = (v >= mod ? v - mod : v), *this; }
    MDCONST ModInt(lint v) { _setval(v % mod + mod); }
    MDCONST explicit operator bool() const { return val != 0; }
    MDCONST ModInt operator+(const ModInt &x) const { return ModInt()._setval((lint)val + x.val); }
    MDCONST ModInt operator-(const ModInt &x) const { return ModInt()._setval((lint)val - x.val + mod); }
    MDCONST ModInt operator*(const ModInt &x) const { return ModInt()._setval((lint)val * x.val % mod); }
    MDCONST ModInt operator/(const ModInt &x) const { return ModInt()._setval((lint)val * x.inv() % mod); }
    MDCONST ModInt operator-() const { return ModInt()._setval(mod - val); }
    MDCONST ModInt &operator+=(const ModInt &x) { return *this = *this + x; }
    MDCONST ModInt &operator-=(const ModInt &x) { return *this = *this - x; }
    MDCONST ModInt &operator*=(const ModInt &x) { return *this = *this * x; }
    MDCONST ModInt &operator/=(const ModInt &x) { return *this = *this / x; }
    friend MDCONST ModInt operator+(lint a, const ModInt &x) { return ModInt()._setval(a % mod + x.val); }
    friend MDCONST ModInt operator-(lint a, const ModInt &x) { return ModInt()._setval(a % mod - x.val + mod); }
    friend MDCONST ModInt operator*(lint a, const ModInt &x) { return ModInt()._setval(a % mod * x.val % mod); }
    friend MDCONST ModInt operator/(lint a, const ModInt &x) { return ModInt()._setval(a % mod * x.inv() % mod); }
    MDCONST bool operator==(const ModInt &x) const { return val == x.val; }
    MDCONST bool operator!=(const ModInt &x) const { return val != x.val; }
    MDCONST bool operator<(const ModInt &x) const { return val < x.val; } // To use std::map<ModInt, T>
    friend std::istream &operator>>(std::istream &is, ModInt &x) {
        lint t;
        return is >> t, x = ModInt(t), is;
    }
    MDCONST friend std::ostream &operator<<(std::ostream &os, const ModInt &x) { return os << x.val; }
    MDCONST ModInt pow(lint n) const {
        lint ans = 1, tmp = this->val;
        while (n) {
            if (n & 1) ans = ans * tmp % mod;
            tmp = tmp * tmp % mod, n /= 2;
        }
        return ans;
    }

    static std::vector<long long> facs, invs;
    MDCONST static void _precalculation(int N) {
        int l0 = facs.size();
        if (N <= l0) return;
        facs.resize(N), invs.resize(N);
        for (int i = l0; i < N; i++) facs[i] = facs[i - 1] * i % mod;
        long long facinv = ModInt(facs.back()).pow(mod - 2).val;
        for (int i = N - 1; i >= l0; i--) {
            invs[i] = facinv * facs[i - 1] % mod;
            facinv = facinv * i % mod;
        }
    }
    MDCONST lint inv() const {
        if (this->val < 1 << 20) {
            while (this->val >= int(facs.size())) _precalculation(facs.size() * 2);
            return invs[this->val];
        } else {
            return this->pow(mod - 2).val;
        }
    }
};
template <int mod> std::vector<long long> ModInt<mod>::facs = {1};
template <int mod> std::vector<long long> ModInt<mod>::invs = {0};
using mint = ModInt<1000000007>;


int main() {
    cin.tie(nullptr), ios::sync_with_stdio(false);
    int N;
    cin >> N;
    constexpr int B = 50;
    vector cnt(B, vector<mint>(B, 0));
    vector<mint> dp(N + 1);
    dp[0] = 1;
    REP(i, N) {
        int ai;
        cin >> ai;
        FOR(b, 1, B) {
            int md = i % b;
            dp[i] += cnt[b][md];
        }
        if (ai != 1) dp[i + 1] += dp[i];

        if (ai >= B) {
            for (int j = i + ai; j < N; j += ai) {
                dp[j] += dp[i];
            }
        } else {
            cnt[ai][i % ai] += dp[i];
        }
    }
    cout << dp[N - 1] << '\n';
}
0