답안 #959374

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
959374 2024-04-08T06:16:20 Z ALTAKEXE Fancy Fence (CEOI20_fancyfence) C++17
0 / 100
1 ms 424 KB
#include<bits/stdc++.h>
using namespace std;
#define f first
#define s second
#define ll long long
const ll mod=1e9+7;
int main() {
	int n;
	cin>>n;
	vector<ll> h(n+1,0), w(n+1,0);
	for(int i=0;i<n;++i) cin>>h[i];
	for(int i=0;i<n;++i) cin>>w[i];
	n++;
	vector<pair<ll,ll>> t; 
	t.push_back({0,0});
	ll ans=0;
	for(int i=0;i<n;++i) {
		ll sum=0;
		while(t.back().f>h[i]) { 
			ll mn=max(h[i],t[t.size()-2].f); 
			ll mx=t.back().f-mn; 
			sum=(sum+t.back().s)%mod;
			t.pop_back();
			ans+=(mx*(mx+1)*500000004+mx*mn)*(sum*(sum+1)*500000004)%mod;
			ans%=mod;
		}
		if(t.back().f==h[i]) t.back().s=(t.back().s+sum+w[i]);
		else t.push_back({h[i], sum+w[i]});
	}
	cout<<ans<<endl;
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 1 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 1 ms 424 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 1 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Incorrect 1 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 1 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -