제출 #1217821

#제출 시각아이디문제언어결과실행 시간메모리
1217821asdfghqwertTrains (BOI24_trains)C++20
100 / 100
228 ms282632 KiB
#include <bits/stdc++.h> #pragma GCC optimize("O3,unroll-loops") #define int long long int using namespace std; typedef long long ll; const int T = 350; const int MOD = 1e9 + 7; int32_t main(){ ios_base::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; vector<pair<int , int >> se(n + 1); for(int i = 1 ; i <= n ; i++){ cin >> se[i].first >> se[i].second; } vector<vector<ll>> a(n + 2*T + 1, vector<ll>(T + 1, 0)); vector<ll> dp(n + 2*T + 1, 0); for(int i = n; i >= 1; i--){ ll f = se[i].first; ll s = se[i].second; if(f == 0){ dp[i] = 1; } else if(f <= T){ dp[i] = 1 + a[i + f][f]; if(i + se[i].first * (se[i].second + 1) <= n) dp[i] -=a[i + f*(s+1)][f]; dp[i] = (dp[i] % MOD + MOD) % MOD; } else { dp[i] = 1; for(int j = i + f; j <= min(n, i + f*s); j += f){ dp[i] = (dp[i] + dp[j]) % MOD; } } for(int j = 1; j <= T; j++){ a[i][j] = (a[i + j][j] + dp[i]) % MOD; } } cout << dp[1] << "\n"; }
#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...