Submission #1033749

#TimeUsernameProblemLanguageResultExecution timeMemory
1033749TozzyyyyTrains (BOI24_trains)C++14
100 / 100
151 ms9924 KiB
#ifdef LOCAL #include "D:\debug.h" #else #define cebug(...) "anHiepORZ" #endif #pragma GCC optimize("Ofast,unroll-loops") #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") #include <bits/stdc++.h> using namespace std; #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; #define ordered_set tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update> //less: set //less_equal: multiset (ko dung dc ham ...) #define fi first #define se second #define pb push_back //COUNTDOWN: 9 days left //COUNTDOWN: 9 days left //COUNTDOWN: 9 days left //COUNTDOWN: 9 days left //COUNTDOWN: 9 days left //COUNTDOWN: 9 days left //COUNTDOWN: 9 days left //COUNTDOWN: 9 days left #define int long long const int N = 1e5 + 10; const int mod = 1e9 + 7; const int oo = 1e18; int n; pair<int,int> a[N]; int dp[N]; const int S = 316; int rem[S + 10][S + 10]; vector<pair<pair<int,int>, int>> del[N]; void solve(){ cin >> n; for(int i = 1; i <= n; i++){ cin >> a[i].first >> a[i].second; } dp[1] = 1; for(int i = 1; i <= n; i++){ for(auto &x : del[i]){ rem[x.first.first][x.first.second] = (rem[x.first.first][x.first.second] - x.second)%mod; } for(int j = 1; j < S; j++){ dp[i] = (dp[i] + rem[j][i % j])%mod; } if(a[i].first == 0) continue; if(a[i].first >= S){ int x = 1; for(int j = i + a[i].first; j <= n; j += a[i].first){ if(x > a[i].second) break; x++; dp[j] = (dp[j] + dp[i])%mod; } } else{ rem[a[i].first][i % a[i].first] = (rem[a[i].first][i % a[i].first] + dp[i]) %mod; del[min(n + 1, i + a[i].first * a[i].second + 1)].push_back(make_pair(make_pair(a[i].first, i % a[i].first), dp[i] % mod)); } } int sum = 0; for(int i = 1; i <= n; i++) sum = (sum + dp[i]) % mod; cout << (sum + mod)%mod; } signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int tc; tc = 1; while(tc--) solve(); 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...