답안 #742538

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
742538 2023-05-16T12:37:57 Z Dan4Life Fancy Fence (CEOI20_fancyfence) C++17
0 / 100
1 ms 340 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define sz(a) (int)a.size()
const int mxN = (int)1e5+10;
const int MOD = (int)1e9+7;

int Tw, Th;
int n, h[mxN], w[mxN];
vector<pair<int,int>> v;

int poww(int a, int b){
	if(!b) return 1;
	int x = poww(a,b/2);
	x*=x, x%=MOD;
	if(b&1) x*=a, x%=MOD;
	return x;
}

int32_t main(){
	cin >> n; int ans = 0; int div2 = poww(2,MOD-2);
	for(int i = 1; i <= n; i++) cin >> h[i];
	for(int i = 1; i <= n; i++) cin >> w[i];
	for(int i = 1; i <= n; i++){
		int W = w[i]; Tw+=w[i], Th+=h[i]; Tw%=MOD, Th%=MOD;
		while(i<n and h[i]==h[i+1]) W+=w[++i], W%=MOD;
		v.pb({h[i],W});
	}
	ans = Tw*(Tw+1); ans%=MOD; ans*=div2; ans%=MOD;
	n = sz(v);
	for(auto [h,w] : v){
		//cout << h << " " << w << "\n";
 		if(h==1) continue;
		ans+=w*(w+1); ans%=MOD;
	}
	cout << ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 1 ms 340 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 1 ms 340 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 1 ms 328 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 1 ms 340 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 1 ms 340 KB Output isn't correct
3 Halted 0 ms 0 KB -