Submission #1124297

#TimeUTC-0UsernameProblemLanguageResultExecution timeMemory
11242972024-12-05 17:28:32votranngocvyTrains (BOI24_trains)C++20
58 / 100
260 ms255064 KiB
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = 2e5 + 5;
const int block_size = 320;
const int mod = 1e9 + 7;
int a[N],b[N],dp[N],sum[325][N];
//sum[i][j]: so cach den dinh j voi buoc nhay co do dai i
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int n;
cin >> n;
for (int i = 1; i <= n; i++) cin >> a[i] >> b[i];
for (int i = n; i > 0; i--) {
dp[i] = 1;
if (a[i] > block_size) {
for (int j = 1; j <= b[i] && i + j * a[i] <= n; j++)
dp[i] = (dp[i] + dp[j]) % mod;
}
else if (a[i] > 0) {
if (i + a[i] <= n) dp[i] = (dp[i] + sum[a[i]][i + a[i]]) % mod;
if (i + (b[i] + 1) * a[i] <= n) dp[i] = (dp[i] - sum[a[i]][i + (b[i] + 1) * a[i]] + mod) % mod;
}
for (int j = 1; j <= block_size; j++) sum[j][i] = (sum[j][i + j] + dp[i]) % mod;
}
cout << dp[1] << "\n";
}
 
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
#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...