답안 #555303

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
555303 2022-04-30T11:27:41 Z Koosha_mv Sightseeing in Kyoto (JOI22_kyoto) C++14
100 / 100
45 ms 5412 KB
#include <bits/stdc++.h>
using namespace std;
#define dbgv(v) cout<<#v<<" = "; f(i,0,v.size()) cout<<v[i]<<" "; cout<<endl
#define dbga(a,x,y) cout<<#a<<" = "; f(i,x,y) cout<<a[i]<<" "; cout<<endl
#define erorp(x) cout<<#x<<"={"<<x.F<<" , "<<x.S<<"}"<<endl
#define eror(x) cout<<#x<<'='<<(x)<<endl
#define f_(i,a,b) for(int i=a;i>=b;i--)
#define f(i,a,b) for(int i=a;i<b;i++)
#define nb(x) __builtin_popcount(x)
#define all(v) v.begin(),v.end()
#define bit(n,k) (((n)>>(k))&1)
#define Add(x,y) x=(x+y)%mod
#define maxm(a,b) a=max(a,b)
#define minm(a,b) a=min(a,b)
#define lst(x) x[x.size()-1]
#define sz(x) int(x.size())
#define mp make_pair
#define ll long long
#define pb push_back
#define S second
#define F first
#define int ll
 
typedef pair<int,int> pii;

const int N=1e5+9,inf=2e9;
 
int n,m,ans,a[N],b[N];
 
bool cmp(pii a,pii b){
	return a.F*b.S<=b.F*a.S;
}
pii get(vector<int> &A,int s,int t){
	return {A[t]-A[s],t-s};
}
int solve(vector<int> A,vector<int> B){
	int n=A.size(),m=B.size(),ida=0,idb=0,res=0;
	f_(i,n-2,0) minm(A[i],A[i+1]);
	f_(i,m-2,0) minm(B[i],B[i+1]);
	vector<int> a,b;
	f(i,0,n){
		a.pb(i);
		while(a.size()>2 && cmp(get(A,a[a.size()-2],a[a.size()-1]),get(A,a[a.size()-3],a[a.size()-2]))){
			a.pop_back();
			a.pop_back();
			a.pb(i);
		}
	}
	f(i,0,m){
		b.pb(i);
		while(b.size()>2 && cmp(get(B,b[b.size()-2],b[b.size()-1]),get(B,b[b.size()-3],b[b.size()-2]))){
			b.pop_back();
			b.pop_back();
			b.pb(i);
		}
	}
	while(ida+1<a.size() || idb+1<b.size()){
		if(ida+1<a.size() && (idb+1==b.size() || cmp(get(A,a[ida],a[ida+1]),get(B,b[idb],b[idb+1])))){
			res+=B[b[idb]]*(a[ida+1]-a[ida]);
			ida++;
		}
		else{
			res+=A[a[ida]]*(b[idb+1]-b[idb]);
			idb++;
		}
	}
	//eror(res);
	return res;
}
 
int32_t main(){
	ios:: sync_with_stdio(0), cin.tie(0), cout.tie(0);
	cin>>n>>m;
	int ida=1,idb=1;
	f(i,1,n+1){
		cin>>a[i];
		if(a[i]<a[ida]) ida=i;
	}
	f(i,1,m+1){
		cin>>b[i];
		if(b[i]<b[idb]) idb=i;
	}
	vector<int> A,B;
	f_(i,ida,1) A.pb(a[i]);
	f_(i,idb,1) B.pb(b[i]);
	ans+=solve(A,B);
	A.clear();
	B.clear();
	f(i,ida,n+1) A.pb(a[i]);
	f(i,idb,m+1) B.pb(b[i]);
	ans+=solve(A,B);
	cout<<ans;
}

Compilation message

