Submission #555249

# Submission time Handle Problem Language Result Execution time Memory
555249 2022-04-30T10:23:21 Z Koosha_mv Sightseeing in Kyoto (JOI22_kyoto) C++14
0 / 100
1 ms 468 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
 
const int N=1005,inf=1e17;
 
int n,m,ans,a[N],b[N],dp[N][N];
 
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]);
	while(ida+1<n && idb+1<m){
		if(A[ida+1]-A[ida]<B[idb+1]-B[idb]){
			ida++;
			res+=B[idb];
		}
		else{
			idb++;
			res+=A[ida];
		}
	}
	while(ida+1<n) ida++,res+=B.back();
	while(idb+1<m) idb++,res+=A.back();
	return res;
}
 
int32_t main(){
	ios:: sync_with_stdio(0), cin.tie(0), cout.tie(0);
	cin>>n>>m;
	if(n>1000 || m>1000) assert(0);
	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;
}
# Verdict Execution time Memory 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 Incorrect 1 ms 340 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Runtime error 1 ms 468 KB Execution killed with signal 6
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory 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 Incorrect 1 ms 340 KB Output isn't correct
5 Halted 0 ms 0 KB -