結果
問題 | No.1251 絶対に間違ってはいけない最小化問題 |
ユーザー | mikianaaa |
提出日時 | 2020-10-15 22:28:34 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 62 ms / 2,000 ms |
コード長 | 1,292 bytes |
コンパイル時間 | 1,922 ms |
コンパイル使用メモリ | 173,828 KB |
実行使用メモリ | 6,784 KB |
最終ジャッジ日時 | 2024-07-20 20:02:52 |
合計ジャッジ時間 | 16,032 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 3 ms
5,376 KB |
testcase_02 | AC | 3 ms
5,376 KB |
testcase_03 | AC | 3 ms
5,376 KB |
testcase_04 | AC | 3 ms
5,376 KB |
testcase_05 | AC | 3 ms
5,376 KB |
testcase_06 | AC | 3 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 | 2 ms
5,376 KB |
testcase_12 | AC | 2 ms
5,376 KB |
testcase_13 | AC | 2 ms
5,376 KB |
testcase_14 | AC | 3 ms
5,376 KB |
testcase_15 | AC | 3 ms
5,376 KB |
testcase_16 | AC | 2 ms
5,376 KB |
testcase_17 | AC | 2 ms
5,376 KB |
testcase_18 | AC | 58 ms
6,528 KB |
testcase_19 | AC | 57 ms
6,400 KB |
testcase_20 | AC | 39 ms
5,376 KB |
testcase_21 | AC | 7 ms
5,376 KB |
testcase_22 | AC | 36 ms
5,376 KB |
testcase_23 | AC | 6 ms
5,376 KB |
testcase_24 | AC | 46 ms
5,888 KB |
testcase_25 | AC | 34 ms
5,376 KB |
testcase_26 | AC | 14 ms
5,376 KB |
testcase_27 | AC | 5 ms
5,376 KB |
testcase_28 | AC | 60 ms
6,528 KB |
testcase_29 | AC | 61 ms
6,528 KB |
testcase_30 | AC | 61 ms
6,784 KB |
testcase_31 | AC | 61 ms
6,528 KB |
testcase_32 | AC | 61 ms
6,528 KB |
testcase_33 | AC | 61 ms
6,528 KB |
testcase_34 | AC | 61 ms
6,528 KB |
testcase_35 | AC | 61 ms
6,656 KB |
testcase_36 | AC | 61 ms
6,784 KB |
testcase_37 | AC | 62 ms
6,528 KB |
testcase_38 | AC | 60 ms
6,656 KB |
testcase_39 | AC | 61 ms
6,656 KB |
testcase_40 | AC | 61 ms
6,784 KB |
testcase_41 | AC | 61 ms
6,528 KB |
testcase_42 | AC | 61 ms
6,656 KB |
testcase_43 | AC | 3 ms
5,376 KB |
testcase_44 | AC | 2 ms
5,376 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 1000000000000000000typedef 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;}