Submission #997896

# Submission time Handle Problem Language Result Execution time Memory
997896 2024-06-13T05:11:32 Z imarn Trains (BOI24_trains) C++14
100 / 100
437 ms 9808 KB
#include<bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC target("avx2")
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define plx pair<ll,int>
#define f first
#define s second
#define pb push_back
#define all(x) x.begin(),x.end()
using namespace std;
const int blc=351,inf=1e9+7;
ll sum[351][351]{0};
priority_queue<pair<ll,ll>,vector<pair<ll,ll>>,greater<pair<ll,ll>>>pq[blc][blc];
int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);
    int n;cin>>n;pll g[n+1];ll dp[n]={0};dp[0]=1;
    for(int i=0;i<n;i++)cin>>g[i].f>>g[i].s;ll ans=0;
    for(int i=0;i<n;i++){
        for(int j=1;j<blc;j++){
            while(!pq[i%j][j].empty()&&pq[i%j][j].top().f<i)sum[i%j][j]-=pq[i%j][j].top().s,pq[i%j][j].pop(),sum[i%j][j]%=inf;
        }
        for(int j=1;j<blc;j++){
            dp[i]+=sum[i%j][j];dp[i]%=inf;
        }
        if(g[i].f>=blc){int cur=i;
            for(int j=1;j<=g[i].s;j++){
                cur+=g[i].f;if(cur>=n)break;
                dp[cur]+=dp[i];dp[cur]%=inf;
            }
        }
        else if(g[i].f!=0){
            pq[i%g[i].f][g[i].f].push({i+g[i].f*g[i].s,dp[i]});
            sum[i%g[i].f][g[i].f]+=dp[i];sum[i%g[i].f][g[i].f]%=inf;
        }
        ans+=dp[i];ans%=inf;
    }cout<<(ans%inf+inf)%inf;
}

