답안 #859230

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
859230 2023-10-10T02:05:15 Z willychan Sightseeing in Kyoto (JOI22_kyoto) C++14
100 / 100
23 ms 3156 KB
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include<bits/extc++.h>
//__gnu_pbds



int main(){
	ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	int h,w;cin>>h>>w;
	vector<pair<int,int> > ah;
	vector<pair<int,int> > bh;
	for(int i=1;i<=h;i++){
		int a;cin>>a;
		while(ah.size()>=2){
			int g = ah.size();
			if(1LL*(ah[g-1].first-ah[g-2].first)*(a-ah[g-1].second)<=1LL*(i-ah[g-1].first)*(ah[g-1].second-ah[g-2].second)) ah.pop_back();
			else break;
		}
		ah.push_back({i,a})	;
	}
	for(int i=1;i<=w;i++){
		int a;cin>>a;
		while(bh.size()>=2){
			int g = bh.size();
			if(1LL*(bh[g-1].first-bh[g-2].first)*(a-bh[g-1].second)<=1LL*(i-bh[g-1].first)*(bh[g-1].second-bh[g-2].second)) bh.pop_back();
			else break;
		}
		bh.push_back({i,a})	;
	}
	
	int x=0;int y=0;
	ll ans = 0;
	while(ah[x].first!=h && bh[y].first!=w){
		if(1LL*(ah[x+1].second-ah[x].second)*(bh[y+1].first-bh[y].first)<1LL*(bh[y+1].second-bh[y].second)*(ah[x+1].first-ah[x].first)){ans+=(1LL*bh[y].second*(ah[x+1].first-ah[x].first));x++;}
		else{ans+=(1LL*ah[x].second*(bh[y+1].first-bh[y].first));y++;}
	}
	if(ah[x].first!=h){
		ans+=1LL*bh[y].second*(h-ah[x].first);
	}
	if(bh[y].first!=w){
		ans+=1LL*ah[x].second*(w-bh[y].first);
	}
	cout<<ans<<"\n";
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 1 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 1 ms 348 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 464 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 456 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 7 ms 780 KB Output is correct
5 Correct 4 ms 600 KB Output is correct
6 Correct 2 ms 472 KB Output is correct
7 Correct 13 ms 1080 KB Output is correct
8 Correct 12 ms 1116 KB Output is correct
9 Correct 13 ms 1116 KB Output is correct
10 Correct 13 ms 1116 KB Output is correct
11 Correct 11 ms 980 KB Output is correct
12 Correct 14 ms 1076 KB Output is correct
13 Correct 12 ms 1116 KB Output is correct
14 Correct 11 ms 1220 KB Output is correct
15 Correct 11 ms 1368 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 452 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 452 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 1 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 1 ms 348 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 464 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 456 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
32 Correct 7 ms 780 KB Output is correct
33 Correct 4 ms 600 KB Output is correct
34 Correct 2 ms 472 KB Output is correct
35 Correct 13 ms 1080 KB Output is correct
36 Correct 12 ms 1116 KB Output is correct
37 Correct 13 ms 1116 KB Output is correct
38 Correct 13 ms 1116 KB Output is correct
39 Correct 11 ms 980 KB Output is correct
40 Correct 14 ms 1076 KB Output is correct
41 Correct 12 ms 1116 KB Output is correct
42 Correct 11 ms 1220 KB Output is correct
43 Correct 11 ms 1368 KB Output is correct
44 Correct 0 ms 348 KB Output is correct
45 Correct 0 ms 348 KB Output is correct
46 Correct 0 ms 348 KB Output is correct
47 Correct 0 ms 348 KB Output is correct
48 Correct 0 ms 452 KB Output is correct
49 Correct 0 ms 348 KB Output is correct
50 Correct 0 ms 348 KB Output is correct
51 Correct 0 ms 348 KB Output is correct
52 Correct 0 ms 452 KB Output is correct
53 Correct 1 ms 348 KB Output is correct
54 Correct 0 ms 348 KB Output is correct
55 Correct 8 ms 1196 KB Output is correct
56 Correct 0 ms 348 KB Output is correct
57 Correct 1 ms 348 KB Output is correct
58 Correct 3 ms 604 KB Output is correct
59 Correct 18 ms 2348 KB Output is correct
60 Correct 20 ms 2212 KB Output is correct
61 Correct 18 ms 2384 KB Output is correct
62 Correct 18 ms 2384 KB Output is correct
63 Correct 18 ms 3156 KB Output is correct
64 Correct 21 ms 2528 KB Output is correct
65 Correct 18 ms 2384 KB Output is correct
66 Correct 23 ms 2340 KB Output is correct
67 Correct 17 ms 2396 KB Output is correct