Submission #702628

#TimeUsernameProblemLanguageResultExecution timeMemory
702628a_aguiloFancy Fence (CEOI20_fancyfence)C++14
0 / 100
2 ms340 KiB
#include<bits/stdc++.h> using namespace std; int n; int MOD = 1e9 + 7; long long calcOwnRectangles(long long int h, long long int w){ long long chooseH = (h*(h+1)/2)%MOD; long long chooseW = (w*(w+1)/2)%MOD; long long ans = (chooseH*chooseW)%MOD; return ans; } long long getEndings(long long h, long long w){ long long WOptions = w; long long HOptions = (h*(h+1)/2)%MOD; long long ans = (WOptions*HOptions)%MOD; return ans; } int main(){ cin >> n; int heights[n]; int widths[n]; long long dp[n]; long long int ans = 0; for(int i = 0; i < n; ++i) cin >> heights[i]; for(int i = 0; i < n; ++i) cin >> widths[i]; vector<pair<long long int, long long int>> MyStack; MyStack.reserve(n); for(int i = 0; i < n; ++i){ long long int myH = heights[i]; long long int myW = widths[i]; int lPos = MyStack.size()-1; while(lPos >= 0 and MyStack[lPos].first > myH){ myW += MyStack[lPos].second; MyStack.pop_back(); lPos = MyStack.size()-1; } MyStack.push_back({myH, myW}); long long indepRectangles = calcOwnRectangles(myH, myW); ans += indepRectangles; ans %= MOD; //cout << ans << endl; dp[MyStack.size()-1] = getEndings(myH, myW); if(MyStack.size() == 1){ //Este es el primero continue; }else{ //Este NO es el primero --> para los rectángulos se pueden continuar los que acaban en el anterior ans += (dp[MyStack.size()-2]*myW)%MOD; ans %= MOD; //Tambien se puede hacer que el numero de los que acaban en esta posicion incorpore los que acaban en la anterior dp[MyStack.size()-1] += dp[MyStack.size()-2]; } } cout << ans << endl; 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...