Submission #945678

#TimeUsernameProblemLanguageResultExecution timeMemory
945678Sandarach151Fancy Fence (CEOI20_fancyfence)C++17
60 / 100
18 ms1884 KiB
#include <bits/stdc++.h> using namespace std; #define int long long const int MODD = 1e9+7; const int INV = 5e8+4; int mult(int n){ int temp = 1; temp *= (n); temp %= MODD; temp *= (n+1); temp %= MODD; temp *= INV; temp %= MODD; return temp; } signed main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); int n; cin >> n; int h[n]; int w[n]; bool same = true; bool less = true; for(int i=0; i<n; i++){ cin >> h[i]; if(i>0 && h[i]!=h[i-1]){ same = false; } if(i>0 && h[i]<h[i-1]){ less = false; } } for(int i=0; i<n; i++){ cin >> w[i]; } if(n<=1000){ int ans = 0; for(int i=0; i<n; i++){ int temp = mult(w[i]); temp %= MODD; temp *= mult(h[i]); temp %= MODD; ans += temp; ans %= MODD; } for(int i=0; i<n; i++){ int minn = h[i]; for(int j=i+1; j<n; j++){ minn = min(minn, h[j]); int temp = w[i]*w[j]; temp %= MODD; temp *= mult(minn); temp %= MODD; ans += temp; ans %= MODD; } } cout << ans << '\n'; } else if(same){ int summ = 0; for(int i=0; i<n; i++){ summ += w[i]; summ %= MODD; } int ans = mult(h[0]); ans *= mult(summ); ans %= MODD; cout << ans << '\n'; } else if(less){ int ans = 0; for(int i=0; i<n; i++){ int temp = mult(w[i]); temp %= MODD; temp *= mult(h[i]); temp %= MODD; ans += temp; ans %= MODD; } int summ = 0; for(int i=0; i<n; i++){ summ += w[i]; summ %= MODD; } for(int i=0; i<n; i++){ summ -= w[i]; summ += MODD; summ %= MODD; int temp = w[i]*summ; temp %= MODD; temp *= mult(h[i]); temp %= MODD; ans += temp; ans %= MODD; } 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...