Submission #1052949

#TimeUsernameProblemLanguageResultExecution timeMemory
1052949vjudge1Trains (BOI24_trains)C++17
100 / 100
235 ms8020 KiB
#include <iostream> #include <vector> using namespace std; #define int long long const int N = 1e5 + 5; int dp[N], mod = 1e9 + 7, Ans; int Mod[505][505]; vector<pair<int,int>> rem[N]; signed main(){ int n; cin>>n; dp[1] = 1; for (int i=1, d, x;i<=n;i++){ cin>>d>>x; for (int m=1;m<=500;m++) dp[i] = (dp[i] + Mod[m][i % m]) % mod; if (d > 500){ for (int j=d;j/d<=x and i + j <= n;j+=d) dp[j + i] = (dp[j + i] + dp[i]) % mod; } else if (d){ Mod[d][i % d] = (Mod[d][i % d] + dp[i]) % mod; } if (d and d <= 500 and d * x + i <= n) rem[d * x + i].push_back({i, d}); for (auto [ind, d_ind] : rem[i]) Mod[d_ind][ind % d_ind] = (Mod[d_ind][ind % d_ind] - dp[ind] + mod) % mod; Ans = (Ans + dp[i]) % mod; // exit by removing those } cout<<Ans<<'\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...