답안 #538199

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
538199 2022-03-16T08:15:44 Z Tam_theguide Fancy Fence (CEOI20_fancyfence) C++14
12 / 100
2 ms 340 KB
#include <bits/stdc++.h>
using namespace std;
int n;
int h[100005], w[100005];
int pre[100005];
int l[100005], r[100005];
stack<int>st;
int func(int h_, int w_){
    return (h_*(h_+1)*w_*(w_+1))/4;
}
int ans=0;
int main(){
    cin>>n;
    for (int i=1;i <=n; i++){
        cin>>h[i];
    }
    for (int i=1;i <=n; i++){
        cin>>w[i];
        pre[i]=pre[i-1]+w[i];
    }
    for (int i=1;i <=n; i++){
        while (!st.empty() && h[st.top()]>h[i]){
            st.pop();
        }
        if (st.empty()){l[i]=0;}else{l[i]=st.top();};
        st.push(i);
    }
  /*  for (int i=1;i <=n;i ++){
        cout<<l[i]<<" ";
    } */
    while (st.empty()==false){
        st.pop();
    }
   // cout<<st.size();
    for (int i=n;i >=1; i--){
        while (!st.empty() && h[st.top()]>=h[i]){
            st.pop();
        }
        if (st.empty()){r[i]=n+1;}else{r[i]=st.top();};
        st.push(i);
    }
  /*  for (int i=1;i <=n; i++){
        cout<<i<<" "<<l[i]<<" "<<r[i]<<'\n';
    } */
    for (int i=1;i <=n;i ++){
        int nearest=max(h[l[i]], h[r[i]]);
        int ww=pre[r[i]-1]-pre[l[i]];
        ans+=(func(h[i], ww)-func(nearest, ww));
    }
    cout<<ans;

}
/*
5
1 5 3 3 2
2 2 3 1 2 */
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 1 ms 340 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 312 KB Output is correct
2 Incorrect 1 ms 320 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 308 KB Output is correct
2 Incorrect 1 ms 324 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 2 ms 340 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 1 ms 340 KB Output isn't correct
3 Halted 0 ms 0 KB -