Submission #991342

#TimeUsernameProblemLanguageResultExecution timeMemory
991342AndreyTrains (BOI24_trains)C++14
100 / 100
118 ms317804 KiB
#include<bits/stdc++.h> using namespace std; long long bruh[100001][400]; const long long MOD = 1e9+7; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long n,a,b; cin >> n; vector<pair<long long,long long>> haha(n+1); for(long long i = 0; i < n; i++) { cin >> a >> b; haha[i] = {a,b}; } reverse(haha.begin(),haha.end()); vector<long long> dp(n+1,1); dp[0] = 0; for(long long i = 0; i < 400; i++) { bruh[0][i] = 0; } for(long long i = 1; i <= n; i++) { a = haha[i].first; b = haha[i].second; if(a*a <= n) { if(i > a) { dp[i]+=bruh[i-a][a]; dp[i]%=MOD; } if(i > a*(b+1)) { dp[i]-=bruh[i-a*(b+1)][a]; dp[i]+=MOD; dp[i]%=MOD; } } else { for(long long j = i-a; j >= max(0LL,i-a*b); j-=a) { dp[i]+=dp[j]; dp[i]%=MOD; } } for(long long j = 1; j*j <= n; j++) { if(j <= i) { bruh[i][j] = (bruh[i-j][j]+dp[i])%MOD; } else { bruh[i][j] = dp[i]; } } } cout << dp[n]; 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...