kyoto.cpp: In function 'long long int solve(std::vector<long long int>, std::vector<long long int>)':
kyoto.cpp:57:13: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   57 |  while(ida+1<a.size() || idb+1<b.size()){
      |        ~~~~~^~~~~~~~~
kyoto.cpp:57:31: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   57 |  while(ida+1<a.size() || idb+1<b.size()){
      |                          ~~~~~^~~~~~~~~
kyoto.cpp:58:11: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   58 |   if(ida+1<a.size() && (idb+1==b.size() || cmp(get(A,a[ida],a[ida+1]),get(B,b[idb],b[idb+1])))){
      |      ~~~~~^~~~~~~~~
kyoto.cpp:58:30: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   58 |   if(ida+1<a.size() && (idb+1==b.size() || cmp(get(A,a[ida],a[ida+1]),get(B,b[idb],b[idb+1])))){
      |                         ~~~~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 324 KB Output is correct
7 Correct 1 ms 324 KB Output is correct
8 Correct 1 ms 212 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 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 0 ms 328 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 0 ms 212 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 1 ms 212 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 1 ms 324 KB Output is correct
4 Correct 8 ms 2260 KB Output is correct
5 Correct 6 ms 2236 KB Output is correct
6 Correct 5 ms 1260 KB Output is correct
7 Correct 16 ms 5216 KB Output is correct
8 Correct 17 ms 5184 KB Output is correct
9 Correct 15 ms 4292 KB Output is correct
10 Correct 16 ms 4520 KB Output is correct
11 Correct 17 ms 4948 KB Output is correct
12 Correct 16 ms 4160 KB Output is correct
13 Correct 16 ms 4328 KB Output is correct
14 Correct 19 ms 5360 KB Output is correct
15 Correct 18 ms 5304 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 324 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 1 ms 212 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 212 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 324 KB Output is correct
7 Correct 1 ms 324 KB Output is correct
8 Correct 1 ms 212 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 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 0 ms 328 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 0 ms 212 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 0 ms 212 KB Output is correct
31 Correct 1 ms 324 KB Output is correct
32 Correct 8 ms 2260 KB Output is correct
33 Correct 6 ms 2236 KB Output is correct
34 Correct 5 ms 1260 KB Output is correct
35 Correct 16 ms 5216 KB Output is correct
36 Correct 17 ms 5184 KB Output is correct
37 Correct 15 ms 4292 KB Output is correct
38 Correct 16 ms 4520 KB Output is correct
39 Correct 17 ms 4948 KB Output is correct
40 Correct 16 ms 4160 KB Output is correct
41 Correct 16 ms 4328 KB Output is correct
42 Correct 19 ms 5360 KB Output is correct
43 Correct 18 ms 5304 KB Output is correct
44 Correct 0 ms 212 KB Output is correct
45 Correct 1 ms 212 KB Output is correct
46 Correct 1 ms 212 KB Output is correct
47 Correct 0 ms 324 KB Output is correct
48 Correct 1 ms 212 KB Output is correct
49 Correct 0 ms 212 KB Output is correct
50 Correct 1 ms 212 KB Output is correct
51 Correct 1 ms 212 KB Output is correct
52 Correct 1 ms 212 KB Output is correct
53 Correct 1 ms 212 KB Output is correct
54 Correct 1 ms 212 KB Output is correct
55 Correct 13 ms 2092 KB Output is correct
56 Correct 1 ms 340 KB Output is correct
57 Correct 2 ms 468 KB Output is correct
58 Correct 4 ms 868 KB Output is correct
59 Correct 28 ms 4192 KB Output is correct
60 Correct 26 ms 4288 KB Output is correct
61 Correct 23 ms 4044 KB Output is correct
62 Correct 23 ms 3932 KB Output is correct
63 Correct 25 ms 5412 KB Output is correct
64 Correct 24 ms 4456 KB Output is correct
65 Correct 34 ms 4328 KB Output is correct
66 Correct 24 ms 3836 KB Output is correct
67 Correct 45 ms 5204 KB Output is correct