답안 #959379

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
959379 2024-04-08T06:18:56 Z ALTAKEXE Fancy Fence (CEOI20_fancyfence) C++17
100 / 100
23 ms 4212 KB
#include<bits/stdc++.h>
using namespace std;
#define f first
#define s second
#define ll long long
const ll mod=1e9+7;
int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int n;
	cin>>n;
	vector<ll> h(n+1,0), w(n+1,0);
	for(int i=0;i<n;++i) cin>>h[i];
	for(int i=0;i<n;++i) cin>>w[i];
	n++;
	vector<pair<ll,ll>> t; 
	t.push_back({0,0});
	ll ans=0;
	for(int i=0;i<n;++i) {
		ll sum=0;
		while(t.back().f>h[i]) { 
			ll mn=max(h[i],t[t.size()-2].f); 
			ll mx=t.back().f-mn; 
			sum=(sum+t.back().s)%mod;
			t.pop_back();
			ans+=(mx*(mx+1)%mod*500000004%mod+mx*mn%mod)*(sum*(sum+1)%mod*500000004%mod)%mod;
			ans%=mod;
		}
		if(t.back().f==h[i]) t.back().s=(t.back().s+sum+w[i])%mod;
		else t.push_back({h[i], (sum+w[i])%mod});
	}
	cout<<ans<<endl;
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 7 ms 1256 KB Output is correct
4 Correct 15 ms 2040 KB Output is correct
5 Correct 14 ms 1884 KB Output is correct
6 Correct 13 ms 1884 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 2 ms 604 KB Output is correct
3 Correct 9 ms 1252 KB Output is correct
4 Correct 23 ms 1880 KB Output is correct
5 Correct 16 ms 2036 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 2 ms 604 KB Output is correct
4 Correct 8 ms 1116 KB Output is correct
5 Correct 17 ms 1880 KB Output is correct
6 Correct 18 ms 1884 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 3 ms 856 KB Output is correct
9 Correct 9 ms 1760 KB Output is correct
10 Correct 21 ms 4212 KB Output is correct
11 Correct 19 ms 4048 KB Output is correct
12 Correct 0 ms 600 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 1 ms 344 KB Output is correct
5 Correct 1 ms 600 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 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 376 KB Output is correct
4 Correct 1 ms 456 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 7 ms 1116 KB Output is correct
12 Correct 13 ms 1884 KB Output is correct
13 Correct 14 ms 2032 KB Output is correct
14 Correct 13 ms 1884 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 2 ms 604 KB Output is correct
17 Correct 8 ms 1116 KB Output is correct
18 Correct 17 ms 1884 KB Output is correct
19 Correct 16 ms 1880 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 2 ms 856 KB Output is correct
22 Correct 9 ms 1760 KB Output is correct
23 Correct 18 ms 4056 KB Output is correct
24 Correct 18 ms 4052 KB Output is correct
25 Correct 0 ms 344 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 3 ms 856 KB Output is correct
31 Correct 2 ms 604 KB Output is correct
32 Correct 9 ms 1260 KB Output is correct
33 Correct 12 ms 1116 KB Output is correct
34 Correct 18 ms 1884 KB Output is correct
35 Correct 19 ms 2036 KB Output is correct
36 Correct 18 ms 1884 KB Output is correct
37 Correct 20 ms 1880 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 18 ms 2040 KB Output is correct
40 Correct 18 ms 1884 KB Output is correct
41 Correct 19 ms 2396 KB Output is correct
42 Correct 19 ms 3036 KB Output is correct