結果

問題 No.1331 Moving Penguin
ユーザー 👑 jupirojupiro
提出日時 2021-01-23 15:20:09
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 160 ms / 1,500 ms
コード長 2,574 bytes
コンパイル時間 1,638 ms
コンパイル使用メモリ 136,120 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-25 05:16:52
合計ジャッジ時間 8,342 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 129 ms
5,376 KB
testcase_05 AC 134 ms
5,376 KB
testcase_06 AC 134 ms
5,376 KB
testcase_07 AC 128 ms
5,376 KB
testcase_08 AC 128 ms
5,376 KB
testcase_09 AC 129 ms
5,376 KB
testcase_10 AC 130 ms
5,376 KB
testcase_11 AC 125 ms
5,376 KB
testcase_12 AC 129 ms
5,376 KB
testcase_13 AC 129 ms
5,376 KB
testcase_14 AC 125 ms
5,376 KB
testcase_15 AC 130 ms
5,376 KB
testcase_16 AC 129 ms
5,376 KB
testcase_17 AC 130 ms
5,376 KB
testcase_18 AC 128 ms
5,376 KB
testcase_19 AC 131 ms
5,376 KB
testcase_20 AC 128 ms
5,376 KB
testcase_21 AC 133 ms
5,376 KB
testcase_22 AC 124 ms
5,376 KB
testcase_23 AC 129 ms
5,376 KB
testcase_24 AC 128 ms
5,376 KB
testcase_25 AC 126 ms
5,376 KB
testcase_26 AC 136 ms
5,376 KB
testcase_27 AC 137 ms
5,376 KB
testcase_28 AC 139 ms
5,376 KB
testcase_29 AC 131 ms
5,376 KB
testcase_30 AC 28 ms
5,376 KB
testcase_31 AC 57 ms
5,376 KB
testcase_32 AC 23 ms
5,376 KB
testcase_33 AC 42 ms
5,376 KB
testcase_34 AC 73 ms
5,376 KB
testcase_35 AC 145 ms
5,376 KB
testcase_36 AC 147 ms
5,376 KB
testcase_37 AC 149 ms
5,376 KB
testcase_38 AC 30 ms
5,376 KB
testcase_39 AC 124 ms
5,376 KB
testcase_40 AC 51 ms
5,376 KB
testcase_41 AC 132 ms
5,376 KB
testcase_42 AC 143 ms
5,376 KB
testcase_43 AC 146 ms
5,376 KB
testcase_44 AC 147 ms
5,376 KB
testcase_45 AC 160 ms
5,376 KB
testcase_46 AC 158 ms
5,376 KB
testcase_47 AC 158 ms
5,376 KB
testcase_48 AC 125 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <algorithm>
#include <cmath>
#include <queue>
#include <bitset>
#include <iomanip>
#include <limits>
#include <chrono>
#include <random>
#include <array>
#include <unordered_map>
#include <functional>
#include <complex>
#include <numeric>
#include <cctype>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <tuple>
#include <assert.h>
#include <deque>
#include <utility>
#include <fstream>

using namespace std;
typedef long long ll;
using ull = unsigned long long;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
//template<typename T> T gcd(T a, T b) { a = abs(a), b = abs(b); while (b > 0) { tie(a, b) = make_pair(b, a % b); }return a; }
//mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

constexpr long long INF = 1LL << 60;
constexpr int inf = 1000000007;
constexpr long long mod = 1000000007LL;
//constexpr long long  mod = 998244353;

struct mint {
	long long x;
	mint(long long x = 0) :x((x% mod + mod) % mod) {}
	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;
	}

	// for prime mod
	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;
	}
};

int main()
{

	std::cin.tie(nullptr);
	std::ios::sync_with_stdio(false);

	int n; cin >> n;
	vector<int> a(n); for (auto& e : a) cin >> e;
	const int b = (int)sqrt(n);
	vector sum(b + 1, vector<mint>(b + 1));
	vector<mint> dp(n);
	dp[0] = 1;
	for (int i = 0; i < n; i++) {
		if (i > 0 and a[i - 1] > 1) {
			dp[i] += dp[i - 1];
		}
		for (int j = 1; j <= b; j++) {
			dp[i] += sum[j][i % j];
		}
		if (a[i] <= b) {
			sum[a[i]][i % a[i]] += dp[i];
		}
		else {
			for (int j = i + a[i]; j < n; j += a[i]) dp[j] += dp[i];
		}
	}
	cout << dp[n - 1].x << "\n";
}
0