답안 #598272

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
598272 2022-07-17T22:02:08 Z _Avocado_ Fancy Fence (CEOI20_fancyfence) C++14
100 / 100
49 ms 6656 KB
#include <bits/stdc++.h>
#define int int64_t
using namespace std;

int mod = 1e9+7;
int ans = 0;

int sum(int n){
	n %= mod;
	return (((n*(n+1)))/2)%mod;
}

int find(int a, auto&par){
	if(a == par[a]) return a;
	return par[a] = find(par[a], par);
}

void unite(int a, int b, int h, auto&par, auto&w){
	a = find(a, par);
	b = find(b, par);
	int minus = (((sum(w[a]) * sum(h))%mod) + (sum(w[b]) * sum(h)))%mod;
	//cout<<"minus "<<minus<<endl;
	ans = (ans + ((sum(w[a] + w[b]) * sum(h))%mod - minus + mod)%mod)%mod;
	
	par[b] = a;
	w[a] = (w[a] + w[b])%mod;
	
}

signed main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	//ifstream cin ("input.in");
	//ofstream cout ("output.out");
	
	int n; cin>>n;
	vector<pair<int, int>>height(n);
	vector<int>w(n);
	
	for(int i = 0; i<n; ++i){
		int a; cin>>a;
		height[i] = {a, i};
	}
	for(auto&u: w) cin>>u;
	
	for(int i = 0; i<n; ++i){
		ans = (ans + (sum(height[i].first) * sum(w[i]))%mod)%mod;
	}
	//cout<<ans<<endl;
	vector<int>par(n);
	iota(par.begin(), par.end(), 0);
	vector<int>fred(n);
	
	sort(height.begin(), height.end());
	reverse(height.begin(), height.end());
	
	for(int i = 0; i<n; ++i){
		int cur = height[i].second;
		if(cur != 0 && fred[cur-1]) unite(cur, cur-1, height[i].first, par, w);
		if(cur != n-1 && fred[cur+1]) unite(cur, cur+1, height[i].first, par, w);
		fred[cur] = 1;
	}
	cout<<ans;	
	cout<<'\n';
}

Compilation message

fancyfence.cpp:13:17: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
   13 | int find(int a, auto&par){
      |                 ^~~~
fancyfence.cpp:18:33: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
   18 | void unite(int a, int b, int h, auto&par, auto&w){
      |                                 ^~~~
fancyfence.cpp:18:43: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
   18 | void unite(int a, int b, int h, auto&par, auto&w){
      |                                           ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 324 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 320 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 17 ms 2768 KB Output is correct
4 Correct 31 ms 5404 KB Output is correct
5 Correct 34 ms 5404 KB Output is correct
6 Correct 32 ms 5360 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 4 ms 852 KB Output is correct
3 Correct 18 ms 3160 KB Output is correct
4 Correct 36 ms 6120 KB Output is correct
5 Correct 37 ms 6244 KB Output is correct
6 Correct 1 ms 320 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 4 ms 852 KB Output is correct
4 Correct 19 ms 3136 KB Output is correct
5 Correct 36 ms 6164 KB Output is correct
6 Correct 37 ms 6280 KB Output is correct
7 Correct 1 ms 328 KB Output is correct
8 Correct 4 ms 848 KB Output is correct
9 Correct 18 ms 3284 KB Output is correct
10 Correct 33 ms 5964 KB Output is correct
11 Correct 37 ms 6116 KB Output is correct
12 Correct 0 ms 320 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 0 ms 324 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 324 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 372 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 320 KB Output is correct
9 Correct 0 ms 320 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 18 ms 2860 KB Output is correct
12 Correct 31 ms 5360 KB Output is correct
13 Correct 34 ms 5404 KB Output is correct
14 Correct 34 ms 5360 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 4 ms 852 KB Output is correct
17 Correct 18 ms 3160 KB Output is correct
18 Correct 39 ms 6092 KB Output is correct
19 Correct 46 ms 6232 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 6 ms 852 KB Output is correct
22 Correct 19 ms 3292 KB Output is correct
23 Correct 35 ms 6036 KB Output is correct
24 Correct 37 ms 6120 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 6 ms 852 KB Output is correct
31 Correct 5 ms 844 KB Output is correct
32 Correct 22 ms 3156 KB Output is correct
33 Correct 21 ms 3156 KB Output is correct
34 Correct 42 ms 5964 KB Output is correct
35 Correct 49 ms 5868 KB Output is correct
36 Correct 43 ms 6092 KB Output is correct
37 Correct 42 ms 6116 KB Output is correct
38 Correct 0 ms 212 KB Output is correct
39 Correct 41 ms 6124 KB Output is correct
40 Correct 39 ms 6088 KB Output is correct
41 Correct 37 ms 6252 KB Output is correct
42 Correct 34 ms 6656 KB Output is correct