제출 #1263303

#제출 시각아이디문제언어결과실행 시간메모리
1263303viduxTrains (BOI24_trains)C++17
16 / 100
13 ms8264 KiB
#include <bits/stdc++.h>
using namespace std;
#define SINGLE_TEST 1

typedef long long ll;
typedef unsigned long long ull; 
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;

#define FOR(i, n) for (int(i) = 0; (i) < (n); ++(i))
#define REP(i, k, n) for (int(i) = (k); (i) <= (n); ++(i))
#define REPR(i, k, n) for (int(i) = (k); (i) >= (n); --(i))
#define FORR(x, arr) for (auto &x : arr)
#define FORR2(x, y, arr) for (auto &[x, y] : arr)
#define ALL(a) (a.begin()), (a.end())
#define RALL(a) (a.rbegin()), (a.rend())
#define REVERSE(v) reverse(ALL(v))
#define SZ(x) (int)(x).size()
#define fi first
#define se second
#define debug(x) cerr << #x << " = " << (x) << endl

const int MOD = 1e9 + 7;
const int INF = 1e9;
const ll LLINF = 1e18;

void solve() {
	int n; cin >> n;
	vl d(n), x(n);
	FOR(i, n) cin >> d[i] >> x[i];
	vector<unordered_map<int, ll>> v(n);
	vl ways(n+1);
	ways[0] = 1;
	ways[1] = MOD-1;
	ll ans = 0, cur = 0;
	FOR(i, n) {
		cur = (cur+ways[i]+MOD)%MOD;
		ans = (ans+cur) % MOD;
		if (d[i] && x[i]) {
			int end = min((ll)n, i+d[i]*x[i]+1);
			ways[i+1] = (ways[i+1]+cur)%MOD;
			ways[end] = (ways[end]-cur+MOD)%MOD;
		}
	}
	cout << ans << endl;
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

#if SINGLE_TEST
	solve();
#else
	int t;
	cin >> t;
	while (t--) {
		solve();
	}
#endif

	return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...