結果

問題 No.1331 Moving Penguin
ユーザー leaf_1415leaf_1415
提出日時 2021-01-08 22:19:11
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 267 ms / 1,500 ms
コード長 1,529 bytes
コンパイル時間 1,878 ms
コンパイル使用メモリ 81,388 KB
実行使用メモリ 254,372 KB
最終ジャッジ日時 2023-08-07 10:54:02
合計ジャッジ時間 14,432 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 64 ms
251,400 KB
testcase_01 AC 50 ms
251,208 KB
testcase_02 AC 51 ms
251,208 KB
testcase_03 AC 50 ms
251,276 KB
testcase_04 AC 245 ms
254,236 KB
testcase_05 AC 243 ms
254,372 KB
testcase_06 AC 243 ms
254,232 KB
testcase_07 AC 243 ms
254,140 KB
testcase_08 AC 244 ms
254,216 KB
testcase_09 AC 244 ms
254,356 KB
testcase_10 AC 245 ms
254,244 KB
testcase_11 AC 246 ms
254,236 KB
testcase_12 AC 246 ms
254,140 KB
testcase_13 AC 246 ms
254,356 KB
testcase_14 AC 246 ms
254,240 KB
testcase_15 AC 246 ms
254,312 KB
testcase_16 AC 246 ms
254,236 KB
testcase_17 AC 243 ms
254,308 KB
testcase_18 AC 243 ms
254,224 KB
testcase_19 AC 242 ms
254,244 KB
testcase_20 AC 239 ms
254,300 KB
testcase_21 AC 243 ms
254,188 KB
testcase_22 AC 241 ms
254,244 KB
testcase_23 AC 247 ms
254,244 KB
testcase_24 AC 246 ms
254,144 KB
testcase_25 AC 246 ms
254,144 KB
testcase_26 AC 245 ms
254,220 KB
testcase_27 AC 244 ms
254,152 KB
testcase_28 AC 244 ms
254,240 KB
testcase_29 AC 245 ms
254,352 KB
testcase_30 AC 115 ms
252,252 KB
testcase_31 AC 160 ms
253,148 KB
testcase_32 AC 107 ms
252,088 KB
testcase_33 AC 135 ms
252,556 KB
testcase_34 AC 180 ms
253,260 KB
testcase_35 AC 267 ms
254,220 KB
testcase_36 AC 267 ms
254,360 KB
testcase_37 AC 266 ms
254,172 KB
testcase_38 AC 118 ms
252,308 KB
testcase_39 AC 238 ms
254,068 KB
testcase_40 AC 147 ms
253,044 KB
testcase_41 AC 243 ms
254,144 KB
testcase_42 AC 262 ms
254,232 KB
testcase_43 AC 261 ms
254,280 KB
testcase_44 AC 260 ms
254,144 KB
testcase_45 AC 260 ms
254,176 KB
testcase_46 AC 260 ms
254,280 KB
testcase_47 AC 260 ms
254,300 KB
testcase_48 AC 242 ms
254,184 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cassert>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <algorithm>
#include <utility>
#include <complex>
#define rep(x, s, t) for(llint (x) = (s); (x) <= (t); (x)++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))
#define all(x) (x).begin(),(x).end()
#define inf 1e18
#define mod 1000000007

using namespace std;

typedef long long llint;
typedef long long ll;
typedef pair<llint, llint> P;

const ll B = 320;
ll n;
ll a[100005];
ll dp[100005];
ll sum[B][100005];

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n;
	rep(i, 1, n) cin >> a[i];
	
	dp[1] = 1;
	rep(i, 1, n){
		
		if(i > 1){
			if(a[i-1] != 1){
				dp[i] += dp[i-1];
				if(dp[i] >= mod) dp[i] -= mod;
			}
			rep(j, 1, B-1) if(i-j >= 1) dp[i] += sum[j][i-j];
			dp[i] %= mod;
		}
		rep(j, 1, B-1){
			ll s = 0;
			if(i-j >= 1) s = sum[j][i-j];
			sum[j][i] = s;
			if(j == a[i]) sum[j][i] += dp[i];
			if(sum[j][i] >= mod) sum[j][i] -= mod;
		}
		
		if(a[i] >= B){
			rep(j, 1, n){
				if(i+j*a[i] > n) break;
				dp[i+j*a[i]] += dp[i];
				if(dp[i+j*a[i]] >= mod) dp[i+j*a[i]] -= mod;
			}
		}
	}
	cout << dp[n] << endl;
	
	/*rep(i, 1, n) cout << sum[1][i] << " "; cout << endl;
	rep(i, 1, n) cout << sum[2][i] << " "; cout << endl;
	rep(i, 1, n) cout << dp[i] << " "; cout << endl;*/
	
	return 0;
}
0