Submission #958908

#TimeUsernameProblemLanguageResultExecution timeMemory
958908TAhmed33Fancy Fence (CEOI20_fancyfence)C++98
30 / 100
1100 ms1428 KiB
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7; const int TWOINV = 5e8 + 4; const int MAXN = 1e5 + 25; int add (int a, int b) { a += b; if (a >= MOD) a -= MOD; return a; } int sub (int a, int b) { a -= b; if (a < 0) a += MOD; return a; } int mul (int a, int b) { return (a * 1ll * b) % MOD; } int h[MAXN], w[MAXN], n; int main () { ios::sync_with_stdio(0); cin.tie(0); cin >> n; for (int i = 1; i <= n; i++) cin >> h[i]; for (int i = 1; i <= n; i++) cin >> w[i]; int ans = 0; for (int i = 1; i <= n; i++) { int x = w[i], y = h[i]; x = mul(x, mul(x + 1, TWOINV)); y = mul(y, mul(y + 1, TWOINV)); ans = add(ans, mul(x, y)); } for (int i = 1; i <= n; i++) { for (int j = i + 1; j <= n; j++) { int x = *min_element(h + i, h + j + 1); x = mul(x, mul(x + 1, TWOINV)); int y = mul(w[i], w[j]); ans = add(ans, mul(x, y)); } } cout << ans << '\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...