답안 #891894

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
891894 2023-12-24T11:39:19 Z asdasdqwer Fancy Fence (CEOI20_fancyfence) C++14
100 / 100
25 ms 11088 KB
#include <bits/stdc++.h>
using namespace std;

#define int int64_t
#define pii pair<int,int>

const int MOD = 1e9 + 7;

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n;cin>>n;
    vector<int> h(n), w(n);
    for (int &x:h)cin>>x;
    for (int &x:w)cin>>x;
    vector<bool> era(n, false);
    vector<int> pv(n, 0);
    for (int i=1;i<n;i++) {
        if (h[i] == h[i-1]) {
            era[i]=true;
            pv[i]=pv[i-1];
            w[pv[i]]+=w[i];
        }

        else {
            pv[i]=i;
        }
    }

    vector<int> th, tw;
    for (int i=0;i<n;i++) {
        if (!era[i]) {
            th.push_back(h[i]);
            tw.push_back(w[i]);
        }
    }

    w=tw;h=th;
    n = w.size();
    vector<bool> ign(n, false);
    stack<array<int,2>> s;

    vector<int> p(n);
    p[0]=w[0];
    for (int i=1;i<n;i++) p[i]=p[i-1]+w[i];

    vector<int> st(n, 0), en(n, 0), clos(n, 0);

    for (int i=0;i<n;i++) {
        while (s.size() && s.top()[0] >= h[i]) {
            if (s.top()[0] == h[i]) {
                ign[i]=true;
            }

            s.pop();
        }

        if (s.size() == 0) {
            st[i] = 0;
        }

        else {
            st[i] = s.top()[1];
            clos[i] = s.top()[0];
        }

        s.push({h[i], p[i]});
    }

    while (s.size())s.pop();

    for (int i=n-1;i>=0;i--) {
        while (s.size() && s.top()[0] >= h[i]) {
            s.pop();
        }

        if (s.size() == 0) {
            en[i] = p.back();
        }

        else {
            en[i] = s.top()[1];
            
            if (clos[i] == 0) {
                clos[i] = s.top()[0];
            }

            else {
                clos[i] = max(clos[i], s.top()[0]);
            }
        }

        if (i != 0) s.push({h[i], p[i-1]});
    }

    // for (int i=0;i<n;i++) {
    //     cout<<st[i]<<" "<<en[i]<<" "<<clos[i]<<" "<<ign[i]<<"\n";
    // }

    int res=0;

    for (int i=0;i<n;i++) {
        if (ign[i])continue;
        int lenBase = en[i] - st[i] + 1;
        int height = h[i];

        int bases = (lenBase) % MOD;
        bases = (bases * (bases-1)) % MOD;
        bases = (500000004 * bases) % MOD;

        int fullHeight = (height+1) % MOD;
        fullHeight = (fullHeight * (fullHeight - 1)) % MOD;
        fullHeight = (500000004 * fullHeight) % MOD;

        int fullRect = (fullHeight * bases) % MOD;

        int partHeight = (clos[i]+1) % MOD;
        partHeight = (partHeight * (partHeight - 1)) % MOD;
        partHeight = (500000004 * partHeight) % MOD;

        fullRect -= ((partHeight * bases) % MOD);
        fullRect += 2*MOD;
        fullRect %= MOD;

        res += fullRect;
    }

    res %= MOD;
    cout<<res<<"\n";
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 436 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 600 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 8 ms 3352 KB Output is correct
4 Correct 14 ms 5732 KB Output is correct
5 Correct 16 ms 6352 KB Output is correct
6 Correct 13 ms 4824 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 2 ms 860 KB Output is correct
3 Correct 8 ms 2604 KB Output is correct
4 Correct 16 ms 4700 KB Output is correct
5 Correct 16 ms 4824 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 492 KB Output is correct
3 Correct 2 ms 860 KB Output is correct
4 Correct 8 ms 2524 KB Output is correct
5 Correct 16 ms 4700 KB Output is correct
6 Correct 17 ms 4704 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 3 ms 1372 KB Output is correct
9 Correct 10 ms 3800 KB Output is correct
10 Correct 23 ms 10812 KB Output is correct
11 Correct 23 ms 11088 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 456 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 464 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 8 ms 3288 KB Output is correct
12 Correct 15 ms 5604 KB Output is correct
13 Correct 16 ms 6352 KB Output is correct
14 Correct 14 ms 4920 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 2 ms 860 KB Output is correct
17 Correct 8 ms 2392 KB Output is correct
18 Correct 20 ms 4692 KB Output is correct
19 Correct 17 ms 4696 KB Output is correct
20 Correct 1 ms 344 KB Output is correct
21 Correct 3 ms 1372 KB Output is correct
22 Correct 10 ms 3788 KB Output is correct
23 Correct 22 ms 10952 KB Output is correct
24 Correct 23 ms 10952 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 3 ms 1424 KB Output is correct
31 Correct 3 ms 1372 KB Output is correct
32 Correct 12 ms 5072 KB Output is correct
33 Correct 13 ms 5072 KB Output is correct
34 Correct 23 ms 9428 KB Output is correct
35 Correct 23 ms 9416 KB Output is correct
36 Correct 25 ms 9708 KB Output is correct
37 Correct 24 ms 9696 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 23 ms 9556 KB Output is correct
40 Correct 22 ms 9684 KB Output is correct
41 Correct 23 ms 9672 KB Output is correct
42 Correct 23 ms 10172 KB Output is correct