답안 #694733

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
694733 2023-02-04T09:06:20 Z hgmhc Fancy Fence (CEOI20_fancyfence) C++17
100 / 100
40 ms 5800 KB
#include <bits/stdc++.h>
using namespace std; using ll = long long;
#define rep(i,a,b) for (auto i = (a); i <= (b); ++i)

const int N = 100003, MOD = 1e9+7;
int n;
ll h[N], w[N], x[N], c[N], sum, ans;
stack<int> s;

ll C(ll n){return (n*(n-1)/2)%MOD;}

int main() {
    scanf("%d", &n);
    rep(i,1,n) scanf("%lld", &h[i]);
    rep(i,1,n) scanf("%lld", &w[i]), x[i] = (x[i-1]+w[i])%MOD;
    rep(i,1,n) {
        while (not empty(s) and h[s.top()] > h[i]) sum = (sum-c[s.top()])%MOD, s.pop();
        ans += (x[i-1]-(empty(s)?0:x[s.top()]))*C(h[i]+1)%MOD*w[i]%MOD;
        ans += sum*w[i]%MOD + C(w[i]+1)*C(h[i]+1)%MOD;
        ans %= MOD;
        c[i] = (x[i]-(empty(s)?0:x[s.top()]))*C(h[i]+1)%MOD;
        sum = (sum+c[i])%MOD;
        s.push(i);
    }
    printf("%lld\n",(ans%MOD+MOD)%MOD);
}

Compilation message

fancyfence.cpp: In function 'int main()':
fancyfence.cpp:13:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   13 |     scanf("%d", &n);
      |     ~~~~~^~~~~~~~~~
fancyfence.cpp:14:21: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   14 |     rep(i,1,n) scanf("%lld", &h[i]);
      |                ~~~~~^~~~~~~~~~~~~~~
fancyfence.cpp:15:21: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   15 |     rep(i,1,n) scanf("%lld", &w[i]), x[i] = (x[i-1]+w[i])%MOD;
      |                ~~~~~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 2 ms 324 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 308 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 312 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 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 10 ms 2516 KB Output is correct
4 Correct 23 ms 4812 KB Output is correct
5 Correct 25 ms 4684 KB Output is correct
6 Correct 38 ms 4520 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 5 ms 868 KB Output is correct
3 Correct 17 ms 3032 KB Output is correct
4 Correct 36 ms 5768 KB Output is correct
5 Correct 28 ms 5800 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 320 KB Output is correct
3 Correct 3 ms 812 KB Output is correct
4 Correct 13 ms 2996 KB Output is correct
5 Correct 27 ms 5728 KB Output is correct
6 Correct 27 ms 5780 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 3 ms 852 KB Output is correct
9 Correct 13 ms 3048 KB Output is correct
10 Correct 31 ms 5640 KB Output is correct
11 Correct 35 ms 5760 KB Output is correct
12 Correct 1 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 1 ms 212 KB Output is correct
4 Correct 0 ms 312 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 356 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 308 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 2 ms 324 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 360 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 11 ms 2440 KB Output is correct
12 Correct 21 ms 4820 KB Output is correct
13 Correct 29 ms 4636 KB Output is correct
14 Correct 29 ms 4540 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 4 ms 852 KB Output is correct
17 Correct 13 ms 3028 KB Output is correct
18 Correct 28 ms 5652 KB Output is correct
19 Correct 28 ms 5780 KB Output is correct
20 Correct 1 ms 356 KB Output is correct
21 Correct 3 ms 840 KB Output is correct
22 Correct 13 ms 3012 KB Output is correct
23 Correct 26 ms 5592 KB Output is correct
24 Correct 25 ms 5708 KB Output is correct
25 Correct 1 ms 312 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 2 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 3 ms 832 KB Output is correct
31 Correct 3 ms 724 KB Output is correct
32 Correct 14 ms 2644 KB Output is correct
33 Correct 13 ms 2768 KB Output is correct
34 Correct 23 ms 5100 KB Output is correct
35 Correct 25 ms 5136 KB Output is correct
36 Correct 29 ms 5268 KB Output is correct
37 Correct 30 ms 5288 KB Output is correct
38 Correct 1 ms 312 KB Output is correct
39 Correct 40 ms 5332 KB Output is correct
40 Correct 29 ms 5252 KB Output is correct
41 Correct 30 ms 5324 KB Output is correct
42 Correct 29 ms 5448 KB Output is correct