답안 #295420

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
295420 2020-09-09T16:32:46 Z PedroBigMan Fancy Fence (CEOI20_fancyfence) C++14
40 / 100
34 ms 7852 KB
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <queue>
#include <deque>
#include <list>
#include <iomanip>
#include <stdlib.h>
#include <time.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
#define REP(i,a,b) for(ll i=a; i<b; i++)
#define pb push_back
#define mp make_pair
#define pl pair<ll,ll>
#define ff first
#define ss second
#define whole(x) x.begin(),x.end()
#define DEBUG(i) cout<<"Pedro Is The Master "<<i<<endl
#define INF 5000000000000000000LL

template<class A=ll> 
void Out(vector<A> a) {REP(i,0,a.size()) {cout<<a[i]<<" ";} cout<<endl;}

template<class A=ll>
void In(vector<A> &a, ll N) {A cur; REP(i,0,N) {cin>>cur; a.pb(cur);}} 

ll mod=1000000007LL;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    ll N; cin>>N; vector<ll> h,w; In(h,N); In(w,N);
    vector<ll> NSL, NSR;
    REP(i,0,N) {NSL.pb(-1LL); NSR.pb(N);}
    vector<ll> chain; 
    REP(i,0,N)
    {
        while(chain.size()>0 && h[i]<h[chain[chain.size()-1]]) {chain.pop_back();}
        chain.pb(i);
        if(chain.size()>1) {NSL[i]=chain[chain.size()-2];}
    }
    chain.clear();
    for(ll i=N-1;i>=0;i--)
    {
        while(chain.size()>0 && h[i]<=h[chain[chain.size()-1]]) {chain.pop_back();}
        chain.pb(i);
        if(chain.size()>1) {NSR[i]=chain[chain.size()-2];}
    }
    vector<ll> ps; ll sum=0LL; ps.pb(sum); REP(i,0,N) {sum+=w[i]; sum%=mod; ps.pb(sum);}
    if(*min_element(whole(h))==*max_element(whole(h)))
    {
        ll ans = (ps[N]*(ps[N]+1LL))/2LL; ans%=mod; ans*=(((h[0]*(h[0]+1LL))/2LL)%mod); 
        ans%=mod; if(ans<0) {ans+=mod;} 
        bool ok1 =true;
        REP(i,0,N) 
        {
            if(NSL[i]!=i-1) {ok1=false;}
            if(NSR[i]!=N) {ok1=false;}
        }
        if(1!=0) {ok1=false;}
        if(!ok1) {cout<<ans<<endl; return 0;}
    }
    ll t_ans=0LL;
    REP(s,0,N)
    {
        ll L = NSL[s]+1LL;
        ll R = NSR[s]-1LL;
        ll W1 = ps[s]-ps[L]; W1%=mod; ll W2 = ps[R+1]-ps[s+1]; W2%=mod;
        ll ans = W1*W2 + W1*w[s] + W2*w[s] + (w[s]*(w[s]+1LL))/2LL;
        ans%=mod; ans*=((h[s]*(h[s]+1LL))/2LL);
        ans%=mod; 
        t_ans+=ans; 
        t_ans%=mod;
    }
    if(t_ans<0) {t_ans+=mod;}
    cout<<t_ans<<endl;
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Incorrect 1 ms 384 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 14 ms 3068 KB Output is correct
4 Correct 30 ms 5656 KB Output is correct
5 Correct 29 ms 5656 KB Output is correct
6 Correct 28 ms 5396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 4 ms 1152 KB Output is correct
3 Correct 15 ms 3624 KB Output is correct
4 Correct 30 ms 6036 KB Output is correct
5 Correct 33 ms 6040 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 3 ms 1152 KB Output is correct
4 Correct 15 ms 4124 KB Output is correct
5 Correct 32 ms 7840 KB Output is correct
6 Correct 34 ms 7852 KB Output is correct
7 Incorrect 1 ms 384 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Incorrect 1 ms 384 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Incorrect 1 ms 384 KB Output isn't correct