# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
967066 | 2024-04-21T05:32:02 Z | blackslex | Fancy Fence (CEOI20_fancyfence) | C++17 | 34 ms | 5576 KB |
#include<bits/stdc++.h> using namespace std; using ll = long long; const int M = 1e9 + 7, INV = 5e8 + 4; int n; int main() { scanf("%d", &n); vector<int> h(n + 5), w(n + 5); vector<ll> pref(n + 5); for (int i = 1; i <= n; i++) scanf("%d", &h[i]); for (int i = 1; i <= n; i++) scanf("%d", &w[i]), pref[i] = pref[i - 1] + w[i], pref[i] %= M; vector<int> l(n + 5), r(n + 5, n + 1), sec(n + 5); stack<int> st; for (int i = 1; i <= n; i++) { while (!st.empty() && h[i] <= h[st.top()]) { sec[st.top()] = max(sec[st.top()], h[i]); st.pop(); } if (!st.empty()) l[i] = st.top(); st.emplace(i); } while (!st.empty()) st.pop(); for (int i = n; i >= 1; i--) { while (!st.empty() && h[i] < h[st.top()]) { sec[st.top()] = max(sec[st.top()], h[i]); st.pop(); } if (!st.empty()) r[i] = st.top(); st.emplace(i); } for (int i = 1; i <= n; i++) l[i]++, r[i]--; ll ans = 0; for (int i = 1; i <= n; i++) { ll cursz = pref[r[i]] - pref[l[i] - 1]; cursz %= M; cursz += M; cursz %= M; ll pos = cursz * (cursz + 1) % M * INV % M; ans += pos * sec[i] % M * (h[i] - sec[i]) % M; ans %= M; ans += pos * (h[i] - sec[i]) % M * (h[i] - sec[i] + 1) % M * INV % M; ans %= M; } printf("%lld", ans); }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 348 KB | Output is correct |
2 | Correct | 1 ms | 348 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 348 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
3 | Correct | 0 ms | 348 KB | Output is correct |
4 | Correct | 1 ms | 348 KB | Output is correct |
5 | Correct | 0 ms | 348 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 348 KB | Output is correct |
2 | Correct | 1 ms | 348 KB | Output is correct |
3 | Correct | 15 ms | 2324 KB | Output is correct |
4 | Correct | 19 ms | 4444 KB | Output is correct |
5 | Correct | 19 ms | 4424 KB | Output is correct |
6 | Correct | 19 ms | 4184 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 500 KB | Output is correct |
2 | Correct | 2 ms | 860 KB | Output is correct |
3 | Correct | 11 ms | 2904 KB | Output is correct |
4 | Correct | 34 ms | 5440 KB | Output is correct |
5 | Correct | 33 ms | 5456 KB | Output is correct |
6 | Correct | 0 ms | 348 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 344 KB | Output is correct |
2 | Correct | 1 ms | 348 KB | Output is correct |
3 | Correct | 4 ms | 860 KB | Output is correct |
4 | Correct | 11 ms | 2784 KB | Output is correct |
5 | Correct | 26 ms | 5328 KB | Output is correct |
6 | Correct | 28 ms | 5576 KB | Output is correct |
7 | Correct | 1 ms | 344 KB | Output is correct |
8 | Correct | 2 ms | 704 KB | Output is correct |
9 | Correct | 12 ms | 2756 KB | Output is correct |
10 | Correct | 30 ms | 5204 KB | Output is correct |
11 | Correct | 23 ms | 5536 KB | Output is correct |
12 | Correct | 0 ms | 344 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 348 KB | Output is correct |
2 | Correct | 1 ms | 348 KB | Output is correct |
3 | Correct | 1 ms | 348 KB | Output is correct |
4 | Correct | 0 ms | 348 KB | Output is correct |
5 | Correct | 0 ms | 348 KB | Output is correct |
6 | Correct | 0 ms | 600 KB | Output is correct |
7 | Correct | 1 ms | 600 KB | Output is correct |
8 | Correct | 1 ms | 344 KB | Output is correct |
9 | Correct | 1 ms | 348 KB | Output is correct |
10 | Correct | 1 ms | 448 KB | Output is correct |
11 | Correct | 0 ms | 348 KB | Output is correct |
12 | Correct | 0 ms | 348 KB | Output is correct |
13 | Correct | 1 ms | 344 KB | Output is correct |
14 | Correct | 1 ms | 368 KB | Output is correct |
15 | Correct | 1 ms | 348 KB | Output is correct |
16 | Correct | 0 ms | 348 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 348 KB | Output is correct |
2 | Correct | 1 ms | 348 KB | Output is correct |
3 | Correct | 1 ms | 348 KB | Output is correct |
4 | Correct | 1 ms | 468 KB | Output is correct |
5 | Correct | 1 ms | 436 KB | Output is correct |
6 | Correct | 0 ms | 348 KB | Output is correct |
7 | Correct | 0 ms | 348 KB | Output is correct |
8 | Correct | 0 ms | 600 KB | Output is correct |
9 | Correct | 0 ms | 436 KB | Output is correct |
10 | Correct | 1 ms | 344 KB | Output is correct |
11 | Correct | 10 ms | 2396 KB | Output is correct |
12 | Correct | 19 ms | 4440 KB | Output is correct |
13 | Correct | 22 ms | 4436 KB | Output is correct |
14 | Correct | 19 ms | 4188 KB | Output is correct |
15 | Correct | 1 ms | 348 KB | Output is correct |
16 | Correct | 2 ms | 860 KB | Output is correct |
17 | Correct | 11 ms | 2908 KB | Output is correct |
18 | Correct | 21 ms | 5328 KB | Output is correct |
19 | Correct | 21 ms | 5468 KB | Output is correct |
20 | Correct | 0 ms | 348 KB | Output is correct |
21 | Correct | 3 ms | 788 KB | Output is correct |
22 | Correct | 12 ms | 2916 KB | Output is correct |
23 | Correct | 33 ms | 5192 KB | Output is correct |
24 | Correct | 28 ms | 5472 KB | Output is correct |
25 | Correct | 0 ms | 352 KB | Output is correct |
26 | Correct | 1 ms | 352 KB | Output is correct |
27 | Correct | 1 ms | 348 KB | Output is correct |
28 | Correct | 1 ms | 352 KB | Output is correct |
29 | Correct | 1 ms | 352 KB | Output is correct |
30 | Correct | 3 ms | 872 KB | Output is correct |
31 | Correct | 3 ms | 864 KB | Output is correct |
32 | Correct | 11 ms | 2656 KB | Output is correct |
33 | Correct | 18 ms | 2616 KB | Output is correct |
34 | Correct | 22 ms | 4700 KB | Output is correct |
35 | Correct | 33 ms | 4696 KB | Output is correct |
36 | Correct | 26 ms | 4956 KB | Output is correct |
37 | Correct | 34 ms | 5064 KB | Output is correct |
38 | Correct | 1 ms | 348 KB | Output is correct |
39 | Correct | 32 ms | 4984 KB | Output is correct |
40 | Correct | 24 ms | 4948 KB | Output is correct |
41 | Correct | 21 ms | 4952 KB | Output is correct |
42 | Correct | 21 ms | 5212 KB | Output is correct |