Submission #1016684

#TimeUsernameProblemLanguageResultExecution timeMemory
1016684beaconmcTrains (BOI24_trains)C++14
100 / 100
1187 ms25680 KiB
#include <bits/stdc++.h> typedef long long ll; #define FOR(i,x,y) for(ll i=x; i<y; i++) #define FORNEG(i,x,y) for(ll i=x; i>y; i--) using namespace std; multiset<vector<ll>> sus[505][505]; ll sums[505][505]; ll dp[100005]; int main(){ ll n; cin >> n; FOR(i,0,n+1) dp[i] = 0; FOR(i,0,505) FOR(j,0,505) sus[i][j].clear(), sums[i][j] = 0; dp[0] = 1; FOR(i,0,n){ FOR(j,1,501){ ll mod = i%j; while(!sus[j][mod].empty()){ vector<ll> temps = *sus[j][mod].begin(); if (temps[0] <= i){ sums[j][mod] -= temps[1]; sums[j][mod] += 1000000007; sums[j][mod] %= 1000000007; sus[j][mod].erase(sus[j][mod].find(temps)); } else break; } dp[i] += sums[j][mod]; dp[i] %= 1000000007; } ll a,b; cin >> a >> b; if (a==0) continue; ll lim = i + a*b + 1; if (a > 500){ ll cur = i; cur += a; while (cur < lim && cur < 100005){ dp[cur] += dp[i]; dp[cur] %= 1000000007; cur += a; } }else{ sus[a][i%a].insert({lim, dp[i]}); sums[a][i%a] += dp[i]; sums[a][i%a] %= 1000000007; } } ll ans = 0; FOR(i,0,n){ ans += dp[i]; } cout << ans%1000000007; }
#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...