結果

問題 No.1251 絶対に間違ってはいけない最小化問題
ユーザー shiomusubi496shiomusubi496
提出日時 2020-10-09 22:06:33
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 601 bytes
コンパイル時間 1,616 ms
コンパイル使用メモリ 167,784 KB
実行使用メモリ 6,480 KB
最終ジャッジ日時 2023-09-27 17:17:26
合計ジャッジ時間 16,528 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,356 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 WA -
testcase_07 AC 1 ms
4,380 KB
testcase_08 WA -
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 WA -
testcase_12 AC 1 ms
4,380 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 2 ms
4,380 KB
testcase_16 WA -
testcase_17 AC 2 ms
4,380 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 109 ms
5,004 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 AC 194 ms
6,436 KB
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 WA -
testcase_44 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#define int long long
using namespace std;
signed main(){
  int N;
  cin>>N;
  vector<int> A(N),B(N);
  long double mn=1000000,mx=-1000000;
  for(int &i:A){
    cin>>i;
    mn=min(mn,(long double)i),mx=max(mx,(long double)i);
  }
  for(int &i:B)cin>>i;
  for(int I=0;I<200;I++){
    long double l=(mn*2+mx)/3.0,r=(mn+mx*2)/3.0,cnt1=0,cnt2=0;
    for(int i=0;i<N;i++){
      cnt1+=abs(A[i]-l)*B[i];
      cnt2+=abs(A[i]-r)*B[i];
    }
    if(cnt1<cnt2)mx=r;
    else mn=l;
  }
  long double ans=0;
  for(int i=0;i<N;i++)ans+=abs(A[i]-mn)*B[i];
  cout<<mn<<' '<<(int)ans<<endl;
}
0