Submission #945716

# Submission time Handle Problem Language Result Execution time Memory
945716 2024-03-14T06:38:48 Z WongYiKai Fancy Fence (CEOI20_fancyfence) C++14
100 / 100
24 ms 6492 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main(){
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	ll n;
	ll m = 1000000007;
	cin >> n;
	ll h[n+5],w[n+5];
	ll prefw[n+5];
	ll w2 = 0;
	for (int i=0;i<n;i++){
		ll temp;
		cin >> temp;
		h[i] = temp;
	}
	for (int i=0;i<n;i++){
		ll temp;
		cin >> temp;
		w[i] = temp;
		w2 += temp;
		//w2%=m;
		prefw[i] = w2;
	}
	stack<pair<ll,ll>> s;
	ll total=0;
	for (int i=0;i<n;i++){
		ll num=0;
		ll carry=0;
		while (!s.empty() && h[s.top().first]>h[i]){
			s.pop();
		}
		if (!s.empty()){
			carry += s.top().second;
			carry%=m;
			//cout << carry << " ";
			ll height = h[i];
			ll width = prefw[i]-prefw[s.top().first]-w[i];
			width%=m;
			height = height*(height+1)/2;
			height%=m;
			carry += (height*width)%m;
			carry%=m;
		}
		else{
			ll height = h[i];
			ll width = prefw[i]-w[i];
			width%=m;
			height = height*(height+1)/2;
			height%=m;
			carry += (height*width)%m;
			carry%=m;
		}
		//cout << carry << " ";
		ll height = h[i];
		ll width = w[i];
		num += (carry*width)%m;
		num%=m;
		height = height*(height+1)/2;
		ll w2 = width*(width+1)/2;
		height%=m;
		w2%=m;
		num += (height*w2)%m;
		num%=m;
		carry += (height*width)%m;
		carry%=m;
		//cout << i << " " << carry << "\n";
		s.push({i,carry});
		total += num;
		total %=m;
	}
	cout << total%m;
}
		
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 8 ms 1884 KB Output is correct
4 Correct 15 ms 5076 KB Output is correct
5 Correct 18 ms 4696 KB Output is correct
6 Correct 16 ms 4064 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 2 ms 604 KB Output is correct
3 Correct 10 ms 2392 KB Output is correct
4 Correct 19 ms 4444 KB Output is correct
5 Correct 19 ms 4188 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 600 KB Output is correct
3 Correct 2 ms 604 KB Output is correct
4 Correct 9 ms 2396 KB Output is correct
5 Correct 18 ms 4440 KB Output is correct
6 Correct 18 ms 4444 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 3 ms 604 KB Output is correct
9 Correct 10 ms 2392 KB Output is correct
10 Correct 18 ms 4444 KB Output is correct
11 Correct 19 ms 4336 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 500 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 420 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 352 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 7 ms 1880 KB Output is correct
12 Correct 16 ms 5212 KB Output is correct
13 Correct 15 ms 4444 KB Output is correct
14 Correct 15 ms 3932 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 2 ms 1056 KB Output is correct
17 Correct 9 ms 3420 KB Output is correct
18 Correct 19 ms 6224 KB Output is correct
19 Correct 21 ms 6492 KB Output is correct
20 Correct 1 ms 344 KB Output is correct
21 Correct 2 ms 856 KB Output is correct
22 Correct 10 ms 3420 KB Output is correct
23 Correct 19 ms 6112 KB Output is correct
24 Correct 19 ms 6236 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 2 ms 860 KB Output is correct
31 Correct 2 ms 860 KB Output is correct
32 Correct 10 ms 2500 KB Output is correct
33 Correct 10 ms 2396 KB Output is correct
34 Correct 18 ms 4312 KB Output is correct
35 Correct 18 ms 4444 KB Output is correct
36 Correct 19 ms 4700 KB Output is correct
37 Correct 19 ms 4700 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 19 ms 4744 KB Output is correct
40 Correct 24 ms 4692 KB Output is correct
41 Correct 19 ms 4696 KB Output is correct
42 Correct 23 ms 5716 KB Output is correct