# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1000571 | arashMLG | Trains (BOI24_trains) | C++17 | 65 ms | 4736 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
#ifdef LOCAL
#include "Essentials/algo/debug.h"
#else
#define debug(...) 69
#define debugArr(...) 69
#endif
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int N = 1e5 + 23;
const int sq = 320;
const ll mod = 1e9 + 7;
const ll inf = 1e18;
#define F first
#define S second
#define pb push_back
#define kill(x) cout<<x<<endl, exit(0);
#define all(x) x.begin(),x.end()
#define sz(x) (int)x.size()
#define lc (v << 1)
#define rc ((v<<1) |1)
#define int ll
void ok(int &x) {
if(x < 0) x += mod*mod;
x %= mod;
}
int n;
int d[N],x[N];
int dp[N];
vector<int> vals[N];
int sum[sq][sq];
int32_t main() {
cin.tie(nullptr)->sync_with_stdio(false);
cin>>n;
for(int i = 1; i <= n ; i ++) cin>>d[i]>>x[i];
dp[1] = 1;
int ans = 0;
for(int i = 1; i <= n; i ++) {
for(int j = 1 ; j < sq; j ++) {
ok(dp[i] += sum[j][i%j]);
}
if(d[i] != 0) {
if(d[i] < sq) {
if(i + d[i]*x[i] <= n) {
vals[i + d[i]*x[i]].pb(i);
ok(sum[d[i]][i%d[i]] += dp[i]);
}
} else {
for(int j = i+d[i]; j <= n && x[i]--;j += d[i]) {
ok(dp[j] += dp[i]);
}
}
}
for(int j : vals[i]) ok(sum[d[j]][j%d[j]] -= dp[j]);
ok(ans += dp[i]);
debug(i,dp[i]);
}
cout<<ans << '\n';
return 0;
}
// Jumpsuit, Jumpsuit cover me!
// Jumpsuit, Jumpsuit cover me!
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... |