結果
| 問題 |
No.1251 絶対に間違ってはいけない最小化問題
|
| コンテスト | |
| ユーザー |
chacoder1
|
| 提出日時 | 2021-01-10 13:17:29 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 611 bytes |
| コンパイル時間 | 2,273 ms |
| コンパイル使用メモリ | 192,260 KB |
| 最終ジャッジ日時 | 2025-01-17 15:56:01 |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | WA * 3 |
| other | WA * 42 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
int n,cnt;
double l,r,m1,m2;
int A[200000],B[200000];
int f(int x){
double sum=0;
for(int i=0;i<n;i++){
sum+=((double)B[i]*abs((double)A[i]-x));
}
return sum;
}
int main(){
cin>>n;
for(int i=0;i<n;i++){
cin>>A[i];
}
for(int i=0;i<n;i++){
cin>>B[i];
}
cnt=0;
l=-1000000;
r=1000000;
while(cnt<50){
m1=l+(r-l)/3;
m2=l+((r-l)/3)*2;
//cout<<l<<" "<<r<<" "<<m1<<" "<<m2<<endl;
if(f(m1)>f(m2)){
l=m1;
}
else{
r=m2;
}
cnt++;
}
cout<<min(l,r)<<" "<<f(l)<<endl;
return 0;
}
chacoder1