답안 #503617

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
503617 2022-01-08T12:37:10 Z MasterTaster Fancy Fence (CEOI20_fancyfence) C++14
55 / 100
28 ms 7876 KB
#include <bits/stdc++.h>

#define pb push_back
#define ll long long
#define pii pair<int, int>
#define xx first
#define yy second
#define MAXN 100010
#define MOD 1000000007

using namespace std;

ll two=500000004; //inv
ll n, dp[MAXN], pos[MAXN], h[MAXN], w[MAXN], pref[MAXN], cnt[MAXN], ress;

ll add(ll x, ll y)
{
    ll ret=x+y;
    if (ret>=MOD) ret-=MOD;
    return ret;
}
ll mul(ll x, ll y)
{
    ll ret=x*y;
    if (ret>=MOD) ret%=MOD;
    return ret;
}
ll sum(ll x, ll y)
{
    ll ret=mul(mul(y, y+1), two);
    ret-=mul(mul(x-1, x), two);
    if (ret<0) ret+=MOD;
    return ret;
}

int main(){
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

    cin>>n;
    for (int i=1; i<=n; i++) cin>>h[i];
    for (int i=1; i<=n; i++) cin>>w[i];


    stack<pii> st;
    st.push({-1, 0});
    for (int i=1; i<=n; i++)
    {
        while (st.top().xx>h[i]) st.pop();
        pos[i]=st.top().yy;
        st.push({h[i], i});
    }

    pref[0]=0;
    for (int i=1; i<=n; i++) pref[i]=add(pref[i-1], w[i]);


    ll x, y;
    cnt[1]=0;
    for (int i=2; i<=n; i++)
    {
        int ind=pos[i];
        cnt[i]=cnt[ind];

        x=w[ind];
        y=sum(1, h[ind]);
        cnt[i]=add(cnt[i], mul(x, y));

        x=pref[i-1]-pref[ind];
        y=sum(1, h[i]);
        ll pom=mul(x, y);

        cnt[i]=add(cnt[i], pom);
    }

    dp[1]=mul(sum(1, w[1]), sum(1, h[1]));
    for (int i=2; i<=n; i++)
    {
        int ind=pos[i];
        dp[i]=mul(cnt[i], w[i]);

        x=sum(1, w[i]);
        y=sum(1, h[i]);
        dp[i]=add(dp[i], mul(x, y));
    }

    for (int i=1; i<=n; i++) { ress=add(dp[i], ress); /*cout<<dp[i]<<" ";*/ }
    //cout<<endl;

    cout<<ress;
}
/*

3
1 2 1
1 2 3

*/

Compilation message

fancyfence.cpp: In function 'int main()':
fancyfence.cpp:78:13: warning: unused variable 'ind' [-Wunused-variable]
   78 |         int ind=pos[i];
      |             ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 332 KB Output is correct
2 Incorrect 0 ms 332 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 10 ms 3392 KB Output is correct
4 Correct 23 ms 6736 KB Output is correct
5 Correct 20 ms 6456 KB Output is correct
6 Correct 20 ms 6244 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 3 ms 948 KB Output is correct
3 Correct 13 ms 4040 KB Output is correct
4 Correct 26 ms 7724 KB Output is correct
5 Correct 28 ms 7820 KB Output is correct
6 Correct 0 ms 324 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 3 ms 984 KB Output is correct
4 Correct 13 ms 4036 KB Output is correct
5 Correct 25 ms 7744 KB Output is correct
6 Correct 27 ms 7876 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 4 ms 1044 KB Output is correct
9 Correct 13 ms 3972 KB Output is correct
10 Correct 26 ms 7548 KB Output is correct
11 Correct 24 ms 7648 KB Output is correct
12 Correct 0 ms 324 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 332 KB Output is correct
2 Incorrect 1 ms 332 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 332 KB Output is correct
2 Incorrect 0 ms 332 KB Output isn't correct