Submission #1139209

#TimeUsernameProblemLanguageResultExecution timeMemory
1139209why1Trains (BOI24_trains)C++20
34 / 100
125 ms2804 KiB
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define pb push_back
#define pii pair<int,int>
#define sz size()
#define all(v) v.begin(),v.end()
#define fi first
#define se second

const int N = 2e5;
const int mod = 1e9+7;
const int INF = 1e9;

const int di[] = {1, -1, 0, 0};
const int dj[] = {0, 0, 1, -1};

const int M = 320;

int n;
ll d[N+1],x[N+1];
ll add[M][M];

void slow(){
    ll dp[n+1];
	memset(dp,0,sizeof(dp));
	dp[1]=1;
	for(int i = 2; i <= n; i++){
		for(int j = 1; j < i; j++){
			if(d[j]==0)
				continue;
			int k=(i-j)/d[j];
			if(i%d[j]==j%d[j] && 1<=k && k<=x[j]){
				dp[i]=(dp[i]+dp[j])%mod;
			}
		}
	}
	ll ans=0;
	for(int i = 1; i <= n; i++){
		ans=(ans+dp[i])%mod;
	}
	cout<<"SLOW: \n";
	for(int i = 1; i <= n; i++){
		cout<<dp[i]<<" ";
	}
	cout<<"\n";
	cout<<ans<<"\n";
}

void solve() {
	cin>>n;
	for(int i = 1; i <= n; i++){
		cin>>d[i]>>x[i];
	}
	ll dp[n+1];
	memset(dp,0,sizeof(dp));
	dp[1]=1;
	for(int i = 1; i <= n; i++){
		for(int d = 1; d < M; d++){
	        dp[i]=(dp[i]+add[d][i%d])%mod;
	    }
	    if(d[i]!=0){
            if(d[i]>=M){
                for(int j = 1; j <= x[i]; j++){
                    if(i+d[i]*j>n) break;
                    dp[i+d[i]*j]=(dp[i+d[i]*j]+dp[i])%mod;
                }
            }
            else{
				add[d[i]][i%d[i]]=(add[d[i]][i%d[i]]+dp[i])%mod;
            }
	    }
	}
	int ans=0;
	for(int i = 1; i <= n; i++){
	    ans=(ans+dp[i])%mod;
	}
	cout<<ans<<"\n";
}

int main() {

	//freopen("cowrun.in","r",stdin);
	//freopen("cowrun.out","w",stdout);

    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

	int t=1;
	//cin>>t;
	while(t--) {
        solve();
	}

    return 0;
}

#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...