結果

問題 No.1251 絶対に間違ってはいけない最小化問題
ユーザー 👑 kmjpkmjp
提出日時 2020-10-09 23:04:47
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 73 ms / 2,000 ms
コード長 1,332 bytes
コンパイル時間 3,856 ms
コンパイル使用メモリ 204,380 KB
実行使用メモリ 7,132 KB
最終ジャッジ日時 2023-09-27 19:25:43
合計ジャッジ時間 16,890 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,364 KB
testcase_01 AC 2 ms
5,364 KB
testcase_02 AC 2 ms
5,364 KB
testcase_03 AC 2 ms
5,368 KB
testcase_04 AC 2 ms
5,568 KB
testcase_05 AC 2 ms
5,340 KB
testcase_06 AC 2 ms
5,436 KB
testcase_07 AC 2 ms
5,408 KB
testcase_08 AC 2 ms
5,380 KB
testcase_09 AC 2 ms
5,360 KB
testcase_10 AC 2 ms
5,380 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 2 ms
5,420 KB
testcase_13 AC 2 ms
5,348 KB
testcase_14 AC 2 ms
5,484 KB
testcase_15 AC 2 ms
5,484 KB
testcase_16 AC 2 ms
5,412 KB
testcase_17 AC 2 ms
5,360 KB
testcase_18 AC 63 ms
6,944 KB
testcase_19 AC 62 ms
7,096 KB
testcase_20 AC 36 ms
6,212 KB
testcase_21 AC 6 ms
5,724 KB
testcase_22 AC 38 ms
6,172 KB
testcase_23 AC 5 ms
5,616 KB
testcase_24 AC 49 ms
6,392 KB
testcase_25 AC 37 ms
6,172 KB
testcase_26 AC 15 ms
5,776 KB
testcase_27 AC 5 ms
5,616 KB
testcase_28 AC 73 ms
7,012 KB
testcase_29 AC 67 ms
7,128 KB
testcase_30 AC 68 ms
7,012 KB
testcase_31 AC 67 ms
6,932 KB
testcase_32 AC 67 ms
6,948 KB
testcase_33 AC 67 ms
6,968 KB
testcase_34 AC 68 ms
7,060 KB
testcase_35 AC 66 ms
7,132 KB
testcase_36 AC 67 ms
6,928 KB
testcase_37 AC 68 ms
7,124 KB
testcase_38 AC 67 ms
6,924 KB
testcase_39 AC 67 ms
6,936 KB
testcase_40 AC 68 ms
6,924 KB
testcase_41 AC 65 ms
7,132 KB
testcase_42 AC 67 ms
6,952 KB
testcase_43 AC 2 ms
5,428 KB
testcase_44 AC 2 ms
5,476 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define FORR2(x,y,arr) for(auto& [x,y]:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N;
ll A[202020],B[202020],C[202020];

ll hoge(ll v) {
	ll ret=0;
	int i;
	FOR(i,N) ret+=B[i]*abs(v-A[i]);
	return ret;
}

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N;
	vector<int> V;
	FOR(i,N) cin>>A[i], V.push_back(A[i]);
	FOR(i,N) cin>>B[i];
	sort(ALL(V));
	V.erase(unique(ALL(V)),V.end());
	int L=0,R=V.size()-1;
	while(R-L>=3) {
		int m1=(L*2+R)/3;
		int m2=(R*2+L)/3;
		ll v1=hoge(V[m1]);
		ll v2=hoge(V[m2]);
		if(v1<=v2) R=m2;
		if(v2<=v1) L=m1;
	}
	
	int mi=V[L];
	ll ret=1LL<<61;
	for(i=L;i<=R;i++) {
		ll v=hoge(V[i]);
		if(v<ret) {
			mi=V[i];
			ret=v;
		}
	}
	cout<<mi<<" "<<ret<<endl;
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}
0