#include <bits/stdc++.h>
#define FAST_IO ios_base::sync_with_stdio(0); cin.tie(nullptr); cout.tie(nullptr)
#define FOR(i, begin, end) for(int i = (begin); i < (end); i++)
#define TSTS int ttt; cin >> ttt; while(ttt--) solve()
#define all(x) (x).begin(), (x).end()
#define le(vec) vec[vec.size()-1]
#define sz(x) ((int)((x).size()))
#define pb push_back
#define s second
#define f first
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef map<int, int> mii;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef pair<long double, long double> pdd;
const int INF=1e9, MOD=1e9+7, mod=998244353;
const ll LINF=1e18;
void setIO()
{
FAST_IO;
}
void setIO(string s)
{
FAST_IO;
freopen((s+".in").c_str(), "r", stdin);
freopen((s+".out").c_str(), "w", stdout);
}
const int N=1e3+10;
ll h[N], w[N], sm[N][N], mn[N][N];
int n;
ll eq(ll x)
{
return (x+1)*x/2%MOD;
}
int main()
{
setIO();
cin >> n;
FOR(i, 0, n) cin >> h[i];
FOR(i, 0, n) cin >> w[i];
FOR(i, 0, n)
{
sm[i][i]=w[i];
mn[i][i]=h[i];
FOR(j, i+1, n)
{
mn[i][j]=min(mn[i][j-1], h[j]);
sm[i][j]+=w[j];
sm[i][j]%=MOD;
}
}
ll ans=0;
FOR(i, 0, n)
{
ans+=eq(h[i])*eq(w[i])%MOD;
ans%=MOD;
FOR(j, i+1, n)
{
ans+=eq(sm[i][j])*eq(mn[i][j])%MOD;
ans-=eq(sm[i][j]-w[i])*eq(mn[i][j])%MOD;
ans-=eq(sm[i][j]-w[j])*eq(mn[i][j])%MOD;
ans+=eq(sm[i][j]-w[i]-w[j])*eq(mn[i][j])%MOD;
ans%=MOD;
}
}
cout << ans;
}
Compilation message
fancyfence.cpp: In function 'void setIO(std::string)':
fancyfence.cpp:32:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
32 | freopen((s+".in").c_str(), "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
fancyfence.cpp:33:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
33 | freopen((s+".out").c_str(), "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
320 KB |
Output is correct |
2 |
Correct |
17 ms |
14148 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
328 KB |
Output is correct |
2 |
Correct |
1 ms |
572 KB |
Output is correct |
3 |
Correct |
1 ms |
588 KB |
Output is correct |
4 |
Correct |
1 ms |
308 KB |
Output is correct |
5 |
Correct |
1 ms |
716 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Correct |
16 ms |
14220 KB |
Output is correct |
3 |
Runtime error |
1 ms |
460 KB |
Execution killed with signal 11 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
19 ms |
14156 KB |
Output is correct |
2 |
Runtime error |
2 ms |
588 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
316 KB |
Output is correct |
2 |
Correct |
16 ms |
14272 KB |
Output is correct |
3 |
Runtime error |
1 ms |
588 KB |
Execution killed with signal 11 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
320 KB |
Output is correct |
2 |
Correct |
17 ms |
14160 KB |
Output is correct |
3 |
Correct |
0 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
460 KB |
Output is correct |
5 |
Correct |
1 ms |
584 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
720 KB |
Output is correct |
8 |
Correct |
16 ms |
14132 KB |
Output is correct |
9 |
Correct |
17 ms |
14168 KB |
Output is correct |
10 |
Correct |
17 ms |
14132 KB |
Output is correct |
11 |
Correct |
1 ms |
1084 KB |
Output is correct |
12 |
Correct |
5 ms |
6220 KB |
Output is correct |
13 |
Correct |
18 ms |
14212 KB |
Output is correct |
14 |
Correct |
17 ms |
14204 KB |
Output is correct |
15 |
Correct |
16 ms |
14148 KB |
Output is correct |
16 |
Correct |
0 ms |
320 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
320 KB |
Output is correct |
2 |
Correct |
17 ms |
14148 KB |
Output is correct |
3 |
Correct |
1 ms |
320 KB |
Output is correct |
4 |
Correct |
17 ms |
14136 KB |
Output is correct |
5 |
Correct |
0 ms |
332 KB |
Output is correct |
6 |
Correct |
0 ms |
576 KB |
Output is correct |
7 |
Correct |
1 ms |
556 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
712 KB |
Output is correct |
10 |
Correct |
16 ms |
14212 KB |
Output is correct |
11 |
Runtime error |
1 ms |
472 KB |
Execution killed with signal 11 |
12 |
Halted |
0 ms |
0 KB |
- |