제출 #1111529

#제출 시각아이디문제언어결과실행 시간메모리
1111529jmuzhenTrains (BOI24_trains)C++17
21 / 100
2069 ms8176 KiB
#include<bits/stdc++.h> using namespace std; #define int long long struct St { int d, x, end; }; int n; vector<St> stations; vector<int> tt; const int MOD = 1e9 + 7; int ans = 0; #define DEBUG false // returns the number of diff routes starting at src. int dp(int src) { if (DEBUG) cout << "dp:" << src << endl; if (tt[src] != -1) return tt[src]; auto& st = stations[src]; int d = st.d, end = st.end; if (DEBUG) cout << d << " " << end << endl; // simple case: if d == 0 then we must stop if (d == 0) { return 1; } // we can either stop here (ans++) // or we can take the train (to src + d, src + ..., <= end) int value = 0; // easier case: stop here value += 1; { // case 2 int e = src + d; while (e <= end) { if (DEBUG) cout << src << " wl: " << e << " <= " << end << endl; value += dp(e); e += d; } } value %= MOD; tt[src] = value; if (DEBUG) cout << "dp:" << src << " = " << value << endl; return value; } signed main() { cin >> n; stations.resize(n+1); tt.resize(n+1, -1); for (int i = 1; i <= n; i++) { int d, x; cin >> d >> x; long long end = min((long long)n, (long long)i + d * x); stations[i] = {d, x, (int)end}; } ans = dp(1); cout << ans << endl; }
#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...