Submission #710108

# Submission time Handle Problem Language Result Execution time Memory
710108 2023-03-15T04:44:56 Z Spade1 Fancy Fence (CEOI20_fancyfence) C++14
12 / 100
1 ms 340 KB
#include<bits/stdc++.h>
//#include "grader.h"
#define pii pair<int, int>
#define pll pair<long long, long long>
#define ll long long
#define ld long double
#define st first
#define nd second
#define pb push_back
#define INF INT_MAX
using namespace std;

const int N = 1e5 + 10;
const int M = 1e9+7;

ll h[N], w[N];

stack<pii> s;

ll ans;
ll add(ll a, ll b) {return ((((a%M)+(b%M))%M)+M)%M;}
ll mul(ll a, ll b) {return (a%M*b%M)%M;}

ll power(ll a, ll b) {
    if (b==0) return 1;
    ll ret = power(a, b/2);
    if (b&1) return mul(ret, mul(ret, a));
    else return mul(ret, ret);
}

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

    s.push({0, 0});
    ll inv = power(2, M-2);
    for (int i = 1; i <= n; ++i) {
        while (s.top().st > h[i]) {
            auto [H, W] = s.top(); s.pop();
            if (s.top().st > h[i]) {
                H -= s.top().st;
                auto [HH, WW] = s.top(); s.pop();
                s.push({HH, WW + W});
                ll cur = 0;
                cur = mul(H, s.top().st);
                cur = mul(cur, W);
                cur = mul(cur, W+1);
                cur = mul(cur, inv);
                ans = add(ans, cur);
            }
            else {
                H -= h[i];
                s.push({h[i], W});
                ll cur = 0;
                cur = mul(H, h[i]);
                cur = mul(cur, W);
                cur = mul(cur, W+1);
                cur = mul(cur, inv);
                ans = add(ans, cur);
            }
            ll cur = 0;
            cur = mul(H, H+1);
            cur = mul(cur, inv);
            cur = mul(cur, W);
            cur = mul(cur, W+1);
            cur = mul(cur, inv);
            ans = add(ans, cur);
        }
        if (s.top().st == h[i]) {
            auto [HH, WW] = s.top(); s.pop();
            s.push({HH, WW + w[i]});
        }
        else
            s.push({h[i], w[i]});
    }
    while (s.size() > 1) {
        auto [H, W] = s.top(); s.pop();
        H -= s.top().st;
        auto [HH, WW] = s.top(); s.pop();
        s.push({HH, WW + W});
        ll cur = 0;
        cur = mul(H, s.top().st);
        cur = mul(cur, W);
        cur = mul(cur, W+1);
        cur = mul(cur, inv);
        ans = add(ans, cur);
        cur = 0;
        cur = mul(H, H+1);
        cur = mul(cur, inv);
        cur = mul(cur, W);
        cur = mul(cur, W+1);
        cur = mul(cur, inv);
        ans = add(ans, cur);
    }
    cout << ans << '\n';
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(NULL);
    int t = 1;
//    cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}

Compilation message

fancyfence.cpp: In function 'void solve()':
fancyfence.cpp:40:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   40 |             auto [H, W] = s.top(); s.pop();
      |                  ^
fancyfence.cpp:43:22: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   43 |                 auto [HH, WW] = s.top(); s.pop();
      |                      ^
fancyfence.cpp:71:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   71 |             auto [HH, WW] = s.top(); s.pop();
      |                  ^
fancyfence.cpp:78:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   78 |         auto [H, W] = s.top(); s.pop();
      |              ^
fancyfence.cpp:80:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   80 |         auto [HH, WW] = s.top(); s.pop();
      |              ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 1 ms 340 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 284 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 1 ms 340 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 1 ms 340 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 1 ms 340 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 1 ms 340 KB Output isn't correct
3 Halted 0 ms 0 KB -