# Verdict Execution time Memory Grader output
1 Correct 1 ms 4700 KB Output is correct
2 Correct 1 ms 4700 KB Output is correct
3 Correct 1 ms 4700 KB Output is correct
4 Correct 1 ms 4708 KB Output is correct
5 Correct 1 ms 4700 KB Output is correct
6 Correct 1 ms 4700 KB Output is correct
7 Correct 1 ms 4700 KB Output is correct
8 Correct 1 ms 4696 KB Output is correct
9 Correct 1 ms 4700 KB Output is correct
10 Correct 1 ms 4700 KB Output is correct
11 Correct 1 ms 4700 KB Output is correct
12 Correct 1 ms 4700 KB Output is correct
13 Correct 1 ms 4700 KB Output is correct
14 Correct 1 ms 4700 KB Output is correct
15 Correct 1 ms 4700 KB Output is correct
16 Correct 1 ms 4700 KB Output is correct
17 Correct 1 ms 4700 KB Output is correct
18 Correct 1 ms 4720 KB Output is correct
19 Correct 1 ms 4700 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4700 KB Output is correct
2 Correct 1 ms 4700 KB Output is correct
3 Correct 1 ms 4700 KB Output is correct
4 Correct 1 ms 4708 KB Output is correct
5 Correct 1 ms 4700 KB Output is correct
6 Correct 1 ms 4700 KB Output is correct
7 Correct 1 ms 4700 KB Output is correct
8 Correct 1 ms 4696 KB Output is correct
9 Correct 1 ms 4700 KB Output is correct
10 Correct 1 ms 4700 KB Output is correct
11 Correct 1 ms 4700 KB Output is correct
12 Correct 1 ms 4700 KB Output is correct
13 Correct 1 ms 4700 KB Output is correct
14 Correct 1 ms 4700 KB Output is correct
15 Correct 1 ms 4700 KB Output is correct
16 Correct 1 ms 4700 KB Output is correct
17 Correct 1 ms 4700 KB Output is correct
18 Correct 1 ms 4720 KB Output is correct
19 Correct 1 ms 4700 KB Output is correct
20 Correct 23 ms 4956 KB Output is correct
21 Correct 9 ms 4956 KB Output is correct
22 Correct 32 ms 5748 KB Output is correct
23 Correct 17 ms 4956 KB Output is correct
24 Correct 12 ms 5212 KB Output is correct
25 Correct 28 ms 5092 KB Output is correct
26 Correct 12 ms 4956 KB Output is correct
27 Correct 22 ms 5236 KB Output is correct
28 Correct 26 ms 5204 KB Output is correct
29 Correct 26 ms 5464 KB Output is correct
30 Correct 27 ms 5468 KB Output is correct
31 Correct 27 ms 5208 KB Output is correct
32 Correct 31 ms 5212 KB Output is correct
33 Correct 33 ms 4952 KB Output is correct
34 Correct 26 ms 4956 KB Output is correct
35 Correct 27 ms 5116 KB Output is correct
36 Correct 32 ms 5204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4700 KB Output is correct
2 Correct 17 ms 4900 KB Output is correct
3 Correct 12 ms 4884 KB Output is correct
4 Correct 22 ms 5212 KB Output is correct
5 Correct 223 ms 6536 KB Output is correct
6 Correct 251 ms 9168 KB Output is correct
7 Correct 253 ms 9168 KB Output is correct
8 Correct 1 ms 4696 KB Output is correct
9 Correct 1 ms 4700 KB Output is correct
10 Correct 1 ms 4700 KB Output is correct
11 Correct 27 ms 5212 KB Output is correct
12 Correct 255 ms 9184 KB Output is correct
13 Correct 1 ms 4700 KB Output is correct
14 Correct 28 ms 5348 KB Output is correct
15 Correct 258 ms 9120 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 123 ms 6740 KB Output is correct
2 Correct 102 ms 6484 KB Output is correct
3 Correct 256 ms 8824 KB Output is correct
4 Correct 191 ms 7632 KB Output is correct
5 Correct 1 ms 4696 KB Output is correct
6 Correct 1 ms 4700 KB Output is correct
7 Correct 27 ms 5240 KB Output is correct
8 Correct 261 ms 9164 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4700 KB Output is correct
2 Correct 1 ms 4700 KB Output is correct
3 Correct 1 ms 4700 KB Output is correct
4 Correct 1 ms 4708 KB Output is correct
5 Correct 1 ms 4700 KB Output is correct
6 Correct 1 ms 4700 KB Output is correct
7 Correct 1 ms 4700 KB Output is correct
8 Correct 1 ms 4696 KB Output is correct
9 Correct 1 ms 4700 KB Output is correct
10 Correct 1 ms 4700 KB Output is correct
11 Correct 1 ms 4700 KB Output is correct
12 Correct 1 ms 4700 KB Output is correct
13 Correct 1 ms 4700 KB Output is correct
14 Correct 1 ms 4700 KB Output is correct
15 Correct 1 ms 4700 KB Output is correct
16 Correct 1 ms 4700 KB Output is correct
17 Correct 1 ms 4700 KB Output is correct
18 Correct 1 ms 4720 KB Output is correct
19 Correct 1 ms 4700 KB Output is correct
20 Correct 23 ms 4956 KB Output is correct
21 Correct 9 ms 4956 KB Output is correct
22 Correct 32 ms 5748 KB Output is correct
23 Correct 17 ms 4956 KB Output is correct
24 Correct 12 ms 5212 KB Output is correct
25 Correct 28 ms 5092 KB Output is correct
26 Correct 12 ms 4956 KB Output is correct
27 Correct 22 ms 5236 KB Output is correct
28 Correct 26 ms 5204 KB Output is correct
29 Correct 26 ms 5464 KB Output is correct
30 Correct 27 ms 5468 KB Output is correct
31 Correct 27 ms 5208 KB Output is correct
32 Correct 31 ms 5212 KB Output is correct
33 Correct 33 ms 4952 KB Output is correct
34 Correct 26 ms 4956 KB Output is correct
35 Correct 27 ms 5116 KB Output is correct
36 Correct 32 ms 5204 KB Output is correct
37 Correct 1 ms 4700 KB Output is correct
38 Correct 17 ms 4900 KB Output is correct
39 Correct 12 ms 4884 KB Output is correct
40 Correct 22 ms 5212 KB Output is correct
41 Correct 223 ms 6536 KB Output is correct
42 Correct 251 ms 9168 KB Output is correct
43 Correct 253 ms 9168 KB Output is correct
44 Correct 1 ms 4696 KB Output is correct
45 Correct 1 ms 4700 KB Output is correct
46 Correct 1 ms 4700 KB Output is correct
47 Correct 27 ms 5212 KB Output is correct
48 Correct 255 ms 9184 KB Output is correct
49 Correct 1 ms 4700 KB Output is correct
50 Correct 28 ms 5348 KB Output is correct
51 Correct 258 ms 9120 KB Output is correct
52 Correct 123 ms 6740 KB Output is correct
53 Correct 102 ms 6484 KB Output is correct
54 Correct 256 ms 8824 KB Output is correct
55 Correct 191 ms 7632 KB Output is correct
56 Correct 1 ms 4696 KB Output is correct
57 Correct 1 ms 4700 KB Output is correct
58 Correct 27 ms 5240 KB Output is correct
59 Correct 261 ms 9164 KB Output is correct
60 Correct 225 ms 8532 KB Output is correct
61 Correct 256 ms 9108 KB Output is correct
62 Correct 257 ms 7216 KB Output is correct
63 Correct 258 ms 9164 KB Output is correct
64 Correct 253 ms 7000 KB Output is correct
65 Correct 420 ms 8364 KB Output is correct
66 Correct 255 ms 8752 KB Output is correct
67 Correct 265 ms 7516 KB Output is correct
68 Correct 255 ms 8140 KB Output is correct
69 Correct 437 ms 9040 KB Output is correct
70 Correct 263 ms 7004 KB Output is correct
71 Correct 251 ms 7248 KB Output is correct
72 Correct 416 ms 9808 KB Output is correct