結果

問題 No.180 美しいWhitespace (2)
ユーザー srjywrdnprktsrjywrdnprkt
提出日時 2022-12-25 21:34:05
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 3 ms / 5,000 ms
コード長 898 bytes
コンパイル時間 1,315 ms
コンパイル使用メモリ 107,912 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-30 01:50:27
合計ジャッジ時間 2,528 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 3 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 3 ms
5,376 KB
testcase_12 AC 3 ms
5,376 KB
testcase_13 AC 3 ms
5,376 KB
testcase_14 AC 3 ms
5,376 KB
testcase_15 AC 3 ms
5,376 KB
testcase_16 AC 3 ms
5,376 KB
testcase_17 AC 3 ms
5,376 KB
testcase_18 AC 3 ms
5,376 KB
testcase_19 AC 3 ms
5,376 KB
testcase_20 AC 2 ms
5,376 KB
testcase_21 AC 2 ms
5,376 KB
testcase_22 AC 2 ms
5,376 KB
testcase_23 AC 2 ms
5,376 KB
testcase_24 AC 2 ms
5,376 KB
testcase_25 AC 2 ms
5,376 KB
testcase_26 AC 2 ms
5,376 KB
testcase_27 AC 2 ms
5,376 KB
testcase_28 AC 2 ms
5,376 KB
testcase_29 AC 2 ms
5,376 KB
testcase_30 AC 3 ms
5,376 KB
testcase_31 AC 3 ms
5,376 KB
testcase_32 AC 3 ms
5,376 KB
testcase_33 AC 3 ms
5,376 KB
testcase_34 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
In file included from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/iostream:39,
                 from main.cpp:1:
In member function 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(long long int) [with _CharT = char; _Traits = std::char_traits<char>]',
    inlined from 'int main()' at main.cpp:49:13:
/home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/ostream:202:25: warning: 'ans' may be used uninitialized [-Wmaybe-uninitialized]
  202 |       { return _M_insert(__n); }
      |                ~~~~~~~~~^~~~~
main.cpp: In function 'int main()':
main.cpp:41:24: note: 'ans' was declared here
   41 |     long long mi=2e18, ans;
      |                        ^~~

ソースコード

diff #

#include <iostream>
#include <vector>
#include <cmath>
#include <map>
#include <set>
#include <iomanip>
#include <queue>
#include <algorithm>
#include <numeric>
#include <deque>
#include <sstream>

using namespace std;

long long N;
vector<long long> a, b;

long double f(long long X){
    long long mx=0, mi=2e18;
    for (int i=0; i<N; i++){
        mx = max(mx, a[i]+X*b[i]);
        mi = min(mi, a[i]+X*b[i]);
    }

    return mx-mi;
}

int main(){

    cin >> N;
    a.resize(N); b.resize(N);
    for (int i=0; i<N; i++) cin >> a[i] >> b[i];

    long long l=1, r=1e9, cl, cr;
    while (r-l > 2){
        cl = (l*2+r)/3; cr = (l+r*2)/3;
        if (f(cl) > f(cr)) l = cl;
        else r = cr;
    }

    long long mi=2e18, ans;
    for (long long i=l; i<=r; i++){
        if (mi > f(i)){
            ans = i;
            mi = f(i);
        }
    }

    cout << ans << endl;

    return 0;
}
0