답안 #881484

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
881484 2023-12-01T09:45:54 Z 1L1YA Fancy Fence (CEOI20_fancyfence) C++17
12 / 100
1 ms 2548 KB
//1L1YA
#include<bits/stdc++.h>
using namespace std;
#define ll           long long
#define Pb           push_back
#define dokme(x)     cout << x << endl, exit(0)
#define pii          pair<int,int>
#define F            first
#define S            second
#define endl         '\n'
#define sep          ' '
#define all(x)       x.begin(),x.end()
#define FastIO       ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define lc           id<<1
#define rc           lc|1

const ll mod=1e9+7;
const ll oo=4e18;
const int N=1e5+5;
const int lg=23;

ll n,h[N],w[N],dp[N],lst[N],sum[N];

ll C(ll x){
    x%=mod;
    return (x*(x-1)/2)%mod;
}

int main(){
    FastIO

    cin >> n;
    for(int i=1;i<=n;i++)
        cin >> h[i];
    for(int i=1;i<=n;i++)
        cin >> w[i],sum[i]=(sum[i-1]+w[i])%mod;
    vector<int> st;
    st.Pb(0);
    for(int i=1;i<=n;i++){
        while(h[i]<=h[st.back()])
            st.pop_back();
        lst[i]=st.back();
        st.Pb(i);
    }
    ll ans=0;
    for(int i=1;i<=n;i++){
        ll W=(sum[i]-sum[lst[i]]+mod)%mod;
        ll p=C(W+1);
        p=(p-C((W-w[i]+1+mod)%mod)+mod)%mod;
        ans+=p*C(h[i]+1)%mod;
        ans+=dp[lst[i]]*w[i]%mod;
        dp[i]=(W*C(h[i]+1)%mod+dp[lst[i]])%mod;
    }
    cout << ans << endl;

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2392 KB Output is correct
2 Incorrect 1 ms 2396 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2392 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Incorrect 1 ms 2524 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 2396 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2548 KB Output is correct
2 Incorrect 1 ms 2396 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Incorrect 1 ms 2396 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2392 KB Output is correct
2 Incorrect 1 ms 2396 KB Output isn't correct
3 Halted 0 ms 0 KB -