提出 #28322862
ソースコード 拡げる
// #include <atcoder/all>
// using namespace atcoder;
// using mint = modint998244353;
// using mint = modint1000000007;
#include <bits/stdc++.h>
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rep2(i,k,n) for (int i = (k); i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
// using P = pair<ll,ll>;
const ll INF = (ll)1e18;
// const int INF = (int)1e9+7;
template<typename T>
void chmin(T &a, T b) { a = min(a, b); }
template<typename T>
void chmax(T &a, T b) { a = max(a, b); }
template<typename T>
void print(vector<T> v) {
int n = v.size();
rep(i,n) {
if (i == 0) cout << v[i];
else cout << ' ' << v[i];
}
cout << endl;
}
void solve() {
int n;
cin >> n;
vector<ll> a(n), b(n);
const ll MAX = 3005;
rep(i,n) cin >> a[i];
rep(i,n) cin >> b[i];
const ll MOD = 998244353;
vector<vector<ll>> dp(n, vector<ll>(MAX, 0));
rep2(x,a[0],b[0]+1) dp[0][x] = 1;
rep2(i,1,n) {
rep2(x,a[i],b[i]+1) {
if (x == a[i]) {
rep2(k,a[i-1],x+1) {
dp[i][x] += dp[i-1][k];
dp[i][x] %= MOD;
}
} else {
dp[i][x] = (dp[i-1][x] + dp[i][x-1]) % MOD;
}
}
}
ll ans = 0;
rep(i,MAX) {
ans += dp[n-1][i];
ans %= MOD;
}
cout << ans << endl;
}
int main() {
solve();
return 0;
}
提出情報
ジャッジ結果
| セット名 |
Sample |
All |
| 得点 / 配点 |
0 / 0 |
400 / 400 |
| 結果 |
|
|
| セット名 |
テストケース |
| Sample |
00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt |
| All |
00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 01_small_00.txt, 01_small_01.txt, 01_small_02.txt, 01_small_03.txt, 01_small_04.txt, 01_small_05.txt, 01_small_06.txt, 01_small_07.txt, 02_random_00.txt, 02_random_01.txt, 02_random_02.txt, 03_same_00.txt, 03_same_01.txt, 04_min_00.txt, 04_min_01.txt, 05_max_00.txt, 05_max_01.txt, 06_minmax_00.txt |
| ケース名 |
結果 |
実行時間 |
メモリ |
| 00_sample_00.txt |
AC |
5 ms |
3656 KiB |
| 00_sample_01.txt |
AC |
2 ms |
3492 KiB |
| 00_sample_02.txt |
AC |
2 ms |
3684 KiB |
| 01_small_00.txt |
AC |
2 ms |
3620 KiB |
| 01_small_01.txt |
AC |
2 ms |
3724 KiB |
| 01_small_02.txt |
AC |
2 ms |
3728 KiB |
| 01_small_03.txt |
AC |
2 ms |
3568 KiB |
| 01_small_04.txt |
AC |
2 ms |
3536 KiB |
| 01_small_05.txt |
AC |
67 ms |
73640 KiB |
| 01_small_06.txt |
AC |
66 ms |
73736 KiB |
| 01_small_07.txt |
AC |
65 ms |
73636 KiB |
| 02_random_00.txt |
AC |
53 ms |
73656 KiB |
| 02_random_01.txt |
AC |
58 ms |
73500 KiB |
| 02_random_02.txt |
AC |
52 ms |
73740 KiB |
| 03_same_00.txt |
AC |
54 ms |
73736 KiB |
| 03_same_01.txt |
AC |
58 ms |
73524 KiB |
| 04_min_00.txt |
AC |
56 ms |
73648 KiB |
| 04_min_01.txt |
AC |
68 ms |
73732 KiB |
| 05_max_00.txt |
AC |
57 ms |
73552 KiB |
| 05_max_01.txt |
AC |
75 ms |
73588 KiB |
| 06_minmax_00.txt |
AC |
89 ms |
73524 KiB |