답안 #1008286

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1008286 2024-06-26T08:53:53 Z andecaandeci Fancy Fence (CEOI20_fancyfence) C++17
100 / 100
57 ms 11208 KB
#include <bits/stdc++.h>
using namespace std;
#define pii pair<ll,ll>
#define REP(i,x,y) for(ll i=x;i<=y;i++)
#define freeopen freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
#define pb push_back
#define mk make_pair
#define ll long long
#define foor(x,vec) for(auto x:vec ){cout<<x<<" ";}
#define fi first
#define se second
#define MAXN 700069
#define lld long double
#define cha ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ffl fflush(stdout)
#define sst string
#define pii pair<ll,ll>
ll mvx[]={0,0,-1,1};
ll mvy[]={1,-1,0,0};
ll n,q;
ll a,b;
ll h[MAXN],w[MAXN];
ll ps[MAXN];
ll dp[MAXN];
ll idx[MAXN];
const ll mod =1e9+7;
ll add(ll x, ll y) {
    ll res=(x+y+mod)%mod;
    return res;
}
 
 
ll cal(ll x) {
    return (ll)((1ll * x * (x + 1) / 2) % mod);
}
ll mult(ll x, ll y) {
    return (ll)((1ll * x * y) % mod);
}
 
 
int main(){
    cin>>n;
    REP(i,1,n)cin>>h[i];
    REP(i,1,n)cin>>w[i];
    REP(i,1,n){
        ps[i]=ps[i-1]+w[i];
        ps[i]%=mod;
    }
    vector <ll> vec;
    vec.pb(0);
    for(ll i = 1; i <= n; i++) {
        while(vec.size() && h[i] < h[vec.back()]) {
            vec.pop_back();
        }
        assert(vec.size());
        idx[i] = vec.back();
        vec.pb(i);
    }
    ll ans=0;
    REP(i,1,n){
        dp[i] = add(dp[idx[i]], mult((ps[i]-ps[idx[i]]+mod)%mod, cal(h[i])));
        ll val = mult(dp[idx[i]], w[i]);
        // ini buat sebelumnya
        val = add(val, mult(cal(w[i] ), cal(h[i] )));
        val = add(val, mult( (ps[i - 1] - ps[idx[i]]+mod)%mod, mult(w[i], cal(h[i]))));
        // ini buat diantara
        // ini buat sendiri
        ans = add(ans, val);
    }
    ans=(ans+mod)%mod;
    cout<<ans<<endl;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4440 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 18 ms 9688 KB Output is correct
4 Correct 32 ms 11044 KB Output is correct
5 Correct 44 ms 9268 KB Output is correct
6 Correct 36 ms 10424 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 6 ms 4956 KB Output is correct
3 Correct 29 ms 8148 KB Output is correct
4 Correct 47 ms 9776 KB Output is correct
5 Correct 45 ms 9768 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 2 ms 4444 KB Output is correct
3 Correct 5 ms 4804 KB Output is correct
4 Correct 25 ms 8248 KB Output is correct
5 Correct 49 ms 9780 KB Output is correct
6 Correct 57 ms 11208 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 5 ms 4956 KB Output is correct
9 Correct 25 ms 8148 KB Output is correct
10 Correct 42 ms 9720 KB Output is correct
11 Correct 47 ms 9760 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 2392 KB Output is correct
3 Correct 0 ms 2392 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 0 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 0 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 1 ms 2392 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 1 ms 4440 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 0 ms 4444 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 0 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 0 ms 2396 KB Output is correct
8 Correct 1 ms 4440 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 16 ms 6200 KB Output is correct
12 Correct 34 ms 8196 KB Output is correct
13 Correct 38 ms 7884 KB Output is correct
14 Correct 32 ms 7508 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 5 ms 4956 KB Output is correct
17 Correct 30 ms 4484 KB Output is correct
18 Correct 50 ms 6332 KB Output is correct
19 Correct 55 ms 6440 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 6 ms 3000 KB Output is correct
22 Correct 25 ms 4556 KB Output is correct
23 Correct 41 ms 8268 KB Output is correct
24 Correct 51 ms 6340 KB Output is correct
25 Correct 0 ms 2396 KB Output is correct
26 Correct 1 ms 2392 KB Output is correct
27 Correct 1 ms 2396 KB Output is correct
28 Correct 1 ms 2396 KB Output is correct
29 Correct 1 ms 2396 KB Output is correct
30 Correct 5 ms 2652 KB Output is correct
31 Correct 5 ms 4700 KB Output is correct
32 Correct 23 ms 5872 KB Output is correct
33 Correct 22 ms 3932 KB Output is correct
34 Correct 43 ms 7504 KB Output is correct
35 Correct 42 ms 7508 KB Output is correct
36 Correct 48 ms 5468 KB Output is correct
37 Correct 46 ms 7464 KB Output is correct
38 Correct 1 ms 4440 KB Output is correct
39 Correct 54 ms 5520 KB Output is correct
40 Correct 42 ms 7508 KB Output is correct
41 Correct 47 ms 5828 KB Output is correct
42 Correct 45 ms 7892 KB Output is correct