답안 #791368

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
791368 2023-07-24T04:02:21 Z PoonYaPat Fancy Fence (CEOI20_fancyfence) C++14
0 / 100
1 ms 508 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 (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().second]+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 0 ms 340 KB Output is correct
2 Runtime error 1 ms 468 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Runtime error 1 ms 508 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 468 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Runtime error 1 ms 468 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Runtime error 1 ms 468 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Runtime error 1 ms 468 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -