結果
問題 | No.545 ママの大事な二人の子供 |
ユーザー | azyobuzin |
提出日時 | 2017-07-16 21:15:27 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,172 bytes |
コンパイル時間 | 1,042 ms |
コンパイル使用メモリ | 115,436 KB |
実行使用メモリ | 327,716 KB |
最終ジャッジ日時 | 2024-10-08 04:31:08 |
合計ジャッジ時間 | 4,964 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
10,496 KB |
testcase_01 | AC | 2 ms
5,248 KB |
testcase_02 | AC | 2 ms
5,248 KB |
testcase_03 | AC | 2 ms
5,248 KB |
testcase_04 | AC | 2 ms
5,248 KB |
testcase_05 | AC | 2 ms
5,248 KB |
testcase_06 | AC | 2 ms
5,248 KB |
testcase_07 | AC | 2 ms
5,248 KB |
testcase_08 | AC | 2 ms
5,248 KB |
testcase_09 | AC | 2 ms
5,248 KB |
testcase_10 | AC | 2 ms
5,248 KB |
testcase_11 | AC | 2 ms
5,248 KB |
testcase_12 | AC | 3 ms
5,248 KB |
testcase_13 | WA | - |
testcase_14 | AC | 8 ms
5,248 KB |
testcase_15 | AC | 2 ms
5,248 KB |
testcase_16 | AC | 14 ms
6,656 KB |
testcase_17 | AC | 98 ms
23,424 KB |
testcase_18 | TLE | - |
testcase_19 | -- | - |
testcase_20 | -- | - |
testcase_21 | -- | - |
testcase_22 | -- | - |
testcase_23 | -- | - |
testcase_24 | -- | - |
testcase_25 | -- | - |
testcase_26 | -- | - |
testcase_27 | -- | - |
testcase_28 | -- | - |
testcase_29 | -- | - |
testcase_30 | -- | - |
testcase_31 | -- | - |
コンパイルメッセージ
In file included from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/iostream:39, from main.cpp:3: In member function 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(long int) [with _CharT = char; _Traits = std::char_traits<char>]', inlined from 'int main()' at main.cpp:65:15: /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/ostream:167:25: warning: 'min_diff' may be used uninitialized [-Wmaybe-uninitialized] 167 | { return _M_insert(__n); } | ~~~~~~~~~^~~~~ main.cpp: In function 'int main()': main.cpp:37:17: note: 'min_diff' was declared here 37 | int64_t min_diff; | ^~~~~~~~
ソースコード
#include <algorithm> #include <cmath> #include <iostream> #include <unordered_map> #include <vector> struct Item { int64_t a; int64_t b; }; struct Sums { int64_t sum_a; int64_t sum_b; }; int64_t get_diff(Sums& s) { return std::abs(s.sum_a - s.sum_b); } int main() { int n; std::cin >> n; std::vector<Item> items; items.reserve(n); for (int i = 0; i < n; i++) { int64_t a, b; std::cin >> a >> b; items.push_back({ a,b }); } std::unordered_map<int64_t, Sums> dp; dp.insert({ 0,{0,0} }); int64_t min_diff; for (int i = 0; i < n; i++) { min_diff = INT64_MAX; std::unordered_map<int64_t, Sums> new_map; new_map.reserve(dp.size() * 2); for (std::pair<const int64_t, Sums>& si : dp) { { Sums s = si.second; s.sum_a += items[i].a; int64_t diff = get_diff(s); new_map[diff] = s; min_diff = std::min(min_diff, diff); } { Sums s = si.second; s.sum_b += items[i].b; int64_t diff = get_diff(s); new_map[diff] = s; min_diff = std::min(min_diff, diff); } } dp = std::move(new_map); } std::cout << min_diff << std::endl; }