답안 #898425

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
898425 2024-01-04T16:13:45 Z LCJLY Fancy Fence (CEOI20_fancyfence) C++14
100 / 100
27 ms 6104 KB
#include <bits/stdc++.h>
using namespace std;
 
#define int long long
#define ld long double
#define show(x,y) cout << y << " " << #x << endl;
#define show2(x,y,i,j) cout << y << " " << #x << "  " << j << " " << #i << endl;
#define show3(x,y,i,j,p,q) cout << y << " " << #x << "  " << j << " " << #i << "  " << q << " " << #p << endl; 
#define show4(x,y) for(auto it:x) cout << it << " "; cout << #y << endl;
typedef pair<int,int>pii;
typedef pair<pii,pii>pi2;

int mod=1e9+7;
int f(int a, int b){
	a%=mod;
	b%=mod;
	return (a*b)%mod;
}

int calc(int n){
	int hold=f(f(n,n+1),500000004);
	return hold;
}

int len(int a, int b){
	return b-a;
}

void solve(){	
	int n;
	cin >> n;

	pii arr[n];
	for(int x=0;x<n;x++){
		cin >> arr[x].first;
	}
	
	for(int x=0;x<n;x++){
		cin >> arr[x].second;
		//w+=arr[x].second;
	}
	
	//int last=0;
	//int counter=0;
	//int pos=1;
	//for(int x=0;x<n;x++){
		//if(arr[x].first>last){
			//int hold=(calc(arr[x].first)-calc(last)+mod)%mod;
			//counter=(counter+f(hold,calc(len(pos,w))))%mod;
			//last=arr[x].first;
		//}
		//pos+=arr[x].second;
	//}
	
	//counter%=mod;
	
	//cout << counter;
	
	vector<pii>stk; //h pos
	stk.push_back({0,0});
	int pos=1;
	
	int counter=0;
	for(int x=0;x<n;x++){
		int cur=pos;
		while(!stk.empty()&&arr[x].first<stk.back().first){
			int sz=stk.size();
			int w=len(stk[sz-1].second,pos);
			int h1=stk[sz-1].first;
			int h2=max(stk[sz-2].first,arr[x].first);
			//show2(h1,h1,h2,h2);
			int hold=(calc(h1)-calc(h2)+mod)%mod;
			counter=(counter+f(hold,calc(w)))%mod;
			cur=stk[sz-1].second;
			stk.pop_back();
		}
		if(arr[x].first!=stk.back().first){
			stk.push_back({arr[x].first,cur});
		}
		pos+=arr[x].second;
	}
	//show(counter,counter);
	while(stk.size()>1){
		int sz=stk.size();
		int w=len(stk[sz-1].second,pos);
		int h1=stk[sz-1].first;
		int h2=stk[sz-2].first;
		int hold=(calc(h1)-calc(h2)+mod)%mod;
		counter=(counter+f(hold,calc(w)))%mod;
		stk.pop_back();
	}
	
	cout << counter;
}
 
int32_t main(){										
	ios::sync_with_stdio(0);	
	cin.tie(0);
	//freopen("redistricting.in", "r", stdin);
	//freopen("redistricting.out", "w", stdout);
	int t=1;
	//cin >> t;
	while(t--){
		solve();
	}	
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 460 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 7 ms 1816 KB Output is correct
4 Correct 22 ms 3160 KB Output is correct
5 Correct 14 ms 3164 KB Output is correct
6 Correct 13 ms 3280 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 2 ms 604 KB Output is correct
3 Correct 8 ms 1116 KB Output is correct
4 Correct 15 ms 1884 KB Output is correct
5 Correct 16 ms 1884 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 3 ms 604 KB Output is correct
4 Correct 8 ms 1232 KB Output is correct
5 Correct 18 ms 1884 KB Output is correct
6 Correct 15 ms 2012 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 3 ms 860 KB Output is correct
9 Correct 15 ms 1760 KB Output is correct
10 Correct 26 ms 4056 KB Output is correct
11 Correct 27 ms 4052 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 368 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 1 ms 488 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 0 ms 600 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 7 ms 1628 KB Output is correct
12 Correct 14 ms 3164 KB Output is correct
13 Correct 14 ms 3164 KB Output is correct
14 Correct 13 ms 3164 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 2 ms 604 KB Output is correct
17 Correct 11 ms 2140 KB Output is correct
18 Correct 16 ms 3912 KB Output is correct
19 Correct 19 ms 4192 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 3 ms 972 KB Output is correct
22 Correct 11 ms 2784 KB Output is correct
23 Correct 27 ms 6020 KB Output is correct
24 Correct 27 ms 6104 KB Output is correct
25 Correct 0 ms 344 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 3 ms 604 KB Output is correct
31 Correct 3 ms 604 KB Output is correct
32 Correct 12 ms 2120 KB Output is correct
33 Correct 13 ms 2136 KB Output is correct
34 Correct 25 ms 3668 KB Output is correct
35 Correct 24 ms 3668 KB Output is correct
36 Correct 27 ms 3932 KB Output is correct
37 Correct 26 ms 3792 KB Output is correct
38 Correct 0 ms 344 KB Output is correct
39 Correct 25 ms 3932 KB Output is correct
40 Correct 26 ms 3932 KB Output is correct
41 Correct 27 ms 4188 KB Output is correct
42 Correct 27 ms 5076 KB Output is correct