結果

問題 No.1251 絶対に間違ってはいけない最小化問題
ユーザー chocopuuchocopuu
提出日時 2020-10-09 21:29:17
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 157 ms / 2,000 ms
コード長 1,291 bytes
コンパイル時間 2,074 ms
コンパイル使用メモリ 201,676 KB
実行使用メモリ 6,324 KB
最終ジャッジ日時 2023-09-27 14:43:29
合計ジャッジ時間 17,058 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 144 ms
6,004 KB
testcase_19 AC 141 ms
5,932 KB
testcase_20 AC 79 ms
4,656 KB
testcase_21 AC 13 ms
4,380 KB
testcase_22 AC 87 ms
4,936 KB
testcase_23 AC 10 ms
4,376 KB
testcase_24 AC 111 ms
5,424 KB
testcase_25 AC 81 ms
4,956 KB
testcase_26 AC 31 ms
4,376 KB
testcase_27 AC 11 ms
4,376 KB
testcase_28 AC 155 ms
6,324 KB
testcase_29 AC 154 ms
6,116 KB
testcase_30 AC 150 ms
6,216 KB
testcase_31 AC 150 ms
6,144 KB
testcase_32 AC 150 ms
6,156 KB
testcase_33 AC 153 ms
6,164 KB
testcase_34 AC 145 ms
6,160 KB
testcase_35 AC 153 ms
6,196 KB
testcase_36 AC 146 ms
6,116 KB
testcase_37 AC 154 ms
6,204 KB
testcase_38 AC 152 ms
6,292 KB
testcase_39 AC 147 ms
6,248 KB
testcase_40 AC 150 ms
6,164 KB
testcase_41 AC 157 ms
6,276 KB
testcase_42 AC 149 ms
6,320 KB
testcase_43 AC 1 ms
4,376 KB
testcase_44 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;
//#include "atcoder/all"
//using namespace atcoder;
#define int long long
#define REP(i, n) for (int i = 0; i < (int)n; ++i)
#define RREP(i, n) for (int i = (int)n - 1; i >= 0; --i)
#define FOR(i, s, n) for (int i = s; i < (int)n; ++i)
#define RFOR(i, s, n) for (int i = (int)n - 1; i >= s; --i)
#define ALL(a) a.begin(), a.end()
#define IN(a, x, b) (a <= x && x < b)
template<class T>istream&operator >>(istream&is,vector<T>&vec){for(T&x:vec)is>>x;return is;}
template<class T>inline void out(T t){cout << t << "\n";}
template<class T,class... Ts>inline void out(T t,Ts... ts){cout << t << " ";out(ts...);}
template<class T>inline bool CHMIN(T&a,T b){if(a > b){a = b;return true;}return false;}
template<class T>inline bool CHMAX(T&a,T b){if(a < b){a = b;return true;}return false;}
constexpr int INF = 1e18;

signed main(){
	int N;
	cin >> N;
	vector<int>a(N), b(N);
	cin >> a >> b;

	int l = -1e7, r = 1e7;
	auto f = [&](int x) {
		int ret = 0;
		REP(i, N) {
			ret += abs(x - a[i]) * b[i];
		}
		return ret;
	};
	REP(i, 60) {
		int m1 = (l + l + r) / 3;
		int m2 = (l + r + r) / 3;
		if(f(m1) < f(m2)) {
			r = m2;
		} else {
			l = m1;
		}
	}
	int ans = INF, idx = -1;
	FOR(i, l - 30, l + 30) if(CHMIN(ans, f(i))) idx = i;
	out(idx, ans);
}
0