結果

問題 No.1331 Moving Penguin
ユーザー SSRS
提出日時 2021-01-08 22:39:40
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
MLE  
実行時間 -
コード長 853 bytes
コンパイル時間 2,641 ms
コンパイル使用メモリ 191,948 KB
実行使用メモリ 1,204,736 KB
最終ジャッジ日時 2024-11-16 13:51:25
合計ジャッジ時間 24,309 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 39 TLE * 5 MLE * 5
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC target("avx")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++){
    cin >> A[i];
  }
  vector<long long> dp(N, 0);
  dp[0] = 1;
  vector<map<int, long long>> next(N);
  for (int i = 0; i < N; i++){
    for (auto &&P : next[i]){
      P.second %= MOD;
      dp[i] += P.second;
      if (i + P.first < N){
        next[i + P.first][P.first] += P.second;
      }
    }
    dp[i] %= MOD;
    if (i < N - 1 && A[i] != 1){
      dp[i + 1] += dp[i];
      if (dp[i + 1] >= MOD){
        dp[i + 1] -= MOD;
      }
    }
    if (i + A[i] < N){
      next[i + A[i]][A[i]] += dp[i];
    }
  }
  cout << dp[N - 1] << "\n";
}
0