// ~~ icebear ~~
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
template<class T>
bool minimize(T &a, const T &b) {
if (a > b) return a = b, true;
return false;
}
template<class T>
bool maximize(T &a, const T &b) {
if (a < b) return a = b, true;
return false;
}
#define FOR(i,a,b) for(int i=(a); i<=(b); ++i)
#define FORR(i,a,b) for(int i=(a); i>=(b); --i)
#define REP(i, n) for(int i=0; i<(n); ++i)
#define RED(i, n) for(int i=(n)-1; i>=0; --i)
#define MASK(i) (1LL << (i))
#define BIT(S, i) (((S) >> (i)) & 1)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define task "icebear"
const int MOD = 1e9 + 7;
const int inf = 1e9 + 27092008;
const ll INF = 1e18 + 27092008;
const int N = 1e4 + 5;
int n, a[N], b[N];
int dpL[N][1005], dpR[N][1005];
int pL[1005], pR[1005];
void init(void) {
cin >> n;
FOR(i, 1, n) cin >> a[i];
FOR(i, 1, n) cin >> b[i];
}
void process(void) {
dpL[0][0] = dpR[n + 1][0] = 1;
FOR(i, 0, n - 1) FOR(j, 0, 1000) {
(dpL[i + 1][max(a[i + 1], j)] += dpL[i][j]) %= MOD;
(dpL[i + 1][max(b[i + 1], j)] += dpL[i][j]) %= MOD;
}
FORR(i, n + 1, 2) FOR(j, 0, 1000) {
(dpR[i - 1][max(a[i - 1], j)] += dpR[i][j]) %= MOD;
(dpR[i - 1][max(b[i - 1], j)] += dpR[i][j]) %= MOD;
}
int ans = 0;
FOR(i, 2, n - 1) {
// FOR(j, 1, 1000) pL[j] = (pL[j - 1] + dpL[i - 1][j]) % MOD;
// FOR(j, 1, 1000) pR[j] = (pR[j - 1] + dpR[i + 1][j]) % MOD;
// int res = 0;
FOR(j, 1, 1000) FOR(k, 1, 1000) if (dpL[i - 1][j] > 0 && dpR[i + 1][k] > 0) {
int v1 = max(0, min(j, k) - a[i]);
int v2 = max(0, min(j, k) - b[i]);
(ans += 1LL * (v1 + v2) * dpL[i - 1][j] % MOD * dpR[i + 1][k] % MOD) %= MOD;
// (res += 1LL * (v1 + v2) * dpL[i - 1][j] % MOD * dpR[i + 1][k] % MOD) %= MOD;
}
// cout << i << ' ' << res << '\n';
}
cout << ans;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
if (fopen(task".inp", "r")) {
freopen(task".inp", "r", stdin);
freopen(task".out", "w", stdout);
}
int tc = 1;
// cin >> tc;
while(tc--) {
init();
process();
}
return 0;
}
Compilation message (stderr)
Main.cpp: In function 'int main()':
Main.cpp:81:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
81 | freopen(task".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:82:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
82 | freopen(task".out", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |