Submission #404745

# Submission time Handle Problem Language Result Execution time Memory
404745 2021-05-14T22:33:53 Z SirCovidThe19th Fancy Fence (CEOI20_fancyfence) C++14
100 / 100
105 ms 6084 KB
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define mod (ll)1000000007

ll m(ll a, ll b){
    a %= mod; b %= mod;
    return (a*b)%mod;
}
ll m(ll a, ll b, ll c){
    a %= mod; b %= mod; c %= mod;
    return m(m(a, b), c);
}
ll sum(ll x){
    return ((x*(x+1))/2)%mod;
}

int main(){
    
    ll n, ans; cin >> n; 
    ll h[n+1], w[n+1], p[n+1], dp[n+1]; 
    h[0] = 0; p[0] = 0; dp[0] = 0, ans = 0;

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

    stack<ll> stk; stk.push(0);

    for (int i = 1; i <= n; i++){
        while (!stk.empty() and h[stk.top()] >= h[i]) stk.pop();
        dp[i] = dp[stk.top()] + m(sum(h[i]), (p[i]-p[stk.top()]));
        ans += m(dp[stk.top()], w[i]) + m(sum(h[i]), (p[i-1]-p[stk.top()]), w[i]) + m(sum(h[i]), sum(w[i]));
        dp[i] %= mod; ans %= mod; stk.push(i);
    }

    cout<<ans;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 296 KB Output is correct
2 Correct 2 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 300 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
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 2 ms 332 KB Output is correct
3 Correct 33 ms 2380 KB Output is correct
4 Correct 66 ms 4548 KB Output is correct
5 Correct 66 ms 4548 KB Output is correct
6 Correct 66 ms 4544 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 332 KB Output is correct
2 Correct 10 ms 692 KB Output is correct
3 Correct 47 ms 2728 KB Output is correct
4 Correct 96 ms 5296 KB Output is correct
5 Correct 97 ms 5432 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 2 ms 332 KB Output is correct
3 Correct 10 ms 800 KB Output is correct
4 Correct 46 ms 2712 KB Output is correct
5 Correct 104 ms 5300 KB Output is correct
6 Correct 94 ms 5444 KB Output is correct
7 Correct 2 ms 332 KB Output is correct
8 Correct 10 ms 844 KB Output is correct
9 Correct 51 ms 3000 KB Output is correct
10 Correct 88 ms 5996 KB Output is correct
11 Correct 105 ms 6084 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 2 ms 332 KB Output is correct
3 Correct 1 ms 292 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 2 ms 332 KB Output is correct
10 Correct 2 ms 332 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 2 ms 332 KB Output is correct
14 Correct 2 ms 332 KB Output is correct
15 Correct 2 ms 304 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 296 KB Output is correct
2 Correct 2 ms 332 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 2 ms 332 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 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 34 ms 2352 KB Output is correct
12 Correct 71 ms 4548 KB Output is correct
13 Correct 66 ms 4536 KB Output is correct
14 Correct 66 ms 4544 KB Output is correct
15 Correct 2 ms 332 KB Output is correct
16 Correct 13 ms 796 KB Output is correct
17 Correct 46 ms 2728 KB Output is correct
18 Correct 100 ms 5300 KB Output is correct
19 Correct 94 ms 5436 KB Output is correct
20 Correct 2 ms 332 KB Output is correct
21 Correct 10 ms 844 KB Output is correct
22 Correct 51 ms 2984 KB Output is correct
23 Correct 90 ms 5948 KB Output is correct
24 Correct 91 ms 6084 KB Output is correct
25 Correct 1 ms 204 KB Output is correct
26 Correct 1 ms 204 KB Output is correct
27 Correct 2 ms 332 KB Output is correct
28 Correct 2 ms 332 KB Output is correct
29 Correct 2 ms 332 KB Output is correct
30 Correct 10 ms 808 KB Output is correct
31 Correct 10 ms 668 KB Output is correct
32 Correct 43 ms 2628 KB Output is correct
33 Correct 47 ms 2716 KB Output is correct
34 Correct 88 ms 5044 KB Output is correct
35 Correct 105 ms 5060 KB Output is correct
36 Correct 98 ms 5288 KB Output is correct
37 Correct 93 ms 5340 KB Output is correct
38 Correct 1 ms 204 KB Output is correct
39 Correct 91 ms 5316 KB Output is correct
40 Correct 92 ms 5320 KB Output is correct
41 Correct 92 ms 5428 KB Output is correct
42 Correct 91 ms 5700 KB Output is correct