답안 #295443

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
295443 2020-09-09T16:44:30 Z PedroBigMan Fancy Fence (CEOI20_fancyfence) C++14
30 / 100
1000 ms 3196 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);}
    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;
        if(*min_element(whole(h))==*max_element(whole(h)) && (W1!=0 || R!=N-1LL))
        {
            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 ans = ((W1*W2)%mod) + ((W1*w[s])%mod) + ((W2*w[s])%mod) + (((w[s]*(w[s]+1LL))/2LL)%mod);
        ans%=mod; ans*=(((h[s]*(h[s]+1LL))/2LL)%mod);
        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 1 ms 384 KB Output is correct
2 Correct 3 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 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 3 ms 384 KB Output is correct
3 Execution timed out 1095 ms 3068 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 384 KB Output is correct
2 Correct 229 ms 1144 KB Output is correct
3 Execution timed out 1036 ms 3196 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 3 ms 384 KB Output is correct
3 Correct 233 ms 1064 KB Output is correct
4 Execution timed out 1095 ms 3196 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 3 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 3 ms 384 KB Output is correct
9 Correct 3 ms 384 KB Output is correct
10 Correct 3 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 3 ms 384 KB Output is correct
14 Correct 3 ms 384 KB Output is correct
15 Correct 3 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 3 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 3 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 3 ms 384 KB Output is correct
11 Execution timed out 1094 ms 3068 KB Time limit exceeded
12 Halted 0 ms 0 KB -