Submission #1086030

# Submission time Handle Problem Language Result Execution time Memory
1086030 2024-09-09T10:17:18 Z Mr_Ph Trains (BOI24_trains) C++17
100 / 100
160 ms 7872 KB
#include<bits/stdc++.h>
using namespace std;
const int mod=(int)1e9+7; 
#define endl '\n'
#define all(arr) arr.begin(),arr.end()
#define allr(arr) arr.rbegin(),arr.rend()
#define sz size()
#define int long long
int dp[100002];
void iforgor()
{
    int n;
    cin>>n;
    dp[0]=1;
    int pog=sqrt(n);
    vector<vector<int>>dp1(pog,vector<int>(pog));
    // cout<<pog<<endl;
    vector<vector<array<int,3>>>nig(n);
    for(int i=0;i<n;i++)
    {
        int d,x;
        cin>>d>>x;
        for(int j=1;j<pog;j++){
            int lo=i%j;
            dp[i]+=dp1[j][lo];
            dp[i]%=mod;
        }
        for(auto j:nig[i])
        {
            int lo=j[2],dd=j[1],dp1m=j[0];
            dp1[dd][lo]=(dp1[dd][lo]-dp1m+mod)%mod;
        }
        if(x==0||d==0)continue;
        if(d>=pog){
            for(int j=i+d;j<n;j+=d)
            {
                x--;
                if(x<0)break;
                dp[j]+=dp[i];
                dp[j]%=mod;
            }
        }
        else
        {
            int lo=i%d;
            dp1[d][lo]+=dp[i];
            dp1[d][lo]%=mod;
            if((i+d*x)<n)nig[i+d*x].push_back({dp[i],d,lo});
        }
    }
    int ans=0;
    for(int i=0;i<n;i++)ans+=dp[i],ans%=mod;
    cout<<ans<<endl;
}   
signed main()
{
    ios_base::sync_with_stdio(false);   
    cin.tie(NULL);   
    int t=1;
    // cin>>t;
    while(t--)iforgor();
}   
# Verdict Execution time Memory Grader output
1 Correct 0 ms 600 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 464 KB Output is correct
8 Correct 1 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 348 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 348 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 600 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 464 KB Output is correct
8 Correct 1 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 348 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 348 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 4 ms 860 KB Output is correct
21 Correct 1 ms 632 KB Output is correct
22 Correct 6 ms 860 KB Output is correct
23 Correct 3 ms 604 KB Output is correct
24 Correct 2 ms 604 KB Output is correct
25 Correct 5 ms 860 KB Output is correct
26 Correct 2 ms 644 KB Output is correct
27 Correct 4 ms 896 KB Output is correct
28 Correct 6 ms 860 KB Output is correct
29 Correct 6 ms 964 KB Output is correct
30 Correct 6 ms 860 KB Output is correct
31 Correct 6 ms 860 KB Output is correct
32 Correct 6 ms 860 KB Output is correct
33 Correct 6 ms 1148 KB Output is correct
34 Correct 6 ms 860 KB Output is correct
35 Correct 6 ms 860 KB Output is correct
36 Correct 5 ms 956 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 3 ms 604 KB Output is correct
3 Correct 2 ms 604 KB Output is correct
4 Correct 5 ms 776 KB Output is correct
5 Correct 102 ms 6228 KB Output is correct
6 Correct 145 ms 5200 KB Output is correct
7 Correct 142 ms 5476 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 6 ms 912 KB Output is correct
12 Correct 141 ms 5576 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 6 ms 860 KB Output is correct
15 Correct 144 ms 5372 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 52 ms 2804 KB Output is correct
2 Correct 38 ms 2308 KB Output is correct
3 Correct 141 ms 5592 KB Output is correct
4 Correct 89 ms 4148 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 6 ms 860 KB Output is correct
8 Correct 144 ms 5460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 600 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 464 KB Output is correct
8 Correct 1 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 348 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 348 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 4 ms 860 KB Output is correct
21 Correct 1 ms 632 KB Output is correct
22 Correct 6 ms 860 KB Output is correct
23 Correct 3 ms 604 KB Output is correct
24 Correct 2 ms 604 KB Output is correct
25 Correct 5 ms 860 KB Output is correct
26 Correct 2 ms 644 KB Output is correct
27 Correct 4 ms 896 KB Output is correct
28 Correct 6 ms 860 KB Output is correct
29 Correct 6 ms 964 KB Output is correct
30 Correct 6 ms 860 KB Output is correct
31 Correct 6 ms 860 KB Output is correct
32 Correct 6 ms 860 KB Output is correct
33 Correct 6 ms 1148 KB Output is correct
34 Correct 6 ms 860 KB Output is correct
35 Correct 6 ms 860 KB Output is correct
36 Correct 5 ms 956 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 3 ms 604 KB Output is correct
39 Correct 2 ms 604 KB Output is correct
40 Correct 5 ms 776 KB Output is correct
41 Correct 102 ms 6228 KB Output is correct
42 Correct 145 ms 5200 KB Output is correct
43 Correct 142 ms 5476 KB Output is correct
44 Correct 0 ms 344 KB Output is correct
45 Correct 0 ms 348 KB Output is correct
46 Correct 0 ms 348 KB Output is correct
47 Correct 6 ms 912 KB Output is correct
48 Correct 141 ms 5576 KB Output is correct
49 Correct 0 ms 348 KB Output is correct
50 Correct 6 ms 860 KB Output is correct
51 Correct 144 ms 5372 KB Output is correct
52 Correct 52 ms 2804 KB Output is correct
53 Correct 38 ms 2308 KB Output is correct
54 Correct 141 ms 5592 KB Output is correct
55 Correct 89 ms 4148 KB Output is correct
56 Correct 0 ms 344 KB Output is correct
57 Correct 0 ms 348 KB Output is correct
58 Correct 6 ms 860 KB Output is correct
59 Correct 144 ms 5460 KB Output is correct
60 Correct 110 ms 4608 KB Output is correct
61 Correct 141 ms 5204 KB Output is correct
62 Correct 150 ms 7872 KB Output is correct
63 Correct 141 ms 5152 KB Output is correct
64 Correct 146 ms 6184 KB Output is correct
65 Correct 160 ms 5716 KB Output is correct
66 Correct 142 ms 5456 KB Output is correct
67 Correct 146 ms 5712 KB Output is correct
68 Correct 143 ms 5456 KB Output is correct
69 Correct 152 ms 7248 KB Output is correct
70 Correct 144 ms 5456 KB Output is correct
71 Correct 145 ms 5124 KB Output is correct
72 Correct 146 ms 5160 KB Output is correct