結果

問題 No.1331 Moving Penguin
コンテスト
ユーザー TonalidadeHidrica
提出日時 2021-01-08 21:59:45
言語 C++17
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=c++17 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 104 ms / 1,500 ms
コード長 1,126 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,349 ms
コンパイル使用メモリ 209,532 KB
実行使用メモリ 6,400 KB
最終ジャッジ日時 2026-06-16 11:36:30
合計ジャッジ時間 6,980 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 49
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) FOR(i, 0, (n))
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define LAR(a, b) ((a)=max((a),(b)))
#define SML(a, b) ((a)=min((a),(b)))
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vl = vector<ll>;
using pii = pair<int, int>;
using vpii = vector<pair<int, int>>;
template<typename T>
using pque = priority_queue<T, vector<T>, greater<T>>;
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define ALL(a) (a).begin(), (a).end()
#ifdef LOCAL_DEBUG
#define DEBUG(...) printf(__VA_ARGS__)
#else
#define DEBUG(...)
#endif

#define MOD 1'000'000'007LL
#define N 112345
#define M 316

int a[N];
ll b[M][M];
ll c[N] = {};

int main(){
	int n; scanf("%d", &n);
	REP(i, n) scanf("%d", a+i);
	for(int i = n-1; i >= 0; i--){
		if(i == n-1) {
			c[i] = 1;
		} else if(a[i] >= M){
			c[i] += c[i+1];
			for(int j = i+a[i]; j < n; j += a[i]) c[i] += c[j];
		} else {
			if(a[i] > 1) c[i] += c[i+1];
			c[i] += b[a[i]][i%a[i]];
		}
		c[i] %= MOD;
		FOR(j, 1, M) b[j][i%j] = (b[j][i%j] + c[i]) % MOD;
	}
	printf("%lld\n", c[0]);
}
0