Submission #1093445

#TimeUsernameProblemLanguageResultExecution timeMemory
1093445raphaelpTrains (BOI24_trains)C++14
100 / 100
215 ms9940 KiB
#include <bits/stdc++.h> using namespace std; int main() { long long N; cin >> N; long long MOD = 1000000007; vector<long long> D(N), X(N); for (long long i = 0; i < N; i++) { cin >> D[i] >> X[i]; } vector<long long> dp(N, 0); dp[0] = 1; vector<vector<long long>> ST(sqrt(N) + 1); for (long long i = 1; i <= sqrt(N); i++) { ST[i].assign(i, 0); } priority_queue<vector<long long>> PQ; long long tot = 0; for (long long i = 0; i < N; i++) { for (long long j = 1; j <= sqrt(N); j++) { dp[i] = (dp[i] + ST[j][i % j]) % MOD; } tot = (tot + dp[i]) % MOD; if (D[i] > sqrt(N)) { long long temp = i; for (long long j = 0; j < X[i]; j++) { temp += D[i]; if (temp >= N) break; dp[temp] = (dp[temp] + dp[i]) % MOD; } } else if (D[i] != 0) { ST[D[i]][i % D[i]] = (ST[D[i]][i % D[i]] + dp[i]) % MOD; PQ.push({-(i + X[i] * D[i]), D[i], dp[i]}); } while (!PQ.empty() && -PQ.top()[0] <= i) { ST[PQ.top()[1]][i % PQ.top()[1]] = (ST[PQ.top()[1]][i % PQ.top()[1]] + MOD - PQ.top()[2]) % MOD; PQ.pop(); } } cout << tot; }
#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...