Submission #1058279

# Submission time Handle Problem Language Result Execution time Memory
1058279 2024-08-14T09:12:44 Z ZeroCool Trains (BOI24_trains) C++14
100 / 100
111 ms 239408 KB
#include <bits/stdc++.h>

using namespace std;

#define ar array
#define int long long
#define ld long double
#define crash assert(69 == 420)

const int MOD = 1e9 + 7;
const int INF = 1e9;

const int N = 1e5 + 20;
const int K = 300;
const int LOG = 20;

int n;

int dp[N];
int ans;
int sum[K][N];

void upd(int i,int x){
	for(int j = 0;j < K;j++){
		sum[j][i] = x;
		if(i + j < n)sum[j][i] += sum[j][i + j], sum[j][i] %= MOD;
	}
}


signed main(){ios_base::sync_with_stdio(false);cin.tie(0);
	cin>>n;
	int d[n], t[n];
	for(int i = 0;i < n;i++)cin>>d[i]>>t[i];
	for(int i = n - 1;i >= 0;i--){
		dp[i] = 1;
		if(d[i] == 0){
			upd(i, dp[i]);
			continue;
		}
		if(d[i] >= K){
			for(int j = 1;j <= t[i] && i + j * d[i] < n;j++)dp[i] += dp[i + j * d[i]], dp[i] %= MOD;
		}else{
			int l = i + d[i], r = i + (t[i] + 1) * d[i];
			if(l < n)dp[i] += sum[d[i]][l];
			if(r < n)dp[i] -= sum[d[i]][r];
			dp[i] = (dp[i] % MOD + MOD) % MOD;
		}
		upd(i, dp[i]);
		
	}
//	for(int i = 0;i  <n;i++)cout<<dp[i]<<" ";
	//cout<<'\n';
	cout<<dp[0];
}
# Verdict Execution time Memory Grader output
1 Correct 15 ms 209756 KB Output is correct
2 Correct 17 ms 211804 KB Output is correct
3 Correct 15 ms 211932 KB Output is correct
4 Correct 15 ms 215896 KB Output is correct
5 Correct 16 ms 213848 KB Output is correct
6 Correct 16 ms 215924 KB Output is correct
7 Correct 16 ms 215856 KB Output is correct
8 Correct 15 ms 213852 KB Output is correct
9 Correct 17 ms 213852 KB Output is correct
10 Correct 15 ms 213848 KB Output is correct
11 Correct 15 ms 215900 KB Output is correct
12 Correct 15 ms 213880 KB Output is correct
13 Correct 15 ms 215836 KB Output is correct
14 Correct 17 ms 213936 KB Output is correct
15 Correct 16 ms 215824 KB Output is correct
16 Correct 15 ms 215912 KB Output is correct
17 Correct 15 ms 215904 KB Output is correct
18 Correct 16 ms 213780 KB Output is correct
19 Correct 15 ms 215896 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 209756 KB Output is correct
2 Correct 17 ms 211804 KB Output is correct
3 Correct 15 ms 211932 KB Output is correct
4 Correct 15 ms 215896 KB Output is correct
5 Correct 16 ms 213848 KB Output is correct
6 Correct 16 ms 215924 KB Output is correct
7 Correct 16 ms 215856 KB Output is correct
8 Correct 15 ms 213852 KB Output is correct
9 Correct 17 ms 213852 KB Output is correct
10 Correct 15 ms 213848 KB Output is correct
11 Correct 15 ms 215900 KB Output is correct
12 Correct 15 ms 213880 KB Output is correct
13 Correct 15 ms 215836 KB Output is correct
14 Correct 17 ms 213936 KB Output is correct
15 Correct 16 ms 215824 KB Output is correct
16 Correct 15 ms 215912 KB Output is correct
17 Correct 15 ms 215904 KB Output is correct
18 Correct 16 ms 213780 KB Output is correct
19 Correct 15 ms 215896 KB Output is correct
20 Correct 23 ms 215776 KB Output is correct
21 Correct 20 ms 214620 KB Output is correct
22 Correct 22 ms 216412 KB Output is correct
23 Correct 21 ms 217336 KB Output is correct
24 Correct 18 ms 214876 KB Output is correct
25 Correct 21 ms 217892 KB Output is correct
26 Correct 18 ms 215132 KB Output is correct
27 Correct 21 ms 217908 KB Output is correct
28 Correct 23 ms 216412 KB Output is correct
29 Correct 22 ms 218196 KB Output is correct
30 Correct 22 ms 218204 KB Output is correct
31 Correct 22 ms 218204 KB Output is correct
32 Correct 22 ms 216404 KB Output is correct
33 Correct 22 ms 218060 KB Output is correct
34 Correct 22 ms 216400 KB Output is correct
35 Correct 22 ms 218220 KB Output is correct
36 Correct 22 ms 216244 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 215868 KB Output is correct
2 Correct 22 ms 217456 KB Output is correct
3 Correct 18 ms 214872 KB Output is correct
4 Correct 23 ms 215888 KB Output is correct
5 Correct 68 ms 232036 KB Output is correct
6 Correct 89 ms 237580 KB Output is correct
7 Correct 93 ms 237648 KB Output is correct
8 Correct 14 ms 193628 KB Output is correct
9 Correct 14 ms 195648 KB Output is correct
10 Correct 14 ms 195676 KB Output is correct
11 Correct 21 ms 199772 KB Output is correct
12 Correct 91 ms 237444 KB Output is correct
13 Correct 14 ms 193624 KB Output is correct
14 Correct 26 ms 198012 KB Output is correct
15 Correct 89 ms 237656 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 50 ms 215892 KB Output is correct
2 Correct 45 ms 211280 KB Output is correct
3 Correct 95 ms 237652 KB Output is correct
4 Correct 65 ms 229728 KB Output is correct
5 Correct 18 ms 209756 KB Output is correct
6 Correct 15 ms 211768 KB Output is correct
7 Correct 22 ms 218196 KB Output is correct
8 Correct 85 ms 237648 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 209756 KB Output is correct
2 Correct 17 ms 211804 KB Output is correct
3 Correct 15 ms 211932 KB Output is correct
4 Correct 15 ms 215896 KB Output is correct
5 Correct 16 ms 213848 KB Output is correct
6 Correct 16 ms 215924 KB Output is correct
7 Correct 16 ms 215856 KB Output is correct
8 Correct 15 ms 213852 KB Output is correct
9 Correct 17 ms 213852 KB Output is correct
10 Correct 15 ms 213848 KB Output is correct
11 Correct 15 ms 215900 KB Output is correct
12 Correct 15 ms 213880 KB Output is correct
13 Correct 15 ms 215836 KB Output is correct
14 Correct 17 ms 213936 KB Output is correct
15 Correct 16 ms 215824 KB Output is correct
16 Correct 15 ms 215912 KB Output is correct
17 Correct 15 ms 215904 KB Output is correct
18 Correct 16 ms 213780 KB Output is correct
19 Correct 15 ms 215896 KB Output is correct
20 Correct 23 ms 215776 KB Output is correct
21 Correct 20 ms 214620 KB Output is correct
22 Correct 22 ms 216412 KB Output is correct
23 Correct 21 ms 217336 KB Output is correct
24 Correct 18 ms 214876 KB Output is correct
25 Correct 21 ms 217892 KB Output is correct
26 Correct 18 ms 215132 KB Output is correct
27 Correct 21 ms 217908 KB Output is correct
28 Correct 23 ms 216412 KB Output is correct
29 Correct 22 ms 218196 KB Output is correct
30 Correct 22 ms 218204 KB Output is correct
31 Correct 22 ms 218204 KB Output is correct
32 Correct 22 ms 216404 KB Output is correct
33 Correct 22 ms 218060 KB Output is correct
34 Correct 22 ms 216400 KB Output is correct
35 Correct 22 ms 218220 KB Output is correct
36 Correct 22 ms 216244 KB Output is correct
37 Correct 15 ms 215868 KB Output is correct
38 Correct 22 ms 217456 KB Output is correct
39 Correct 18 ms 214872 KB Output is correct
40 Correct 23 ms 215888 KB Output is correct
41 Correct 68 ms 232036 KB Output is correct
42 Correct 89 ms 237580 KB Output is correct
43 Correct 93 ms 237648 KB Output is correct
44 Correct 14 ms 193628 KB Output is correct
45 Correct 14 ms 195648 KB Output is correct
46 Correct 14 ms 195676 KB Output is correct
47 Correct 21 ms 199772 KB Output is correct
48 Correct 91 ms 237444 KB Output is correct
49 Correct 14 ms 193624 KB Output is correct
50 Correct 26 ms 198012 KB Output is correct
51 Correct 89 ms 237656 KB Output is correct
52 Correct 50 ms 215892 KB Output is correct
53 Correct 45 ms 211280 KB Output is correct
54 Correct 95 ms 237652 KB Output is correct
55 Correct 65 ms 229728 KB Output is correct
56 Correct 18 ms 209756 KB Output is correct
57 Correct 15 ms 211768 KB Output is correct
58 Correct 22 ms 218196 KB Output is correct
59 Correct 85 ms 237648 KB Output is correct
60 Correct 86 ms 234528 KB Output is correct
61 Correct 89 ms 238492 KB Output is correct
62 Correct 90 ms 238164 KB Output is correct
63 Correct 86 ms 238312 KB Output is correct
64 Correct 89 ms 239408 KB Output is correct
65 Correct 111 ms 238840 KB Output is correct
66 Correct 88 ms 238816 KB Output is correct
67 Correct 92 ms 239184 KB Output is correct
68 Correct 85 ms 238664 KB Output is correct
69 Correct 93 ms 238236 KB Output is correct
70 Correct 87 ms 238804 KB Output is correct
71 Correct 89 ms 238420 KB Output is correct
72 Correct 90 ms 238552 KB Output is correct