結果
問題 | No.1251 絶対に間違ってはいけない最小化問題 |
ユーザー | msm1993 |
提出日時 | 2020-10-23 15:28:19 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 60 ms / 2,000 ms |
コード長 | 1,292 bytes |
コンパイル時間 | 1,825 ms |
コンパイル使用メモリ | 175,704 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-07-21 10:06:16 |
合計ジャッジ時間 | 15,989 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,812 KB |
testcase_01 | AC | 2 ms
6,944 KB |
testcase_02 | AC | 2 ms
6,944 KB |
testcase_03 | AC | 2 ms
6,940 KB |
testcase_04 | AC | 2 ms
6,944 KB |
testcase_05 | AC | 2 ms
6,940 KB |
testcase_06 | AC | 2 ms
6,940 KB |
testcase_07 | AC | 2 ms
6,940 KB |
testcase_08 | AC | 2 ms
6,940 KB |
testcase_09 | AC | 2 ms
6,940 KB |
testcase_10 | AC | 2 ms
6,940 KB |
testcase_11 | AC | 2 ms
6,944 KB |
testcase_12 | AC | 2 ms
6,940 KB |
testcase_13 | AC | 2 ms
6,940 KB |
testcase_14 | AC | 2 ms
6,940 KB |
testcase_15 | AC | 2 ms
6,940 KB |
testcase_16 | AC | 2 ms
6,944 KB |
testcase_17 | AC | 2 ms
6,944 KB |
testcase_18 | AC | 56 ms
6,940 KB |
testcase_19 | AC | 57 ms
6,944 KB |
testcase_20 | AC | 32 ms
6,944 KB |
testcase_21 | AC | 6 ms
6,940 KB |
testcase_22 | AC | 36 ms
6,944 KB |
testcase_23 | AC | 5 ms
6,940 KB |
testcase_24 | AC | 46 ms
6,940 KB |
testcase_25 | AC | 34 ms
6,940 KB |
testcase_26 | AC | 13 ms
6,944 KB |
testcase_27 | AC | 5 ms
6,940 KB |
testcase_28 | AC | 60 ms
6,940 KB |
testcase_29 | AC | 60 ms
6,940 KB |
testcase_30 | AC | 59 ms
6,940 KB |
testcase_31 | AC | 59 ms
6,940 KB |
testcase_32 | AC | 59 ms
6,944 KB |
testcase_33 | AC | 60 ms
6,944 KB |
testcase_34 | AC | 60 ms
6,940 KB |
testcase_35 | AC | 59 ms
6,940 KB |
testcase_36 | AC | 59 ms
6,940 KB |
testcase_37 | AC | 60 ms
6,944 KB |
testcase_38 | AC | 59 ms
6,944 KB |
testcase_39 | AC | 59 ms
6,940 KB |
testcase_40 | AC | 60 ms
6,940 KB |
testcase_41 | AC | 59 ms
6,940 KB |
testcase_42 | AC | 60 ms
6,944 KB |
testcase_43 | AC | 2 ms
6,940 KB |
testcase_44 | AC | 2 ms
6,944 KB |
コンパイルメッセージ
In file included from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/istream:39, from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/sstream:38, from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/complex:45, from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/ccomplex:39, from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/x86_64-pc-linux-gnu/bits/stdc++.h:54, from main.cpp:2: In member function 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(long double) [with _CharT = char; _Traits = std::char_traits<char>]', inlined from 'int main()' at main.cpp:59:41: /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/ostream:233:25: warning: 'med' may be used uninitialized [-Wmaybe-uninitialized] 233 | { return _M_insert(__f); } | ~~~~~~~~~^~~~~ main.cpp: In function 'int main()': main.cpp:30:8: note: 'med' was declared here 30 | ld med; | ^~~
ソースコード
#include <algorithm> #include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define all(x) (x).begin(), (x).end() #define ll long long #define ld long double #define INF 1000000000000000000 typedef pair<ll, ll> pll; typedef pair<int, int> pint; vector<pll> A; int main() { cin.tie(0); ios::sync_with_stdio(false); int N; cin >> N; A.resize(N); ll sum = 0, ssum; rep(i, N) { cin >> A[i].first; } rep(i, N) { cin >> A[i].second; sum += A[i].second; } ssum = sum; ld med; sort(all(A)); if (sum % 2 == 0) { ll bd = sum / 2; rep(i, N) { ssum -= A[i].second; if (ssum == bd) { med = (A[i + 1].first + A[i].first) / 2; break; } if (ssum < bd) { med = A[i].first; break; } } } else { ll bd = sum / 2; rep(i, N) { ssum -= A[i].second; if (ssum <= bd) { med = A[i].first; break; } } } ld ans = 0; rep(i, N) { ans += A[i].second * abs(A[i].first - med); } cout << fixed << setprecision(5) << med << " " << (ll)ans << endl; }