Submission #1005636

#TimeUsernameProblemLanguageResultExecution timeMemory
1005636TrinhKhanhDungTrains (BOI24_trains)C++14
100 / 100
77 ms253176 KiB
#include <bits/stdc++.h> #define ll long long #define fi first #define se second #define sz(x) (int)x.size() #define ALL(v) v.begin(),v.end() #define MASK(k) (1LL << (k)) #define BIT(x, i) (((x) >> (i)) & 1) #define oo (ll)1e18 #define INF (ll)1e9 #define MOD (ll)(1e9 + 7) #define int ll using namespace std; template<class T1, class T2> bool maximize(T1 &a, T2 b){if(a < b){a = b; return true;} return false;} template<class T1, class T2> bool minimize(T1 &a, T2 b){if(a > b){a = b; return true;} return false;} template<class T1, class T2> void add(T1 &a, T2 b){a += b; if(a >= MOD) a -= MOD;} template<class T1, class T2> void sub(T1 &a, T2 b){a -= b; if(a < 0) a += MOD;} template<class T> void cps(T &v){sort(ALL(v)); v.resize(unique(ALL(v)) - v.begin());} const int MAX = 1e5 + 10; int N; int d[MAX], t[MAX]; void input(){ cin >> N; for(int i=1; i<=N; i++){ cin >> d[i] >> t[i]; } } namespace subtask2{ int f[MAX]; void solve(){ f[1] = 1; for(int i=1; i<=N; i++) if(f[i] && d[i]){ for(int j=1; j<=t[i]; j++){ if(i + 1LL * d[i] * j > N) break; add(f[i + d[i] * j], f[i]); } } int ans = 0; for(int i=1; i<=N; i++){ add(ans, f[i]); } cout << ans << '\n'; } } namespace subtask3{ bool check(){ for(int i=1; i<=N; i++){ if(d[i] != 1) return false; } return true; } int f[MAX]; void solve(){ f[1] = 1; for(int i=1; i<=N; i++){ add(f[i], f[i - 1]); int p = min(1LL * N, i + 1LL * d[i] * t[i]); add(f[i + 1], 1); sub(f[p + 1], 1); } int ans = 0; for(int i=1; i<=N; i++){ add(ans, f[i]); } cout << ans << '\n'; } } namespace subtask5{ const int S = sqrt(MAX + 10); int f[MAX], g[MAX][S]; void solve(){ for(int i=N; i>=1; i--){ if(d[i] < S){ if(d[i] && t[i]){ ll st = i + d[i]; ll en = i + d[i] * (t[i] + 1); if(st <= N){ if(en <= N) add(f[i], (g[st][d[i]] - g[en][d[i]] + MOD) % MOD); else add(f[i], g[st][d[i]]); } } } else if(d[i]){ for(int j=1; j<=t[i] && i + 1LL * j * d[i] <= N; j++){ add(f[i], f[i + 1LL * j * d[i]]); } } f[i]++; for(int j=1; j<S; j++){ g[i][j] = f[i]; if(i + j <=N ) add(g[i][j], g[i + j][j]); } // cout << f[i] << ' '; } cout << f[1]; } } signed main(){ ios_base::sync_with_stdio(0); cin.tie(0); // freopen("netw.inp", "r", stdin); // freopen("netw.out", "w", stdout); input(); return subtask5::solve(), 0; 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...