Submission #702628

# Submission time Handle Problem Language Result Execution time Memory
702628 2023-02-24T15:47:49 Z a_aguilo Fancy Fence (CEOI20_fancyfence) C++14
0 / 100
2 ms 340 KB
#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 time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 1 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 1 ms 308 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 1 ms 312 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 1 ms 312 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 1 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -