# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1278330 | phuocrucpp | Trains (BOI24_trains) | C++20 | 152 ms | 125308 KiB |
/*ㅤ∧_∧
( ・∀・)
( つ┳⊃
ε (_)へ⌒ヽフ
( ( ・ω・)
◎―◎ ⊃ ⊃
BePhuongSuperSuwi
From TK4 - CHT
ㅤㅤ/ ⌒\____
/・ ) \
/ノへ ノ /|
ノ \\ |/_/_/*/
#include<bits/stdc++.h>
#define task "main"
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#define endl '\n'
//#define int long long
#define pb push_back
#define fi first
#define se second
#define ii pair<int,int>
#define iii pair<int,ii>
#define iv pair<ii, ii>
#define base 341
#define MASK(i) (1ll << i)
#define oo 1e18
#define isOn(x,i) ((x) & MASK(i))
#define bitOn(x,i) ((x) | MASK(i))
#define bitOff(x,i) ((x) & ~MASK(i))
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define __lcm(a,b) (1ll * ((a) / __gcd((a), (b))) * (b))
using namespace std;
//using namespace __gnu_pbds;
const int maxn = 1e5 + 5;
int n, d[maxn], x[maxn], dp[maxn], mod = 1e9 + 7, p[325][maxn];
main() {
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
if(fopen(task".inp","r")) {
freopen(task".inp","r",stdin);
freopen(task".out","w",stdout);
}
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> d[i] >> x[i];
// d[i] = x[i] = 1e9;
}
int S = sqrt(n);
for (int i = n; i >= 1; i--) {
if (d[i] == 0)
dp[i] = 1;
else {
int lim = min(x[i], (n - i) / d[i]), sum = 0;
if (d[i] > S) {
for (int k = 1; k <= lim; k++) {
int x = i + k * d[i];
sum = (sum + dp[x]) % mod;
}
}
else {
int pos1 = i + d[i];
int pos2 = i + d[i] * (lim + 1);
int s1 = (pos1 <= n ? p[d[i]][pos1] : 0);
int s2 = (pos2 <= n ? p[d[i]][pos2] : 0);
sum = ((s1 - s2) % mod + mod) % mod;
}
dp[i] = (1 + sum) % mod;
}
for(int j=1;j<=S;j++){
int idx = i + j;
int val = dp[i];
if(idx <= n) {
val = (val + p[j][idx]) % mod;
}
p[j][i] = val;
}
}
cout << dp[1] % mod;
}
컴파일 시 표준 에러 (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... |