結果

問題 No.1331 Moving Penguin
ユーザー definedefine
提出日時 2021-01-08 23:00:50
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 33 ms / 1,500 ms
コード長 3,132 bytes
コンパイル時間 1,896 ms
コンパイル使用メモリ 199,836 KB
実行使用メモリ 4,996 KB
最終ジャッジ日時 2023-08-07 11:03:11
合計ジャッジ時間 4,323 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
4,472 KB
testcase_01 AC 2 ms
4,476 KB
testcase_02 AC 2 ms
4,404 KB
testcase_03 AC 3 ms
4,540 KB
testcase_04 AC 11 ms
4,844 KB
testcase_05 AC 26 ms
4,792 KB
testcase_06 AC 26 ms
4,808 KB
testcase_07 AC 26 ms
4,804 KB
testcase_08 AC 9 ms
4,860 KB
testcase_09 AC 9 ms
4,928 KB
testcase_10 AC 9 ms
4,904 KB
testcase_11 AC 10 ms
4,848 KB
testcase_12 AC 10 ms
4,808 KB
testcase_13 AC 10 ms
4,980 KB
testcase_14 AC 11 ms
4,996 KB
testcase_15 AC 11 ms
4,804 KB
testcase_16 AC 11 ms
4,800 KB
testcase_17 AC 8 ms
4,808 KB
testcase_18 AC 9 ms
4,924 KB
testcase_19 AC 9 ms
4,796 KB
testcase_20 AC 9 ms
4,800 KB
testcase_21 AC 9 ms
4,908 KB
testcase_22 AC 9 ms
4,976 KB
testcase_23 AC 11 ms
4,892 KB
testcase_24 AC 10 ms
4,868 KB
testcase_25 AC 10 ms
4,804 KB
testcase_26 AC 13 ms
4,804 KB
testcase_27 AC 13 ms
4,804 KB
testcase_28 AC 13 ms
4,800 KB
testcase_29 AC 11 ms
4,804 KB
testcase_30 AC 5 ms
4,532 KB
testcase_31 AC 9 ms
4,628 KB
testcase_32 AC 5 ms
4,696 KB
testcase_33 AC 7 ms
4,756 KB
testcase_34 AC 9 ms
4,780 KB
testcase_35 AC 32 ms
4,872 KB
testcase_36 AC 32 ms
4,864 KB
testcase_37 AC 33 ms
4,808 KB
testcase_38 AC 6 ms
4,540 KB
testcase_39 AC 13 ms
4,896 KB
testcase_40 AC 8 ms
4,804 KB
testcase_41 AC 30 ms
4,928 KB
testcase_42 AC 14 ms
4,804 KB
testcase_43 AC 14 ms
4,808 KB
testcase_44 AC 15 ms
4,976 KB
testcase_45 AC 13 ms
4,836 KB
testcase_46 AC 12 ms
4,800 KB
testcase_47 AC 12 ms
4,808 KB
testcase_48 AC 8 ms
4,968 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#line 2 "/home/defineprogram/Desktop/Library/template/template.cpp"
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (int i = 0; i < n; i++)
#define REP(i, n) for (int i = 1; i < n; i++)
#define rev(i, n) for (int i = n - 1; i >= 0; i--)
#define all(v) v.begin(), v.end()
#define P pair<ll, ll>
#define len(s) (ll) s.size()

template <class T, class U>
inline bool chmin(T &a, U b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T, class U>
inline bool chmax(T &a, U b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
constexpr ll inf = 3e18;
#line 3 "/home/defineprogram/Desktop/Library/math/extgcd.cpp"

ll extGCD(ll a, ll b, ll &x, ll &y) {
    if (!b) {
        x = 1;
        y = 0;
        return a;
    }
    ll d = extGCD(b, a % b, y, x);
    y -= a / b * x;
    return d;
}

ll modinv(ll a, ll m) {
    ll x, y;
    extGCD(a, m, x, y);
    return (x % m + m) % m;
}
#line 4 "/home/defineprogram/Desktop/Library/math/modint.cpp"

template <int MOD>
struct mint {
    int32_t n;
    mint() : n(0) {}
    mint(ll x) : n(x >= 0 ? x % MOD : (MOD - (-x) % MOD) % MOD) {}

    mint &operator+=(const mint &p) {
        if ((n += p.n) >= MOD) n -= MOD;
        return *this;
    }
    mint &operator-=(const mint &p) {
        if ((n += MOD - p.n) >= MOD) n -= MOD;
        return *this;
    }
    mint &operator*=(const mint &p) {
        n = 1ll * n * p.n % MOD;
        return *this;
    }
    mint &operator/=(const mint &p) {
        *this *= p.inverse();
        return *this;
    }
    mint operator-() const { return mint(-n); }
    mint operator+(const mint &p) const { return mint(*this) += p; }
    mint operator-(const mint &p) const { return mint(*this) -= p; }
    mint operator*(const mint &p) const { return mint(*this) *= p; }
    mint operator/(const mint &p) const { return mint(*this) /= p; }
    bool operator==(const mint &p) const { return n == p.n; }
    bool operator!=(const mint &p) const { return n != p.n; }

    friend ostream &operator<<(ostream &os, const mint &p) {
        return os << p.n;
    }
    friend istream &operator>>(istream &is, mint &p) {
        int x;
        is >> x;
        p = mint(x);
        return is;
    }
    mint pow(int64_t x) const {
        mint res(1), mul(n);
        while (x > 0) {
            if (x & 1) res *= mul;
            mul *= mul;
            x >>= 1;
        }
        return res;
    }
    mint inverse() const {
        return mint(modinv(n,MOD));
    }
};
/*
@brief mod int
@docs docs/modint.md
*/
#line 3 "main.cpp"
constexpr int mod=1e9+7;
using modint=mint<mod>;

int N,A[1<<17];
modint dp[1<<17],imos[1<<17];
int main() {
    cin.tie(0); ios::sync_with_stdio(false);
    cin>>N;
    rep(i,N)cin>>A[i];
    dp[0]=1;
    rep(i,N){
        for(int j=i+A[i];j<N;j+=A[i]){
            if(A[j]==A[i]){
                dp[j]+=dp[i]+imos[i];
                imos[j]+=dp[i]+imos[i];
                break;
            }
            dp[j]+=dp[i]+imos[i];
        }
        if(A[i]!=1)dp[i+1]+=dp[i];
    }
    cout<<dp[N-1]<<"\n";
}
0