| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 1334924 | SmuggingSpun | Trains (BOI24_trains) | C++20 | 208 ms | 119028 KiB |
#include<bits/stdc++.h>
#define taskname "C"
using namespace std;
typedef long long ll;
const int lim = 1e5 + 5;
const int mod = 1e9 + 7;
void add(int& a, int b){
if((a += b) >= mod){
a -= mod;
}
}
void sub(int& a, int b){
if((a -= b) < 0){
a += mod;
}
}
int n, d[lim], x[lim];
namespace sub12{
void solve(){
vector<int>dp(n + 1, 0);
for(int i = dp[1] = 1; i <= n; i++){
if(d[i] > 0){
for(int j = i + d[i]; j <= n && x[i] > 0; j += d[i], x[i]--){
add(dp[j], dp[i]);
}
}
}
cout << accumulate(dp.begin(), dp.end(), 0LL) % mod;
}
}
namespace sub345{
const int SIZE = 300;
int dp[lim], f[SIZE][lim];
void solve(){
memset(dp, 0, sizeof(dp));
memset(f, 0, sizeof(f));
for(int i = dp[1] = 1; i <= n; i++){
for(int j = min(SIZE - 1, i); j > 0; j--){
add(f[j][i], f[j][i - j]);
add(dp[i], f[j][i]);
}
if(d[i] > 0){
if(d[i] >= SIZE){
for(int j = i + d[i]; j <= n && x[i] > 0; j += d[i], x[i]--){
add(dp[j], dp[i]);
}
}
else if(i + d[i] <= n){
add(f[d[i]][i + d[i]], dp[i]);
if(i + ll(x[i] + 1) * d[i] <= n){
sub(f[d[i]][i + (x[i] + 1) * d[i]], dp[i]);
}
}
}
}
cout << accumulate(dp + 1, dp + n + 1, 0LL) % mod;
}
}
int main(){
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
if(fopen(taskname".inp", "r")){
freopen(taskname".inp", "r", stdin);
}
cin >> n;
for(int i = 1; i <= n; i++){
cin >> d[i] >> x[i];
}
if(n <= 10000){
sub12::solve();
}
else{
sub345::solve();
}
}컴파일 시 표준 에러 (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... | ||||
