이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pll pair<long long, long long>
#define pb push_back
#define F first
#define S second
#define all(x) (x).begin(), (x).end()
const ll N = 2e5 + 100;
const ll inf = 1e18;
const ll mod = 1e9 + 7;
const ll block = 350;
ll d[N], a[N], dp[N], suf[N][block + 10];
ll n;
void sub_trau(){
dp[1] = 1;
ll res = 0;
for(ll i = 2; i <= n;i++){
for(int j = 1; j <= i - 1;j++){
if(d[j] == 0) continue;
if(j + a[j] * d[j] >= i && i % d[j] == j % d[j]) dp[i] = (dp[i] + dp[j]) % mod;
}
}
for(int i = 1; i <= n;i++) res = (res + dp[i]) % mod;
cout << res << "\n";
}
void sub_full(){
for(int i = n; i >= 1;i--){
dp[i] = 1;
if(d[i] > block){
for(int j = 1; j <= a[i];j++){
if(i + d[i] * j > n) break;
dp[i] = (dp[i] + dp[i + d[i] * j]) % mod;
}
}
if(d[i] <= block && d[i] > 0 && a[i] > 0) {
dp[i] = (dp[i] + suf[i + d[i]][d[i]]) % mod;
if(i + (a[i] + 1) * d[i] <= n) dp[i] = (dp[i] - suf[i + (a[i] + 1) * d[i]][d[i]]) % mod;
}
dp[i] = (dp[i] + mod) % mod;
for(int j = 1; j <= block;j++){
suf[i][j] = (dp[i] + suf[i + j][j]) % mod;
}
}
cout << dp[1] << "\n";
}
void to_thic_cau(){
cin >> n;
for(int i = 1; i <= n;i++) cin >> d[i] >> a[i];
sub_full();
}
signed main(){
//freopen("A.inp", "r", stdin);
//freopen("A.out", "w", stdout);
ios_base::sync_with_stdio(0);
cin.tie(0);
ll tc = 1;
//cin >> tc;
while(tc--) to_thic_cau();
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |