Submission #1309673

#TimeUsernameProblemLanguageResultExecution timeMemory
1309673meesha284Trains (BOI24_trains)C++17
50 / 100
132 ms6768 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define vi vector<ll> #define vvi vector<vector<ll>> #define vs vector<string> #define vc vector<char> #define vb vector<bool> #define vp vector<pair<ll, ll>> #define vpp vector<pair<ll, pair<ll, ll>>> #define pp pair<ll, ll> #define qi queue<ll> #define qp queue<pp> #define pqi priority_queue<ll> #define pqp priority_queue<pp> #define mi map<ll, ll> #define mpi map<pp, ll> #define mip map<ll, pp> #define mp map<pp, pp> #define mb map<ll, bool> #define si set<ll> #define sp set<pp> #define sc set<char> #define mod 1000000007 #define inf 1000000000000000000 #define all(x) (x).begin(), (x).end() int main() { ios_base::sync_with_stdio(0); cin.tie(0); ll n; cin >> n; vi d(n + 1), x(n + 1); for(int i = 1; i <= n; i++) cin >> d[i] >> x[i]; ll LIM = sqrt(n); vi dp(n + 1, 0); dp[1] = 1; vvi add(LIM); for(int i = 1; i < LIM; i++) { add[i] = vi(i, 0); } vector<vector<pair<pp, ll>>> ends(n + 1); for(int i = 1; i <= n; i++) { for(int j = 1; j < LIM; j++) { ll rem = i % j; dp[i] = (dp[i] + add[j][rem]) % mod; } for(auto[t, val] : ends[i]) { auto[div, rem] = t; add[div][rem] = (mod + add[div][rem] - val) % mod; } if(d[i] == 0) continue; if(d[i] >= LIM) { for(int j = 1; j <= x[i]; j++) { ll stop = i + d[i] * j; if(stop > n) break; dp[stop] += dp[i]; dp[stop] %= mod; } } else { ll rem = i % d[i]; add[d[i]][rem] = (add[d[i]][rem] + dp[i]) % mod; ll last = i + d[i] * x[i]; if(last > n) continue; ends[last].push_back({{d[i], rem}, dp[i]}); } } ll ans = 0; for(int i = 1; i <= n; i++) ans = (ans + dp[i]) % mod; cout << ans << '\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...