제출 #1005607

#제출 시각아이디문제언어결과실행 시간메모리
1005607TrinhKhanhDungTrains (BOI24_trains)C++14
0 / 100
1438 ms2884 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) 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'; } } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); // freopen("netw.inp", "r", stdin); // freopen("netw.out", "w", stdout); input(); if(subtask3::check()) return subtask3::solve(), 0; return subtask2::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...