Submission #1051914

# Submission time Handle Problem Language Result Execution time Memory
1051914 2024-08-10T10:33:33 Z Malix Trains (BOI24_trains) C++14
71 / 100
151 ms 254380 KB
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef pair<int,int> pi;
typedef vector<pi> pii;
typedef tuple<int,int,int> tii;
typedef vector<ll> li;
typedef vector<li> lii;
 
#define REP(i,a,b) for(int i=a;i<b;i++)
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define LSOne(s) ((s)&(-s))
 
ll INF=1e18+10;
int inf=1e9+10;
ll M=1e9+7;
 
int n;
vector<ll> dp;
vi d,x;
int m;
 
int main() {   
// ios::sync_with_stdio(0);
// cin.tie(0);
    cin>>n;
if(n<=10000){
    pii a(n);
    REP(i,0,n)cin>>a[i].F>>a[i].S;
    vector<ll> ans(n,0);
    ans[0]=1;
    REP(i,0,n){
        int k=a[i].F;
        if(k==0)continue;
        REP(j,1,a[i].S+1){
            if(i+j*k>=n)break;
            ans[i+j*k]+=ans[i];
            ans[i+j*k]%=M;
        }
    }
    ll val=0;
    REP(i,0,n){
        val+=ans[i];
        val%=M;
    }
    cout<<val;
    return 0;
}
    d.resize(n);x.resize(n);
    REP(i,0,n)cin>>d[i]>>x[i];
    int mn=1e9;
    REP(i,0,n)mn=min(mn,x[i]);
if(mn!=1e9){
    ll b=1;
    pii a(n);
    REP(i,0,n){
        a[i].F=d[i];
        a[i].S=x[i];
    }
    vector<ll> ans(n,0);
    ans[0]=1;
    vector<ll> c(n,0);
    c[min(n-1,a[0].S)]=1;
    REP(i,1,n){
        ans[i]+=b;
        ans[i]%=M;
        b-=c[i];
        b+=M;
        b%=M;
        if(a[i].S!=0){
            c[min(n-1,i+a[i].S)]+=ans[i];
            c[min(n-1,i+a[i].S)]%=M;
            b+=ans[i];
            b%=M;
        }
    }
    ll val=0;
    REP(i,0,n){
        val+=ans[i];
        val%=M;
    }
    cout<<val;
    return 0;
}
    m=sqrt(n);
    ll ans=0;
    vector<ll> val(n,0);
    val[0]=1;
    vector<vector<ll>> arr(n,vector<ll>(m,0));
    REP(i,0,n){
        REP(j,1,m){
            if(arr[i][j]==0)continue;
            val[i]+=arr[i][j];
            val[i]%=M;
            if(i+j<n){
                arr[i+j][j]+=arr[i][j];
                arr[i+j][j]%=M;
            }
        }
        if(d[i]==0)continue;
        if(d[i]<m){
            if(i+d[i]<n){
                arr[i+d[i]][d[i]]+=val[i];
                arr[i+d[i]][d[i]]%=M;
            }
        }
        else{
            REP(j,1,x[i]+1){
                if(i+d[i]*j>=n)break;
                val[i+d[i]*j]+=val[i];
                val[i+d[i]*j]%=M;
            }
        }
    }
    REP(i,0,n){
        ans+=val[i];
        ans%=M;
    }
    cout<<ans;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 440 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 372 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 440 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 372 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 7 ms 604 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 3 ms 604 KB Output is correct
23 Correct 36 ms 552 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 5 ms 604 KB Output is correct
26 Correct 20 ms 348 KB Output is correct
27 Correct 73 ms 604 KB Output is correct
28 Correct 13 ms 600 KB Output is correct
29 Correct 98 ms 604 KB Output is correct
30 Correct 3 ms 600 KB Output is correct
31 Correct 52 ms 600 KB Output is correct
32 Correct 99 ms 604 KB Output is correct
33 Correct 3 ms 604 KB Output is correct
34 Correct 3 ms 604 KB Output is correct
35 Correct 2 ms 588 KB Output is correct
36 Correct 7 ms 856 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 35 ms 560 KB Output is correct
3 Correct 21 ms 344 KB Output is correct
4 Correct 72 ms 604 KB Output is correct
5 Correct 16 ms 3176 KB Output is correct
6 Correct 24 ms 4120 KB Output is correct
7 Correct 25 ms 4396 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 98 ms 604 KB Output is correct
12 Correct 141 ms 254380 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 98 ms 628 KB Output is correct
15 Correct 35 ms 4644 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 58 ms 85852 KB Output is correct
2 Correct 43 ms 65616 KB Output is correct
3 Correct 151 ms 254032 KB Output is correct
4 Correct 97 ms 154372 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 99 ms 704 KB Output is correct
8 Correct 130 ms 254296 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 440 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 372 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 7 ms 604 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 3 ms 604 KB Output is correct
23 Correct 36 ms 552 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 5 ms 604 KB Output is correct
26 Correct 20 ms 348 KB Output is correct
27 Correct 73 ms 604 KB Output is correct
28 Correct 13 ms 600 KB Output is correct
29 Correct 98 ms 604 KB Output is correct
30 Correct 3 ms 600 KB Output is correct
31 Correct 52 ms 600 KB Output is correct
32 Correct 99 ms 604 KB Output is correct
33 Correct 3 ms 604 KB Output is correct
34 Correct 3 ms 604 KB Output is correct
35 Correct 2 ms 588 KB Output is correct
36 Correct 7 ms 856 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 35 ms 560 KB Output is correct
39 Correct 21 ms 344 KB Output is correct
40 Correct 72 ms 604 KB Output is correct
41 Correct 16 ms 3176 KB Output is correct
42 Correct 24 ms 4120 KB Output is correct
43 Correct 25 ms 4396 KB Output is correct
44 Correct 0 ms 348 KB Output is correct
45 Correct 0 ms 348 KB Output is correct
46 Correct 0 ms 348 KB Output is correct
47 Correct 98 ms 604 KB Output is correct
48 Correct 141 ms 254380 KB Output is correct
49 Correct 0 ms 348 KB Output is correct
50 Correct 98 ms 628 KB Output is correct
51 Correct 35 ms 4644 KB Output is correct
52 Correct 58 ms 85852 KB Output is correct
53 Correct 43 ms 65616 KB Output is correct
54 Correct 151 ms 254032 KB Output is correct
55 Correct 97 ms 154372 KB Output is correct
56 Correct 0 ms 348 KB Output is correct
57 Correct 0 ms 348 KB Output is correct
58 Correct 99 ms 704 KB Output is correct
59 Correct 130 ms 254296 KB Output is correct
60 Incorrect 25 ms 3920 KB Output isn't correct
61 Halted 0 ms 0 KB -