답안 #372754

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
372754 2021-03-01T13:22:02 Z jenkinsser Fancy Fence (CEOI20_fancyfence) C++17
100 / 100
36 ms 6140 KB
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define st first
#define nd second
#define pii pair<int,int>
#define piii pair<int,pii>
#define sp " "
#define nl "\n"
#define all(x) x.begin(),x.end()
#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);
#define ll long long
#define int ll
using namespace std;

const int N = 100005;
const int INF = 1e9+7;
const int mod = 1e9+7;
const int inv2 = 500000004;

int n,w[N],h[N],ans;

int comb2(int x){
    return x*(x-1)%mod*inv2%mod;
}

int32_t main(){
    fastio()
    cin >> n;
    for(int i=0;i<n;i++)
        cin >> h[i];
    for(int i=0;i<n;i++)
        cin >> w[i];
    vector<pii> vec;
    vec.pb({0,0});
    for(int i=0;i<=n;i++){
        int len=0;
        while(vec.back().st>h[i]){
            int prv=max(h[i],vec[(int)vec.size()-2].st);
            int dif=vec.back().st-prv;
            len=(len+vec.back().nd)%mod;
            vec.pop_back();
            ans+=((comb2(dif+1)+(dif*prv)%mod))*comb2(len+1);
            ans%=mod;
        }
        if(vec.back().st==h[i]){
            vec.back().nd=(vec.back().nd+len+w[i])%mod;
        }
        else{
            vec.pb({h[i],(len+w[i])%mod});
        }
    }
    cout << ans << nl;
}
# 결과 실행 시간 메모리 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 1 ms 364 KB Output is correct
3 Correct 10 ms 1772 KB Output is correct
4 Correct 20 ms 3052 KB Output is correct
5 Correct 25 ms 3052 KB Output is correct
6 Correct 20 ms 3052 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 3 ms 748 KB Output is correct
3 Correct 13 ms 2156 KB Output is correct
4 Correct 25 ms 3820 KB Output is correct
5 Correct 28 ms 3948 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 3 ms 748 KB Output is correct
4 Correct 14 ms 2156 KB Output is correct
5 Correct 26 ms 3820 KB Output is correct
6 Correct 28 ms 3948 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 3 ms 1132 KB Output is correct
9 Correct 14 ms 2800 KB Output is correct
10 Correct 27 ms 5920 KB Output is correct
11 Correct 28 ms 5992 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 1 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 1 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 384 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 10 ms 1772 KB Output is correct
12 Correct 20 ms 3052 KB Output is correct
13 Correct 20 ms 3052 KB Output is correct
14 Correct 20 ms 3052 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 3 ms 748 KB Output is correct
17 Correct 14 ms 2156 KB Output is correct
18 Correct 25 ms 3820 KB Output is correct
19 Correct 28 ms 3948 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 4 ms 1132 KB Output is correct
22 Correct 14 ms 2944 KB Output is correct
23 Correct 27 ms 6140 KB Output is correct
24 Correct 36 ms 5992 KB Output is correct
25 Correct 1 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 3 ms 748 KB Output is correct
31 Correct 3 ms 748 KB Output is correct
32 Correct 13 ms 2028 KB Output is correct
33 Correct 16 ms 2156 KB Output is correct
34 Correct 26 ms 3692 KB Output is correct
35 Correct 26 ms 3692 KB Output is correct
36 Correct 27 ms 3820 KB Output is correct
37 Correct 27 ms 3948 KB Output is correct
38 Correct 1 ms 364 KB Output is correct
39 Correct 26 ms 3820 KB Output is correct
40 Correct 27 ms 3820 KB Output is correct
41 Correct 26 ms 4208 KB Output is correct
42 Correct 34 ms 4972 KB Output is correct