Submission #945715

# Submission time Handle Problem Language Result Execution time Memory
945715 2024-03-14T06:38:36 Z Sandarach151 Fancy Fence (CEOI20_fancyfence) C++17
60 / 100
19 ms 3936 KB
#include <bits/stdc++.h>
using namespace std;

#define int long long

const int MODD = 1e9+7;
const int INV = 5e8+4;

int mult(int n){
	int temp = 1;
	temp *= (n);
	temp %= MODD;
	temp *= (n+1);
	temp %= MODD;
	temp *= INV;
	temp %= MODD;
	return temp;
}

signed main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n;
	cin >> n;
	int h[n];
	int w[n];
	bool same = true;
	bool less = true;
	for(int i=0; i<n; i++){
		cin >> h[i];
		if(i>0 && h[i]!=h[i-1]){
			same = false;
		}
		if(i>0 && h[i]<h[i-1]){
			less = false;
		}
	}
	for(int i=0; i<n; i++){
		cin >> w[i];
	}
	if(n<=1000){
		int ans = 0;
		for(int i=0; i<n; i++){
			int temp = mult(w[i]);
			temp %= MODD;
			temp *= mult(h[i]);
			temp %= MODD;
			ans += temp;
			ans %= MODD;
		}
		for(int i=0; i<n; i++){
			int minn = h[i];
			for(int j=i+1; j<n; j++){
				minn = min(minn, h[j]);
				int temp = w[i]*w[j];
				temp %= MODD;
				temp *= mult(minn);
				temp %= MODD;
				ans += temp;
				ans %= MODD;
			}
		}
		cout << ans << '\n';
	}
	else if(same){
		int summ = 0;
		for(int i=0; i<n; i++){
			summ += w[i];
			summ %= MODD;
		}
		int ans = mult(h[0]);
		ans *= mult(summ);
		ans %= MODD;
		cout << ans << '\n';
	}
	else if(less){
		int ans = 0;
		for(int i=0; i<n; i++){
			int temp = mult(w[i]);
			temp %= MODD;
			temp *= mult(h[i]);
			temp %= MODD;
			ans += temp;
			ans %= MODD;
		}
		int summ = 0;
		for(int i=0; i<n; i++){
			summ += w[i];
			summ %= MODD;
		}
		for(int i=0; i<n; i++){
			summ -= w[i];
			summ += MODD;
			summ %= MODD;
			int temp = w[i]*summ;
			temp %= MODD;
			temp *= mult(h[i]);
			temp %= MODD;
			ans += temp;
			ans %= MODD;
		}
		cout << ans << '\n';
	}	
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 5 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 5 ms 348 KB Output is correct
3 Incorrect 7 ms 1624 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 348 KB Output is correct
2 Correct 2 ms 604 KB Output is correct
3 Correct 8 ms 2204 KB Output is correct
4 Correct 16 ms 3784 KB Output is correct
5 Correct 17 ms 3924 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 5 ms 348 KB Output is correct
3 Correct 2 ms 608 KB Output is correct
4 Correct 8 ms 2140 KB Output is correct
5 Correct 16 ms 3920 KB Output is correct
6 Correct 17 ms 3936 KB Output is correct
7 Correct 5 ms 348 KB Output is correct
8 Correct 2 ms 800 KB Output is correct
9 Correct 10 ms 2144 KB Output is correct
10 Correct 19 ms 3664 KB Output is correct
11 Correct 19 ms 3932 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 5 ms 484 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 456 KB Output is correct
8 Correct 6 ms 476 KB Output is correct
9 Correct 5 ms 348 KB Output is correct
10 Correct 5 ms 348 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 2 ms 604 KB Output is correct
13 Correct 5 ms 348 KB Output is correct
14 Correct 5 ms 348 KB Output is correct
15 Correct 5 ms 468 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 5 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 5 ms 476 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 500 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 5 ms 348 KB Output is correct
11 Incorrect 6 ms 1748 KB Output isn't correct
12 Halted 0 ms 0 KB -