답안 #555257

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
555257 2022-04-30T10:39:42 Z Koosha_mv Sightseeing in Kyoto (JOI22_kyoto) C++14
10 / 100
5 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=2e9;
 
int n,m,ans,a[N],b[N],dp[N][N];
 
bool cmp(pair<int,int> a,pair<int,int> b){
	return a.F*b.S<b.F*a.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]);
	while(ida+1<n || idb+1<m){
		pair<int,int> mn={inf,1};
		int b=0;
		f(i,ida+1,n) if(cmp({A[i]-A[ida],i-ida},mn)) mn={A[i]-A[ida],i-ida};
		f(i,idb+1,m) if(cmp({B[i]-B[idb],i-idb},mn)) b=1;
		if(b==0){
			ida++;
			res+=B[idb];
		}
		else{
			idb++;
			res+=A[ida];
		}
	}
	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;
}
# 결과 실행 시간 메모리 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 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 3 ms 340 KB Output is correct
10 Correct 3 ms 344 KB Output is correct
11 Correct 4 ms 340 KB Output is correct
12 Correct 2 ms 340 KB Output is correct
13 Correct 3 ms 340 KB Output is correct
14 Correct 3 ms 340 KB Output is correct
15 Correct 2 ms 340 KB Output is correct
16 Correct 2 ms 340 KB Output is correct
17 Correct 5 ms 340 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 0 ms 212 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 0 ms 212 KB Output is correct
26 Correct 0 ms 212 KB Output is correct
27 Correct 0 ms 212 KB Output is correct
28 Correct 0 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 Runtime error 1 ms 468 KB Execution killed with signal 6
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 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 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 3 ms 340 KB Output is correct
10 Correct 3 ms 344 KB Output is correct
11 Correct 4 ms 340 KB Output is correct
12 Correct 2 ms 340 KB Output is correct
13 Correct 3 ms 340 KB Output is correct
14 Correct 3 ms 340 KB Output is correct
15 Correct 2 ms 340 KB Output is correct
16 Correct 2 ms 340 KB Output is correct
17 Correct 5 ms 340 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 0 ms 212 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 0 ms 212 KB Output is correct
26 Correct 0 ms 212 KB Output is correct
27 Correct 0 ms 212 KB Output is correct
28 Correct 0 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 Runtime error 1 ms 468 KB Execution killed with signal 6
32 Halted 0 ms 0 KB -