답안 #555309

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
555309 2022-04-30T11:54:18 Z Koosha_mv Sightseeing in Kyoto (JOI22_kyoto) C++14
0 / 100
1 ms 212 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++;
		}
	}
	return res;
}
 
int32_t main(){
	ios:: sync_with_stdio(0), cin.tie(0), cout.tie(0);
	cin>>n>>m;
	vector<int> A,B;
	f(i,1,n+1){
		int x;
		cin>>x;
		A.pb(x);
	}
	f(i,1,m+1){
		int x;
		cin>>x;
		B.pb(x);
	}
	cout<<solve(A,B);
}

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 Incorrect 0 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 1 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 0 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -