結果
問題 |
No.1251 絶対に間違ってはいけない最小化問題
|
ユーザー |
![]() |
提出日時 | 2020-10-09 22:31:16 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 850 bytes |
コンパイル時間 | 1,488 ms |
コンパイル使用メモリ | 170,632 KB |
実行使用メモリ | 17,664 KB |
最終ジャッジ日時 | 2024-07-20 12:51:07 |
合計ジャッジ時間 | 7,126 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 WA * 1 |
other | AC * 4 WA * 11 TLE * 1 -- * 26 |
ソースコード
#include <bits/stdc++.h> using namespace std; #define int long long typedef pair<int,int> P; int INF = 1e9+7; int mod = 1e9+7; int dx[4] = {1, 0, -1, 0}; int dy[4] = {0, 1, 0, -1}; int N; double f(double x,vector<double>a,vector<double>b) { double res = 0; for(int i = 0; i < N; i++) { res += abs(x-a[i])*b[i]; } return res; } signed main() { cin >> N; vector<double>A(N),B(N); for(int i = 0; i < N; i++) { cin >> A[i]; } for(int i = 0; i < N; i++) { cin >> B[i]; } double low = -INF,high = INF; int time = 1000; while (time--) { double c1 = (low*2+high)/3; double c2 = (low+high*2)/3; if(f(c1,A,B) > f(c2,A,B)) { low = c1; } else { high = c2; } } cout << high << " " << f(high,A,B) << endl; }