제출 #1237337

#제출 시각아이디문제언어결과실행 시간메모리
1237337zadniprovskaTrains (BOI24_trains)C++20
21 / 100
67 ms836 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long const ll DIM = 1e5 + 7; const ll mod = 1e9 + 7; ll dp[DIM], diff[DIM]; int main(){ ios::sync_with_stdio(false);cin.tie(nullptr); cout.tie(nullptr); ll n; cin >> n; if (n <= 10000) { dp[1] = 1; for (int i=1; i<=n; i++) { ll d, x; cin >> d >> x; if (d == 0) continue; for (int j=i+d; j<=min(n, i + x*d); j+=d) { dp[j] += dp[i]; dp[j] %= mod; } } ll answer = 0; for (int i=1; i<=n; i++) { answer += dp[i]; answer %= mod; } cout << answer << endl; } else { diff[2] = -1; ll dp = 1, answer = 0; for (int i=1; i<=n; i++) { ll d, x; cin >> d >> x; // i+d ... i + x*d diff[i+d]+=dp; diff[i+d] %= mod; diff[min(n, i+x*d) + 1]-=dp; diff[min(n, i+x*d) + 1] %= mod; answer += dp; answer %= mod; dp = dp + diff[i+1]; dp %= mod; } cout << answer << 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...