답안 #427809

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
427809 2021-06-14T23:41:28 Z Ozy Fancy Fence (CEOI20_fancyfence) C++17
100 / 100
37 ms 4760 KB
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define rep(i,a,b) for (lli i = (a); i <= (b); i++)
#define repa(i,a,b) for (lli i = (a); i >= (b); i--)
#define debugsl(a) cout << #a << " = " << a << ", "
#define debug(a) cout << #a << " = " << a << endl

#define altura first
#define pos second
#define MAX 100000
#define mod 1000000007

lli n,res,ult,act,a,w,pas;
lli h[MAX+2];
stack<pair<lli,lli> > pila;
pair<lli,lli> k;

lli calcula(lli f, lli c) {

    f %= mod;
    c %= mod;

    lli a = (f*(f+1))/2;
    a %= mod;
    lli b = (c*(c+1))/2;
    b %= mod;

    a *= b;
    a %= mod;

    return a;
}

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

    cin >> n;
    rep(i,1,n) cin >> h[i];

    act = 1;
    pila.push({0,0});

    rep(i,1,n) {

        cin >> w;

        pas = act;
        while (!pila.empty() && pila.top().altura > h[i]) {

            k = pila.top();
            pila.pop();

            pas = k.pos;
            a = act - k.pos;
            res += calcula(a, k.altura);
            res -= calcula(a, max(pila.top().altura, h[i]));

            if (res < 0) res += mod;
            res %= mod;

        }

        act += w;
        if (pila.top().altura == h[i]) continue;
        else (pila.push({h[i],pas}));

    }

    while (!pila.empty()) {

        k = pila.top();
        pila.pop();
        if (k.altura == 0) break;

        a = act-k.pos;
        res += calcula(a, k.altura);
        res -= calcula(a, pila.top().altura);

        if (res < 0) res += mod;
        res %= mod;

    }

    cout << res;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 11 ms 1212 KB Output is correct
4 Correct 22 ms 2220 KB Output is correct
5 Correct 24 ms 2232 KB Output is correct
6 Correct 21 ms 2236 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 3 ms 588 KB Output is correct
3 Correct 13 ms 1616 KB Output is correct
4 Correct 30 ms 2980 KB Output is correct
5 Correct 37 ms 3060 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Correct 3 ms 588 KB Output is correct
4 Correct 13 ms 1620 KB Output is correct
5 Correct 26 ms 3000 KB Output is correct
6 Correct 28 ms 3088 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 4 ms 716 KB Output is correct
9 Correct 15 ms 1996 KB Output is correct
10 Correct 37 ms 4564 KB Output is correct
11 Correct 30 ms 4760 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 328 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 2 ms 332 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 328 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 15 ms 1220 KB Output is correct
12 Correct 26 ms 2244 KB Output is correct
13 Correct 22 ms 2232 KB Output is correct
14 Correct 23 ms 2236 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 3 ms 588 KB Output is correct
17 Correct 13 ms 1688 KB Output is correct
18 Correct 26 ms 3008 KB Output is correct
19 Correct 29 ms 3148 KB Output is correct
20 Correct 1 ms 372 KB Output is correct
21 Correct 4 ms 716 KB Output is correct
22 Correct 19 ms 2056 KB Output is correct
23 Correct 34 ms 4520 KB Output is correct
24 Correct 30 ms 4544 KB Output is correct
25 Correct 1 ms 204 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 4 ms 332 KB Output is correct
28 Correct 1 ms 288 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 4 ms 576 KB Output is correct
31 Correct 4 ms 588 KB Output is correct
32 Correct 15 ms 1484 KB Output is correct
33 Correct 16 ms 1612 KB Output is correct
34 Correct 28 ms 2848 KB Output is correct
35 Correct 28 ms 2744 KB Output is correct
36 Correct 30 ms 2996 KB Output is correct
37 Correct 33 ms 3012 KB Output is correct
38 Correct 1 ms 332 KB Output is correct
39 Correct 37 ms 3012 KB Output is correct
40 Correct 29 ms 3012 KB Output is correct
41 Correct 31 ms 3124 KB Output is correct
42 Correct 29 ms 3844 KB Output is correct