Submission #1224119

#TimeUsernameProblemLanguageResultExecution timeMemory
1224119s3yoonparkTrains (BOI24_trains)C++20
100 / 100
385 ms279084 KiB
#include <bits/stdc++.h>
#define int long long 
using namespace std; 
const int MOD = 1E9 + 7; 
int dp[100005], pref[100005][355]; 
signed main() {
  int n, ans = 0; cin >> n; 
  dp[1] = 1; 
  for (int i = 1; i <= n; i++) {
    int d, x; cin >> d >> x; 
    for (int j = 1; j <= 350; j++) {
      if (i - j >= 0) pref[i][j] += pref[i - j][j]; 
      pref[i][j] %= MOD; 
      dp[i] += pref[i][j]; 
      dp[i] %= MOD; 
    }
    if (d <= 350) {
      pref[i][d] += dp[i];
      pref[i][d] %= MOD; 
      pref[min(i + (x + 1) * d, n + 1)][d] += MOD - dp[i]; 
      pref[min(i + (x + 1) * d, n + 1)][d] %= MOD; 
    } else {
      for (int j = 1; j <= x && i + j * d <= n; j++) {
        dp[i + j * d] += dp[i]; 
        dp[i + j * d] %= MOD; 
      }
    }
    ans += dp[i]; 
    ans %= MOD; 
  }
  cout << ans << '\n'; 
  return 0; 
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...