# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1268911 | minhvule | Trains (BOI24_trains) | C++17 | 108 ms | 6348 KiB |
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define fi first
#define se second
#define pb push_back
#define freo(task) if(fopen(task".inp", "r")){ freopen(task".inp", "r", stdin); freopen(task".out", "w", stdout); }
#define FOR(i, a, b) for(int i = (a), _b = (b); i <= _b; i ++)
#define FORD(i, a, b) for(int i = (a), _b = (b); i >= _b; i --)
#define bit(x, i) ((x >> i) & 1)
#define oo 1e18
#define all(v) v.begin(), v.end()
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
// mt19937 rd(chrono::steady_clock::now().time_since_epoch().count());
// ll rand(ll l, ll r) { assert(l <= r); return uniform_int_distribution<ll>(l, r)(rd); }
const int N = 1e5 + 5;
const int BLOCK = 320;
const int mod = 1e9 + 7;
const int base = 31;
int n, d[N], x[N], dp[N], sum[BLOCK + 10][BLOCK + 10], ans = 0;
vector<int> rem[N];
void add(int &a, int b){
a += b;
if(a >= mod) a -= mod;
}
void sub(int &a, int b){
a -= b;
if(a < 0) a += mod;
}
void solve(){
cin>>n;
FOR(i, 1, n){
cin>>d[i]>>x[i];
if(d[i] != 0) x[i] = min(x[i], (n - i) / d[i]);
x[i] = i + d[i] * x[i];
}
dp[1] = 1;
FOR(i, 1, n){
FOR(j, 1, BLOCK - 1) add(dp[i], sum[j][i % j]);
add(ans, dp[i]);
if(d[i] != 0){
if(d[i] >= BLOCK){
for(int j = i + d[i]; i <= n; j += d[i]){
int t = i + j * d[i];
add(dp[t], dp[i]);
}
}
else{
add(sum[d[i]][i % d[i]], dp[i]);
rem[x[i]].pb(i);
}
}
for(int j : rem[i]) sub(sum[d[j]][j % d[j]], dp[j]);
}
cout<<ans;
}
int32_t main(){
ios::sync_with_stdio(false);
cin.tie(NULL);
freo("cuuho");
int nTest = 1;
// cin>>nTest;
while(nTest --) solve();
// cerr << "\nTime: " << 1.0 * clock() / CLOCKS_PER_SEC << "s\n";
return 0;
}
/*
*/
컴파일 시 표준 에러 (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... |