답안 #954071

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
954071 2024-03-27T08:24:13 Z Sharky Fancy Fence (CEOI20_fancyfence) C++17
43 / 100
18 ms 3676 KB
#include <bits/stdc++.h>
using namespace std;
 
#define int long long
const int mod = 1e9 + 7;
 
int s(int x) {
    return (x * (x + 1) / 2) % mod;
}
 
int s(int l, int r) {
    return (s(r) - s(l-1)) % mod;
}
 
void norm(int& x) {
    x = (x % mod + mod) % mod;
}
 
int32_t main() {
    ios::sync_with_stdio(0); cin.tie(0);
    int n;
    cin >> n;
    stack<pair<int, int>> st;
    int sum = 0, delta = 0;
    vector<int> H(n+1), W(n+1);
    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++) {
        int h = H[i], w = W[i], aw = w;
        while (!st.empty() && st.top().first > h) {
            auto [ff, ss] = st.top();
            st.pop();
            int nxth = h;
            if (!st.empty() && st.top().first > h) nxth = st.top().first, st.top().second += ss;
            else aw += ss;
            delta -= (s(nxth + 1, ff) * ss) % mod;
            norm(delta);
        }
        // cout << delta << ' ' << h << ' ' << w << '\n';
        st.push({h, w});
        sum += delta * w + s(h) * s(w);
        norm(sum);
        delta += s(h) * w;
        norm(delta);
        // cout << sum << ' ' << delta << '\n';
    }
    cout << sum << '\n';
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Incorrect 1 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 7 ms 1368 KB Output is correct
4 Correct 17 ms 3324 KB Output is correct
5 Correct 14 ms 2648 KB Output is correct
6 Correct 14 ms 2140 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 2 ms 604 KB Output is correct
3 Correct 11 ms 2024 KB Output is correct
4 Correct 17 ms 3672 KB Output is correct
5 Correct 17 ms 3676 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 2 ms 604 KB Output is correct
4 Correct 9 ms 2024 KB Output is correct
5 Correct 18 ms 3568 KB Output is correct
6 Correct 17 ms 3676 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 2 ms 604 KB Output is correct
9 Correct 11 ms 2076 KB Output is correct
10 Correct 18 ms 3676 KB Output is correct
11 Correct 18 ms 3576 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Incorrect 0 ms 344 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Incorrect 1 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -