結果

問題 No.5020 Averaging
ユーザー komasandesukomasandesu
提出日時 2024-02-25 15:01:19
言語 C++23
(gcc 12.3.0 + boost 1.83.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
純コード判定しない問題か言語
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,548 KB
testcase_01 AC 2 ms
6,548 KB
testcase_02 AC 2 ms
6,548 KB
testcase_03 AC 1 ms
6,548 KB
testcase_04 AC 2 ms
6,548 KB
testcase_05 AC 2 ms
6,548 KB
testcase_06 AC 2 ms
6,548 KB
testcase_07 AC 1 ms
6,548 KB
testcase_08 AC 2 ms
6,548 KB
testcase_09 AC 2 ms
6,548 KB
testcase_10 AC 2 ms
6,548 KB
testcase_11 AC 1 ms
6,548 KB
testcase_12 AC 2 ms
6,548 KB
testcase_13 AC 2 ms
6,548 KB
testcase_14 AC 2 ms
6,548 KB
testcase_15 AC 2 ms
6,548 KB
testcase_16 AC 2 ms
6,548 KB
testcase_17 AC 2 ms
6,548 KB
testcase_18 AC 1 ms
6,548 KB
testcase_19 AC 2 ms
6,548 KB
testcase_20 AC 2 ms
6,548 KB
testcase_21 AC 2 ms
6,548 KB
testcase_22 AC 2 ms
6,548 KB
testcase_23 AC 2 ms
6,548 KB
testcase_24 AC 2 ms
6,548 KB
testcase_25 AC 1 ms
6,548 KB
testcase_26 AC 2 ms
6,548 KB
testcase_27 AC 2 ms
6,548 KB
testcase_28 AC 2 ms
6,548 KB
testcase_29 AC 2 ms
6,548 KB
testcase_30 AC 2 ms
6,548 KB
testcase_31 AC 1 ms
6,548 KB
testcase_32 AC 2 ms
6,548 KB
testcase_33 AC 2 ms
6,548 KB
testcase_34 AC 2 ms
6,548 KB
testcase_35 AC 2 ms
6,548 KB
testcase_36 AC 2 ms
6,548 KB
testcase_37 AC 2 ms
6,548 KB
testcase_38 AC 2 ms
6,548 KB
testcase_39 AC 1 ms
6,548 KB
testcase_40 AC 1 ms
6,548 KB
testcase_41 AC 2 ms
6,548 KB
testcase_42 AC 2 ms
6,548 KB
testcase_43 AC 2 ms
6,548 KB
testcase_44 AC 2 ms
6,548 KB
testcase_45 AC 2 ms
6,548 KB
testcase_46 AC 2 ms
6,548 KB
testcase_47 AC 2 ms
6,548 KB
testcase_48 AC 2 ms
6,548 KB
testcase_49 AC 1 ms
6,548 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
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

ソースコード

diff #

#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;
}
0