Submission #936348

#TimeUsernameProblemLanguageResultExecution timeMemory
936348VMaksimoski008Fancy Fence (CEOI20_fancyfence)C++14
27 / 100
70 ms3128 KiB
#include <bits/stdc++.h> #define sz(x) (int)x.size() #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() //#define int long long using namespace std; using ll = long long; using ull = unsigned long long; using ld = long double; using pii = pair<int, int>; using pll = pair<ll, ll>; const int mod = 1e9 + 7; const int inv = 500000004; const int LOG = 20; const int maxn = 1e5 + 5; const double eps = 1e-9; int32_t main() { int n; cin >> n; set<int> diff; vector<int> h(n), w(n); for(int &x : h) cin >> x, diff.insert(x); for(int &x : w) cin >> x; auto f = [&](ll a, ll b) { ll p1 = 1ll * a * (a + 1) % mod * inv % mod; ll p2 = 1ll * b * (b + 1) % mod * inv % mod; return (p1 * p2) % mod; }; if(diff.size() == 1) { ll W = 0; for(int &x : w) W += x, W %= mod; cout << f(W, h[0]) << '\n'; return 0; } ll ans = 0; for(int i=0; i<n; i++) { ll W = 0; ll H = h[i]; for(int j=i; j<n; j++) { W += w[j]; H = min(H, 1ll * h[j]); ll res = (f(W, H) - f(H, W-w[i]) + mod - f(H, W-w[j]) + mod + f(H, W-w[i]-w[j])) % mod; if(i == j) res = f(W, H); ans += res; ans %= mod; } } cout << ans << '\n'; return 0; }
#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...