제출 #1037871

#제출 시각아이디문제언어결과실행 시간메모리
1037871thdh__Trains (BOI24_trains)C++17
100 / 100
100 ms319596 KiB
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx,avx2,fma")
#define ll long long
#define pb push_back
#define eb emplace_back
#define pu push
#define ins insert
#define bruh ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ff(x,a,b,c) for (auto x=a;x<=b;x+=c)
#define fd(x,a,b,c) for (auto x=a;x>=b;x-=c)
#define int ll

using namespace std;
//mt19937 mt(chrono::steady_clock::now().time_since_epoch().count());

typedef pair<int, int> ii;
const int N = 2e5+5;
const int M = 350;
const int mod = 1e9+7;
const int INF = 1e18;
using cd = complex<double>;
const long double PI = acos(-1);
int power(int a,int b) {ll x = 1;if (a >= mod) a%=mod; while (b) {if (b & 1) x = x*a % mod;a = a*a % mod;b>>=1;}return x;} 

int n;
int d[N],x[N],dp[N],sum[N][M+50];

void solve()
{
	cin>>n;
	for (int i=1;i<=n;i++) cin>>d[i]>>x[i];
	for (int i=n;i>=1;i--)
	{
		dp[i] = 1;
		if (d[i]>=M)
		{
			for (int j=1;j<=x[i];j++)
			{
				if (i + d[i] * j > n) break;
				dp[i] = (dp[i] + dp[i + d[i]*j])%mod;
			}
		}
		if (d[i]<M && d[i]>0 && x[i]>0)
		{
			dp[i] = (dp[i] + sum[i+d[i]][d[i]])%mod;
			if (i + (x[i]+1)*d[i]<=n) dp[i] = (dp[i] - sum[i + (x[i]+1)*d[i]][d[i]] + mod)%mod;
		}
		for (int j=1;j<=M;j++) sum[i][j] = (sum[i+j][j] + dp[i])%mod;
	}
	cout<<dp[1];
}

signed main()
{
	bruh
	//freopen("input.inp","r",stdin);
	//freopen("output.inp","w",stdout);
	int t = 1;
	//cin>>t;
	while (t--)
	{
		solve();
		cout<<"\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...