# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1270183 | cr7 | Trains (BOI24_trains) | C++17 | 230 ms | 9244 KiB |
#include<bits/stdc++.h>
#define dn cout << "\n";
#define ll long long
#define F first
#define S second
#define name "tasksss"
#define con(x) __builtin_popcount(x)
#define pb push_back
#define bit(i, j) ((i >> j) & 1)
using namespace std;
const int N = 2e5 + 2;
const int BL = 325;
const ll MOD = 1e9 + 7;
int n;
pair<int,int> p[N];
ll dp[N], total[330][330];
vector<int> pos[N];
void add(ll &a, ll b){
a += b;
while(a >= MOD) a -= MOD;
}
void sub(ll &a, ll b){
a -= b;
while(a < 0) a += MOD;
}
ll dem = 0;
void solve(){
cin >> n;
for(int i = 1; i <= n; i ++){
cin >> p[i].F >> p[i].S;
if(p[i].F != 0)
p[i].S = min(p[i].S, (n - i) / p[i].F);
p[i].S = i + p[i].F * p[i].S;
}
dp[1] = 1;
for(int i = 1; i <= n; i ++){
for(int j = 1; j <= BL; j ++)
add(dp[i], total[j][i % j]);
add(dem, dp[i]);
if(p[i].F != 0){
if(p[i].F >= BL){
for(int j = i + p[i].F; j <= p[i].S; j += p[i].F)
add(dp[j], dp[i]);
}
else{
add(total[p[i].F][i % p[i].F], dp[i]);
pos[p[i].S].pb(i);
}
}
for(int j : pos[i]){
sub(total[p[j].F][j % p[j].F], dp[j]);
}
}
cout << dem;
}
main(){
if(fopen(name".inp","r")){
freopen(name".inp","r",stdin);
freopen(name".out","w",stdout);
}
solve();
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |