답안 #383461

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
383461 2021-03-30T00:38:43 Z MODDI Fancy Fence (CEOI20_fancyfence) C++14
100 / 100
40 ms 7168 KB
// I_Love_LPL
#include <bits/stdc++.h>
 
using namespace std;
 
#define ll long long
#define endl '\n'
const int N = 1e5 + 5;
const int mod = 1e9 + 7;
ll h[N], w[N], sum[N], g[N];
ll dp[N];
int main(){
        ios_base::sync_with_stdio(false);
        cin.tie(0);
        if (fopen("A.inp", "r")){
                freopen("test.inp", "r", stdin);
                freopen("test.out", "w", stdout);
        }
        ll n;
        cin >> n;
        ll ans = 0;
        for (int i = 1; i <= n; i++) cin >> h[i];
        for (int i = 1; i <= n; i++) cin >> w[i], g[i] = (g[i - 1] + w[i]) % mod;
        h[0] = 0;
        stack<ll> s;
        s.push(0);
        for (int i = 1; i <= n; i++){
                while (s.size()){
                        if (h[s.top()] > h[i]) s.pop();
                        else break;
                }
                dp[i] = (w[i] * (w[i] + 1) / 2) % mod * ((h[i] * (h[i] + 1) / 2) % mod) % mod;
                sum[i] = sum[s.top()] + (g[i - 1] - g[s.top()] + mod) % mod * ((h[i] * (h[i] + 1) / 2) % mod) % mod;
                dp[i] = (dp[i] + sum[i] * w[i]) % mod;
                ans = (ans + dp[i]) % mod;
                sum[i] = (sum[i] + ((h[i] * (h[i] + 1) / 2) % mod) * w[i] % mod) % mod;
                s.push(i);
        }
        cout << ans;
}

Compilation message

fancyfence.cpp: In function 'int main()':
fancyfence.cpp:16:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   16 |                 freopen("test.inp", "r", stdin);
      |                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
fancyfence.cpp:17:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   17 |                 freopen("test.out", "w", stdout);
      |                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 2 ms 364 KB Output is correct
3 Correct 14 ms 3052 KB Output is correct
4 Correct 26 ms 6124 KB Output is correct
5 Correct 27 ms 5740 KB Output is correct
6 Correct 26 ms 5484 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 5 ms 1132 KB Output is correct
3 Correct 18 ms 3692 KB Output is correct
4 Correct 34 ms 7020 KB Output is correct
5 Correct 36 ms 7148 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 4 ms 1004 KB Output is correct
4 Correct 19 ms 3692 KB Output is correct
5 Correct 40 ms 7020 KB Output is correct
6 Correct 36 ms 7168 KB Output is correct
7 Correct 2 ms 364 KB Output is correct
8 Correct 4 ms 1004 KB Output is correct
9 Correct 22 ms 3692 KB Output is correct
10 Correct 32 ms 6912 KB Output is correct
11 Correct 33 ms 7020 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 2 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 2 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 14 ms 3052 KB Output is correct
12 Correct 26 ms 6124 KB Output is correct
13 Correct 26 ms 5740 KB Output is correct
14 Correct 26 ms 5484 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 4 ms 1004 KB Output is correct
17 Correct 17 ms 3692 KB Output is correct
18 Correct 33 ms 7020 KB Output is correct
19 Correct 35 ms 7148 KB Output is correct
20 Correct 1 ms 440 KB Output is correct
21 Correct 4 ms 1004 KB Output is correct
22 Correct 18 ms 3692 KB Output is correct
23 Correct 32 ms 6892 KB Output is correct
24 Correct 33 ms 7020 KB Output is correct
25 Correct 2 ms 364 KB Output is correct
26 Correct 1 ms 364 KB Output is correct
27 Correct 1 ms 364 KB Output is correct
28 Correct 1 ms 364 KB Output is correct
29 Correct 1 ms 364 KB Output is correct
30 Correct 5 ms 1024 KB Output is correct
31 Correct 4 ms 1004 KB Output is correct
32 Correct 16 ms 3180 KB Output is correct
33 Correct 17 ms 3308 KB Output is correct
34 Correct 38 ms 5996 KB Output is correct
35 Correct 32 ms 5996 KB Output is correct
36 Correct 34 ms 6252 KB Output is correct
37 Correct 34 ms 6252 KB Output is correct
38 Correct 1 ms 364 KB Output is correct
39 Correct 33 ms 6252 KB Output is correct
40 Correct 33 ms 6252 KB Output is correct
41 Correct 33 ms 6252 KB Output is correct
42 Correct 33 ms 6636 KB Output is correct