Submission #922050

# Submission time Handle Problem Language Result Execution time Memory
922050 2024-02-04T22:28:03 Z Alebn Fancy Fence (CEOI20_fancyfence) C++14
73 / 100
24 ms 6228 KB
#include <bits/stdc++.h>
 
#define int long long
#define sz(x) (int)(x.size())
 
using namespace std;
 
const int mod=1000000007;
 
int MOD(int x) {
	return (x+3*mod)%mod;
}
 
struct sections {
	int H=0, W=0;
};
 
int n, k, m;
vector<sections> a;
 
int section(int h, int w) {
	h%=mod, w%=mod;
	int facteur=MOD((h*(h+1))/2);
	int ans=MOD((w*(w+1))/2);
	return MOD(ans*facteur);
}
 
 
int subtask2() {
	int ans=0;
	for (int i=0; i<n; i++) ans=MOD(ans+a[i].W);
	ans=MOD((ans*(ans+1))/2);
	for (int i=0; i<n; i++) {
		if (a[i].H==1) continue;
		ans=MOD(ans+section(1, a[i].W)*2);
	}
	return ans;
}
 
int subtask4() {
	int L=0;
	for (int i=0; i<n; i++) L+=a[i].W;
	int ans=0;
	for (int i=0; i<n; i++) {
		int sec=section(a[i].H, L);
		if (i) sec-=section(a[i-1].H, L);
		L-=a[i].W;
		ans=MOD(ans+MOD(sec));
	}
	return ans;
}
 
int subtask5() {
	int ans=0;
	for (int i=0; i<n; i++) {
		int mini=a[i].H;
		int sum=a[i].W;
		ans=MOD(ans+section(a[i].W, a[i].H)); //i=j
		for (int j=i+1; j<n; j++) { //i!=j
			mini=min(mini, a[j].H);
			int res=section(mini, sum); // toute la section entre i et j
			res-=MOD(section(mini, sum-a[i].W)+section(mini, sum-a[j].W)); // j'enlève tous les points qui ne commencent pas
			res=MOD(res);                                             // par j ou par i
			res+=section(mini, sum-a[i].W-a[j].W);                    // je rajoute ce que j'ai enlevé de trop (a+b)^2
			ans=MOD(ans+MOD(res));
		}
	}
	return ans;
}
 
int solve() {
	cin >> n;
	a.clear();
	a.resize(n);
	bool sub2=true;
	for (auto &u: a) {
		cin >> u.H;
		if (u.H>2) sub2=false;
	}
	for (auto &u: a) {
		cin >> u.W;
	}
	vector<sections> temp;
	for (int i=0; i<n; i++) {
		if (!temp.empty() && a[i].H==temp.back().H) temp.back().W+=a[i].W;
		else temp.push_back(a[i]);
	}
	a.clear();
	a=temp;
	n=a.size();
	if (sub2) return subtask2();
	if (n<=1000) return subtask5();
	return subtask4();
}
 
 
signed main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout << solve() << endl;
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 11 ms 500 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 456 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 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 344 KB Output is correct
3 Correct 7 ms 2272 KB Output is correct
4 Correct 13 ms 3812 KB Output is correct
5 Correct 13 ms 4316 KB Output is correct
6 Correct 13 ms 3808 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 3 ms 600 KB Output is correct
3 Correct 8 ms 1116 KB Output is correct
4 Correct 16 ms 3932 KB Output is correct
5 Correct 19 ms 3804 KB Output is correct
6 Correct 0 ms 600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 2 ms 604 KB Output is correct
4 Correct 8 ms 1196 KB Output is correct
5 Correct 16 ms 3928 KB Output is correct
6 Correct 16 ms 3932 KB Output is correct
7 Correct 11 ms 348 KB Output is correct
8 Correct 2 ms 992 KB Output is correct
9 Correct 9 ms 2784 KB Output is correct
10 Correct 18 ms 5980 KB Output is correct
11 Correct 24 ms 6228 KB Output is correct
12 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 11 ms 500 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 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 348 KB Output is correct
9 Correct 1 ms 472 KB Output is correct
10 Correct 10 ms 344 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 4 ms 604 KB Output is correct
13 Correct 11 ms 348 KB Output is correct
14 Correct 11 ms 348 KB Output is correct
15 Correct 11 ms 348 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 11 ms 500 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 10 ms 348 KB Output is correct
5 Correct 0 ms 456 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 1 ms 464 KB Output is correct
11 Correct 8 ms 2272 KB Output is correct
12 Correct 15 ms 4068 KB Output is correct
13 Correct 14 ms 4352 KB Output is correct
14 Correct 17 ms 3808 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 2 ms 604 KB Output is correct
17 Correct 9 ms 2012 KB Output is correct
18 Correct 16 ms 3928 KB Output is correct
19 Correct 16 ms 4068 KB Output is correct
20 Correct 10 ms 348 KB Output is correct
21 Correct 2 ms 1112 KB Output is correct
22 Correct 9 ms 2784 KB Output is correct
23 Correct 19 ms 5976 KB Output is correct
24 Correct 18 ms 6124 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 3 ms 348 KB Output is correct
27 Correct 11 ms 528 KB Output is correct
28 Correct 11 ms 348 KB Output is correct
29 Correct 11 ms 348 KB Output is correct
30 Incorrect 3 ms 1080 KB Output isn't correct
31 Halted 0 ms 0 KB -