답안 #577528

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
577528 2022-06-15T03:51:15 Z tengiz05 Fancy Fence (CEOI20_fancyfence) C++17
100 / 100
25 ms 3060 KB
#include <bits/stdc++.h>

using namespace std;
using i64 = long long;

constexpr int P = 1E9 + 7, D = (P + 1) / 2;

i64 norm(i64 x) {
    if (x < 0)
        x += P;
    else if (x >= P)
        x -= P;
    return x;
}

i64 C(i64 x) {
    x = norm(x);
    return x * (x + 1) % P * D % P;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int n;
    cin >> n;
    
    vector<i64> 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];
        w[i] += w[i - 1];
        w[i] %= P;
    }
    
    vector<i64> s{0};
    i64 sum = 0;
    
    i64 ans = 0;
    
    for (int i = 1; i <= n; i++) {
        while (h[s.back()] > h[i]) {
            i64 height = h[s.back()];
            i64 r = w[s.back()];
            s.pop_back();
            i64 l = w[s.back()];
            sum = norm(sum - (r - l) * C(height) % P);
            sum = norm(sum + (r - l) * C(h[i]) % P);
        }
        ans = norm(ans + sum * (w[i] - w[i - 1]) % P);
        ans = norm(ans + C(w[i] - w[i - 1]) * C(h[i]) % P);
        sum = norm(sum + (w[i] - w[i - 1]) * C(h[i]) % P);
        s.push_back(i);
    }
    
    cout << ans << "\n";
    
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 9 ms 1492 KB Output is correct
4 Correct 18 ms 3052 KB Output is correct
5 Correct 20 ms 2544 KB Output is correct
6 Correct 19 ms 2084 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 3 ms 596 KB Output is correct
3 Correct 11 ms 1764 KB Output is correct
4 Correct 22 ms 3028 KB Output is correct
5 Correct 24 ms 3052 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 2 ms 596 KB Output is correct
4 Correct 16 ms 1676 KB Output is correct
5 Correct 21 ms 3028 KB Output is correct
6 Correct 24 ms 3040 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 2 ms 596 KB Output is correct
9 Correct 12 ms 1736 KB Output is correct
10 Correct 22 ms 3052 KB Output is correct
11 Correct 23 ms 3060 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 10 ms 1452 KB Output is correct
12 Correct 18 ms 3020 KB Output is correct
13 Correct 18 ms 2412 KB Output is correct
14 Correct 19 ms 2004 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 2 ms 596 KB Output is correct
17 Correct 11 ms 1752 KB Output is correct
18 Correct 21 ms 3024 KB Output is correct
19 Correct 24 ms 3028 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 2 ms 596 KB Output is correct
22 Correct 11 ms 1752 KB Output is correct
23 Correct 22 ms 3028 KB Output is correct
24 Correct 22 ms 3052 KB Output is correct
25 Correct 0 ms 212 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 3 ms 468 KB Output is correct
31 Correct 3 ms 468 KB Output is correct
32 Correct 11 ms 1120 KB Output is correct
33 Correct 12 ms 1108 KB Output is correct
34 Correct 23 ms 1876 KB Output is correct
35 Correct 23 ms 1876 KB Output is correct
36 Correct 23 ms 1876 KB Output is correct
37 Correct 25 ms 1876 KB Output is correct
38 Correct 0 ms 212 KB Output is correct
39 Correct 24 ms 1876 KB Output is correct
40 Correct 24 ms 1900 KB Output is correct
41 Correct 23 ms 2120 KB Output is correct
42 Correct 23 ms 2544 KB Output is correct