Submission #1051320

#TimeUsernameProblemLanguageResultExecution timeMemory
1051320MalixTrains (BOI24_trains)C++14
21 / 100
102 ms2396 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<int> vi; typedef vector<vi> vii; typedef pair<int,int> pi; typedef vector<pi> pii; typedef tuple<int,int,int> tii; typedef vector<ll> li; typedef vector<li> lii; #define REP(i,a,b) for(int i=a;i<b;i++) #define F first #define S second #define PB push_back #define MP make_pair #define LSOne(s) ((s)&(-s)) ll INF=1e18+10; int inf=1e9+10; ll M=1e9+7; int main() { // ios::sync_with_stdio(0); // cin.tie(0); int n;cin>>n; pii a(n); REP(i,0,n)cin>>a[i].F>>a[i].S; vector<ll> ans(n,0); ans[0]=1; if(n<=10000){ REP(i,0,n){ int k=a[i].F; if(k==0)continue; REP(j,1,a[i].S+1){ if(i+j*k>=n)break; ans[i+j*k]+=ans[i]; ans[i+j*k]%=M; } } ll val=0; REP(i,0,n){ val+=ans[i]; val%=M; } cout<<val; return 0; } ll b=1; vector<ll> c(n,0); c[min(n-1,a[0].S)]=1; REP(i,1,n){ ans[i]+=b; ans[i]%=M; b-=c[i]; if(a[i].S!=0){ c[min(n-1,i+a[i].S)]+=ans[i]; c[min(n-1,i+a[i].S)]%=M; b+=ans[i]; b%=M; } } ll val=0; REP(i,0,n){ val+=ans[i]; val%=M; } cout<<val; }
#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...