Submission #1000133

# Submission time Handle Problem Language Result Execution time Memory
1000133 2024-06-16T17:25:37 Z OAleksa Trains (BOI24_trains) C++14
58 / 100
87 ms 7784 KB
#include <bits/stdc++.h>
#define f first
#define s second
#define int long long
using namespace std;
const int N = 1e5 + 69;
const int B = 320;
const int mod = 1e9 + 7;
int n, d[N], x[N], dp[N];
vector<int> cnt[B];
vector<tuple<int, int, int>> who[N];
int add(int x, int y) {
	x += y;
	if (x >= mod)
		x -= mod;
	return x;
}
int sub(int x, int y) {
	x -= y;
	x = (x + 100 * mod) % mod;
	return x;
}
signed main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int tt = 1;
	//cin >> tt;
	while (tt--) {
		cin >> n;
		for (int i = 1;i <= n;i++) {
			cin >> d[i] >> x[i];
			x[i] = min(x[i], n);
		}
		for (int i = 1;i < B;i++)
			cnt[i].resize(i);
		dp[1] = 1;
		for (int i = 1;i <= n;i++) {
			for (auto j : who[i]) {
				int a, b, c;
				tie(a, b, c) = j;
				cnt[a][b] = sub(cnt[a][b], c);
			}
			if (d[i] >= B) {
				for (int j = i + d[i], j1 = 1;j <= n && j1 <= x[i];j += d[i], j1++) 
					dp[j] = add(dp[j], dp[i]);
			}
			else {
				for (int j = 1;j < B;j++) {
					int x = i % j;
					dp[i] = add(dp[i], cnt[j][x]);
				}
				if (d[i] != 0) {
					int when = i + x[i] * d[i];
					if (when < n) 
						who[when + 1].push_back({d[i], i % d[i], dp[i]});
					cnt[d[i]][i % d[i]] = add(cnt[d[i]][i % d[i]], dp[i]);
				}
			}
		}
		int ans = 0;
		for (int i = 1;i <= n;i++)
			ans = add(ans, dp[i]);
		cout << ans;
	}
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4952 KB Output is correct
2 Correct 1 ms 4956 KB Output is correct
3 Correct 1 ms 4956 KB Output is correct
4 Correct 1 ms 4956 KB Output is correct
5 Correct 1 ms 4956 KB Output is correct
6 Correct 1 ms 4956 KB Output is correct
7 Correct 1 ms 4956 KB Output is correct
8 Correct 1 ms 4956 KB Output is correct
9 Correct 1 ms 4956 KB Output is correct
10 Correct 1 ms 4956 KB Output is correct
11 Correct 1 ms 4956 KB Output is correct
12 Correct 1 ms 4956 KB Output is correct
13 Correct 1 ms 4956 KB Output is correct
14 Correct 1 ms 4956 KB Output is correct
15 Correct 1 ms 4956 KB Output is correct
16 Correct 2 ms 4956 KB Output is correct
17 Correct 1 ms 4956 KB Output is correct
18 Correct 1 ms 4956 KB Output is correct
19 Correct 1 ms 4956 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4952 KB Output is correct
2 Correct 1 ms 4956 KB Output is correct
3 Correct 1 ms 4956 KB Output is correct
4 Correct 1 ms 4956 KB Output is correct
5 Correct 1 ms 4956 KB Output is correct
6 Correct 1 ms 4956 KB Output is correct
7 Correct 1 ms 4956 KB Output is correct
8 Correct 1 ms 4956 KB Output is correct
9 Correct 1 ms 4956 KB Output is correct
10 Correct 1 ms 4956 KB Output is correct
11 Correct 1 ms 4956 KB Output is correct
12 Correct 1 ms 4956 KB Output is correct
13 Correct 1 ms 4956 KB Output is correct
14 Correct 1 ms 4956 KB Output is correct
15 Correct 1 ms 4956 KB Output is correct
16 Correct 2 ms 4956 KB Output is correct
17 Correct 1 ms 4956 KB Output is correct
18 Correct 1 ms 4956 KB Output is correct
19 Correct 1 ms 4956 KB Output is correct
20 Correct 9 ms 5212 KB Output is correct
21 Incorrect 2 ms 4956 KB Output isn't correct
22 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4952 KB Output is correct
2 Correct 6 ms 4956 KB Output is correct
3 Correct 5 ms 4956 KB Output is correct
4 Correct 8 ms 4956 KB Output is correct
5 Correct 70 ms 7784 KB Output is correct
6 Correct 86 ms 5548 KB Output is correct
7 Correct 86 ms 5844 KB Output is correct
8 Correct 1 ms 4952 KB Output is correct
9 Correct 1 ms 4956 KB Output is correct
10 Correct 1 ms 4952 KB Output is correct
11 Correct 10 ms 4956 KB Output is correct
12 Correct 87 ms 5516 KB Output is correct
13 Correct 1 ms 4956 KB Output is correct
14 Correct 10 ms 4956 KB Output is correct
15 Correct 86 ms 5468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 42 ms 4956 KB Output is correct
2 Correct 35 ms 4956 KB Output is correct
3 Correct 86 ms 5468 KB Output is correct
4 Correct 62 ms 5208 KB Output is correct
5 Correct 1 ms 4956 KB Output is correct
6 Correct 1 ms 5108 KB Output is correct
7 Correct 10 ms 4956 KB Output is correct
8 Correct 86 ms 5464 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4952 KB Output is correct
2 Correct 1 ms 4956 KB Output is correct
3 Correct 1 ms 4956 KB Output is correct
4 Correct 1 ms 4956 KB Output is correct
5 Correct 1 ms 4956 KB Output is correct
6 Correct 1 ms 4956 KB Output is correct
7 Correct 1 ms 4956 KB Output is correct
8 Correct 1 ms 4956 KB Output is correct
9 Correct 1 ms 4956 KB Output is correct
10 Correct 1 ms 4956 KB Output is correct
11 Correct 1 ms 4956 KB Output is correct
12 Correct 1 ms 4956 KB Output is correct
13 Correct 1 ms 4956 KB Output is correct
14 Correct 1 ms 4956 KB Output is correct
15 Correct 1 ms 4956 KB Output is correct
16 Correct 2 ms 4956 KB Output is correct
17 Correct 1 ms 4956 KB Output is correct
18 Correct 1 ms 4956 KB Output is correct
19 Correct 1 ms 4956 KB Output is correct
20 Correct 9 ms 5212 KB Output is correct
21 Incorrect 2 ms 4956 KB Output isn't correct
22 Halted 0 ms 0 KB -