답안 #791369

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
791369 2023-07-24T04:07:49 Z PoonYaPat Fancy Fence (CEOI20_fancyfence) C++14
100 / 100
20 ms 5212 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pii;

const ll mod=1e9+7;
ll w[100005],h[100005],dp[100005],qs[100005];
int n;
stack<pii> st;

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin>>n;
    for (int i=1; i<=n; ++i) cin>>h[i];
    for (int i=1; i<=n; ++i) cin>>w[i], qs[i]=(qs[i-1]+w[i])%mod;

    ll ans=0;
    st.push(pii(0,0));
    for (int i=1; i<=n; ++i) {
        while (st.size() && h[st.top().first]>h[i]) st.pop();
        ll sum=(st.top().second + (h[i]*(h[i]+1)/2)%mod*(qs[i-1]-qs[st.top().first]+mod))%mod;
        dp[i]=( ((h[i]*(h[i]+1)/2)%mod) * ((w[i]*(w[i]+1)/2)%mod) + sum*w[i])%mod;
        st.push(pii(i,(sum+((h[i]*(h[i]+1)/2)%mod)*w[i])%mod));
        ans=(ans+dp[i])%mod;
    }
    cout<<ans<<"\n";
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 8 ms 2132 KB Output is correct
4 Correct 17 ms 4820 KB Output is correct
5 Correct 15 ms 4136 KB Output is correct
6 Correct 17 ms 3620 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 2 ms 724 KB Output is correct
3 Correct 11 ms 2792 KB Output is correct
4 Correct 19 ms 5152 KB Output is correct
5 Correct 19 ms 5160 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 2 ms 724 KB Output is correct
4 Correct 10 ms 2704 KB Output is correct
5 Correct 19 ms 5168 KB Output is correct
6 Correct 20 ms 5196 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 3 ms 872 KB Output is correct
9 Correct 10 ms 2840 KB Output is correct
10 Correct 19 ms 5188 KB Output is correct
11 Correct 19 ms 5212 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 9 ms 2272 KB Output is correct
12 Correct 15 ms 4828 KB Output is correct
13 Correct 15 ms 4180 KB Output is correct
14 Correct 15 ms 3660 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 3 ms 848 KB Output is correct
17 Correct 10 ms 2852 KB Output is correct
18 Correct 19 ms 5212 KB Output is correct
19 Correct 19 ms 5192 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 2 ms 848 KB Output is correct
22 Correct 10 ms 2772 KB Output is correct
23 Correct 18 ms 5204 KB Output is correct
24 Correct 19 ms 5204 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 2 ms 708 KB Output is correct
31 Correct 2 ms 724 KB Output is correct
32 Correct 9 ms 1964 KB Output is correct
33 Correct 10 ms 1916 KB Output is correct
34 Correct 18 ms 3568 KB Output is correct
35 Correct 19 ms 3532 KB Output is correct
36 Correct 19 ms 3532 KB Output is correct
37 Correct 19 ms 3476 KB Output is correct
38 Correct 0 ms 340 KB Output is correct
39 Correct 18 ms 3512 KB Output is correct
40 Correct 18 ms 3540 KB Output is correct
41 Correct 18 ms 3628 KB Output is correct
42 Correct 18 ms 4308 KB Output is correct