/******************************************************************************
Online C++ Compiler.
Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.
*******************************************************************************/
#include <iostream>
#define mod 1000000007
using namespace std;
unsigned long long n,x[200005],d[200005],sum[200005],ok;
int main()
{
cin>>n;
for (int i = 1; i <= n; i++){
cin>>d[i]>>x[i];
if (d[i] != 1)
ok = 1;
}
if (ok == 1){
sum[1] = 1;
for (int i = 1; i<=n;i++){
while (d[i] == 0 && i <= n){
i++;
}
if (i > n)
break;
int p = i + d[i];
while (x[i]){
if (p <= n){
sum[p] += sum[i] % mod;
sum[p] = sum[p] % mod;
}
else
break;
if (p + d[i] <= n)
p += d[i] % mod;
else
break;
x[i]--;
}
}
long long suma = 0;
for (int i = 1; i <=n; i++){
suma += sum[i] % mod;
suma = suma % mod;
}
cout << suma;
}
else{
long long suma = (n % mod * (n + 1) % mod) / 2 % mod;
cout << suma;
}
return 0;
}
# | 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... |