Submission #991339

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