Submission #1051352

#TimeUsernameProblemLanguageResultExecution timeMemory
1051352WhisperTrains (BOI24_trains)C++17
100 / 100
206 ms269288 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; #define int long long #define FOR(i, a, b) for (int i = (a); i <= (b); i++) #define FORD(i, a, b) for (int i = (b); i >= (a); i --) #define REP(i, a) for (int i = 0; i < (a); ++i) #define REPD(i, a) for (int i = (a) - 1; i >= 0; --i) #define MASK(i) (1LL << (i)) #define BIT(x, i) (((x) >> (i)) & 1) constexpr ll LINF = (1ll << 60); constexpr int INF = (1ll << 30); constexpr int Mod = 1e9 + 7; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); /* Phu Trong from Nguyen Tat Thanh High School for gifted student */ template <class X, class Y> bool minimize(X &x, const Y &y){ X eps = 1e-9; if (x > y + eps) {x = y; return 1;} return 0; } template <class X, class Y> bool maximize(X &x, const Y &y){ X eps = 1e-9; if (x + eps < y) {x = y; return 1;} return 0; } #define MAX 100005 #define BLOCK_SIZE 333 int numTrain; pair<int, int> A[MAX]; //(time between each stop point, num stop point) int dp[MAX]; void add(int &x, int y){ x += y; if (x >= Mod) x %= Mod; while(x < 0) x += Mod; } int pref[MAX][BLOCK_SIZE + 5]; void process(void){ cin >> numTrain; for (int i = 1; i <= numTrain; ++i) cin >> A[i].first >> A[i].second; dp[1] = 1; int ans = 0; for (int i = 1; i <= numTrain; ++i){ for (int v = 1; v <= BLOCK_SIZE; ++v){ if(i >= v) add(pref[i][v], pref[i - v][v]); add(dp[i], pref[i][v]); } if (A[i].first >= BLOCK_SIZE){ int x = A[i].second; for (int v = i + A[i].first; v <= numTrain && x > 0; v += A[i].first, x--){ add(dp[v], dp[i]); } } else{ add(pref[i][A[i].first], dp[i]); int fin = min(numTrain + 1, i + (A[i].first * (A[i].second + 1))); add(pref[fin][A[i].first], -dp[i]); } add(ans, dp[i]); } cout << ans; } signed main(){ #define name "Whisper" cin.tie(nullptr) -> sync_with_stdio(false); //freopen(name".inp", "r", stdin); //freopen(name".out", "w", stdout); process(); return (0 ^ 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...