답안 #1008251

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1008251 2024-06-26T08:38:37 Z kaysan Fancy Fence (CEOI20_fancyfence) C++17
0 / 100
1 ms 348 KB
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define pp pop_back
#define fi first
#define se second
#define lb lower_bound
#define ub upper_bound
#define pll pair<ll,ll> 
#define pii pair<int,int> 
#define vl vector<ll> 
#define nikah ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const ll maxn = 1e5+7, modn1 = 1e9+7, modn2 = 998244353;
using namespace std;

// kalo kamu ngga emas nanti nadya merasa bersalah, ayo san demi nadya!!!
// Kalo emang soalnya susah, pindah soal dulu 
// Jangan sampe diem, pikirin sesuatu, pasti bisa!!!
// Cobain semua approach, jangan ngestuck di satu pemikiran
// Jangan overthinking, jangan panik, tenangin pikiranmu


ll t,n;
ll h[maxn], w[maxn];
vector<ll>v,b;

ll f (ll x) {
	return ((x * (x+1)) / 2) % modn1;
}

void solve () {
	v.pb(0); b.pb(0);
	cin>>n;
	for (ll i=1; i<=n; i++) {
		cin>>h[i];
	}
	for (ll i=1; i<=n; i++) {
		cin>>w[i];
		if (i>1) { 
			if (h[i] != h[i-1]) {
				v.pb(h[i-1]);
				b.pb(w[i-1]);
			} else {
				w[i] += w[i-1];
			}
		}
	}
	v.pb(h[n]); b.pb(w[n]);
	ll ans = 0, cur = 1, cnt = 0, N = v.size();
	bool inc = 0, dec = 0;
	for (ll i=1; i<N; i++) {
		if (i == N - 1) {
			if (dec) {
				ll cnt2 = 0;
				for (ll j=i; j>=cur; j--) {
					cnt2 += b[j];
					if (j == i) ans = (ans + ((f(b[j]) * f(v[j])) % modn1)) % modn1;
					else {
						ans = (ans + ((f(cnt2) * f(v[j])) % modn1)) % modn1;
						ans = (ans - ((f(cnt2 - b[j]) * f(v[j])) % modn1)) % modn1;
					}
				}
				dec = 0;
			} else {
				cnt += b[i];
				if (inc == 0) ans = (ans + ((f(b[i]) * f(v[i])) % modn1)) % modn1;
				else {
					ans = (ans + ((f(cnt) * f(v[i])) % modn1)) % modn1;
					ans = (ans - ((f(cnt - b[i]) * f(v[i])) % modn1)) % modn1;
				}
			}
		} else if (v[i] > v[i+1]) {
			if (dec) {
				ll cnt2 = 0;
				for (ll j=i; j>=cur; j--) {
					cnt2 += b[j];
					if (j == i) ans = (ans + ((f(b[j]) * f(v[j])) % modn1)) % modn1;
					else {
						ans = (ans + ((f(cnt) * f(v[j])) % modn1)) % modn1;
						ans = (ans - ((f(cnt - b[j]) * f(v[j])) % modn1)) % modn1;
					}
				}
				dec = 0;
			} else {
				cnt += b[i];
				if (inc == 0) ans = (ans + ((f(b[i]) * f(v[i])) % modn1)) % modn1;
				else {
					ans = (ans + ((f(cnt) * f(v[i])) % modn1)) % modn1;
					ans = (ans - ((f(cnt - b[i]) * f(v[i])) % modn1)) % modn1;
				}
			}
			inc = 1;
		} else {
			if (!dec) {
				cur = i;
				inc = 0;
				cnt = 0;
			}
			dec = 1;
		}
	//	cout<<i<<" : "<<ans<<endl;
	}
	while (ans < 0) ans += modn1;
	cout<<ans<<endl;
}           


int main () {
  nikah
  t = 1;
//  cin>>t;
  while (t--) {
    solve();
  //  cout<<endl;
  }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Incorrect 1 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 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 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 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 344 KB Output is correct
2 Incorrect 1 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -