結果
問題 | No.1251 絶対に間違ってはいけない最小化問題 |
ユーザー | mikianaaa |
提出日時 | 2020-10-15 22:28:34 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.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 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 42 |
コンパイルメッセージ
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; }