-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathABC_179_D.cpp
More file actions
48 lines (40 loc) · 824 Bytes
/
ABC_179_D.cpp
File metadata and controls
48 lines (40 loc) · 824 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include <iostream>
#include <algorithm>
#include <vector>
#include <utility>
#include <cmath>
using namespace std;
long long dp[200001];
long long prefix[200001];
const int mod = 998244353;
int main()
{
int n, k;
cin >> n >> k;
vector<pair<int, int> > set;
for (int i = 0; i < k; i++)
{
int l, r;
cin >> l >> r;
set.push_back(make_pair(l, r));
}
sort(set.begin(), set.end());
// bottom up dp
dp[1] = 1;
prefix[1] = 1;
for (int i = 1; i <= n; i++)
{
for (int j = 0; j < k; j++)
{
int left = set[j].first;
int right = set[j].second;
int start = max(i - right - 1, 0);
int end = max(i - left, 0);
// (i - right) ~ (i - left) 까지의 합
dp[i] += prefix[end] - prefix[start] + mod;
dp[i] %= mod;
}
prefix[i] = (prefix[i - 1] + dp[i]) % mod;
}
cout << dp[n] << endl;
}