結果
問題 | No.5020 Averaging |
ユーザー | komasandesu |
提出日時 | 2024-02-25 15:01:19 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 1,000 ms |
コード長 | 2,387 bytes |
コンパイル時間 | 3,090 ms |
コンパイル使用メモリ | 249,476 KB |
実行使用メモリ | 6,548 KB |
スコア | 13,109,481 |
最終ジャッジ日時 | 2024-02-25 15:01:27 |
合計ジャッジ時間 | 4,444 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge13 |
純コード判定しない問題か言語 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 50 |
コンパイルメッセージ
main.cpp: In function 'int main()': main.cpp:71:49: warning: 'B_max_itr' may be used uninitialized [-Wmaybe-uninitialized] 71 | long long A_avg_2 = (A[B_max_itr]+A[B_min_itr])/2; | ~~~~~~~~~~~^ main.cpp:21:21: note: 'B_max_itr' was declared here 21 | int B_max_itr; | ^~~~~~~~~ main.cpp:71:62: warning: 'B_min_itr' may be used uninitialized [-Wmaybe-uninitialized] 71 | long long A_avg_2 = (A[B_max_itr]+A[B_min_itr])/2; | ~~~~~~~~~~~^ main.cpp:26:21: note: 'B_min_itr' was declared here 26 | int B_min_itr; | ^~~~~~~~~ In file included from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/bits/stl_iterator.h:85, from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/bits/stl_algobase.h:67, from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/bits/specfun.h:45, from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/cmath:1935, from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/x86_64-pc-linux-gnu/bits/stdc++.h:41, from main.cpp:1: In function 'constexpr decltype (::new(void*(0)) _Tp) std::construct_at(_Tp*, _Args&& ...) [with _Tp = pair<int, int>; _Args = {pair<int, int>}]', inlined from 'static constexpr void std::allocator_traits<std::allocator<_CharT> >::construct(allocator_type&, _Up*, _Args&& ...) [with _Up = std::pair<int, int>; _Args = {std::pair<int, int>}; _Tp = std::pair<int, int>]' at /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/bits/alloc_traits.h:518:21, inlined from 'constexpr std::vector<_Tp, _Alloc>::reference std::vector<_Tp, _Alloc>::emplace_back(_Args&& ...) [with _Args = {std::pair<int, int>}; _Tp = std::pair<int, int>; _Alloc = std::allocator<std::p
ソースコード
#include <bits/stdc++.h> using namespace std; long long N; long long A[59]; long long B[59]; const long long avg = 500000000000000000; int main() { // Step 1. 入力 cin >> N; for (int i = 1; i <= N; i++) cin >> A[i] >> B[i]; // Step 2. 出力 vector<pair<int,int>> output; for (int i = 1; i <= 50; i++) { long long A_max=0; int A_max_itr; long long B_max=0; int B_max_itr; long long A_min=5000000000000000000; int A_min_itr; long long B_min=5000000000000000000; int B_min_itr; for (int j = 1; j <= N; j++){ if( A[j]>A_max ){ A_max_itr = j; A_max = A[j]; } if( B[j]>B_max ){ B_max_itr = j; B_max = A[j]; } if( A[j]<A_min ){ A_min_itr = j; A_min = A[j]; } if( B[j]<B_min ){ B_min_itr = j; B_min = A[j]; } } /* cout << "A_max_itr" << " " << A_max_itr << "," << A_max << endl; cout << "A_min_itr" << " " << A_min_itr << "," << A_min << endl; cout << "B_max_itr" << " " << B_max_itr << "," << B_max << endl; cout << "B_min_itr" << " " << B_min_itr << "," << B_min << endl; */ long long A_avg = (A_max+A_min)/2; long long B_avg = (B_max+B_min)/2; if( abs(A_avg-avg)>abs(B_avg-avg) ){ if(A_max_itr!=A_min_itr){ A[A_max_itr] = A_avg; A[A_min_itr] = A_avg; long long B_avg_2 = (B[A_max_itr]+B[A_min_itr])/2; B[A_max_itr] = B_avg_2; B[A_min_itr] = B_avg_2; //cout << A_max_itr << " " << A_min_itr << endl; output.push_back({A_max_itr,A_min_itr}); } } else{ if(B_max_itr!=B_min_itr){ B[B_max_itr] = B_avg; B[B_min_itr] = B_avg; long long A_avg_2 = (A[B_max_itr]+A[B_min_itr])/2; A[B_max_itr] = A_avg_2; A[B_min_itr] = A_avg_2; //cout << B_max_itr << " " << B_min_itr << endl; output.push_back({B_max_itr,B_min_itr}); } } } cout << output.size() << endl; for(auto x:output){ cout << x.first << " " << x.second << endl; } return 0; }