이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define ll long long
#define ar array
#define db double
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define rint(l, r) uniform_int_distribution<int>(l, r)(rng)
template<typename T> bool ckmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; }
template<typename T> bool ckmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }
const int mod = 1e9+7;
int f(int x) {
return ((ll)x*(x+1)/2)%mod;
}
int mul(int a, int b) {
return (ll)a*b%mod;
}
void fadd(int &a, int b) {
a += b;
if (a >= mod) a -= mod;
}
void test_case() {
int n; cin >> n;
vector<int> h(n), w(n);
for (int &x : h) cin >> x;
for (int &x : w) cin >> x;
int ans = 0;
for (int i = 0; i < n; i++) {
fadd(ans, mul(f(h[i]), f(w[i])));
int he = h[i];
for (int j = i-1; j >= 0; j--) {
ckmin(he, h[j]);
fadd(ans, mul(w[i], mul(w[j], f(he))));
}
}
cout << ans << '\n';
}
int main() {
cin.tie(0)->sync_with_stdio(0);
int t = 1;
// cin >> t;
while (t--) test_case();
}
# | 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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |