結果

問題 No.609 Noelちゃんと星々
ユーザー Naoyk1212Naoyk1212
提出日時 2017-12-12 19:58:19
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 783 bytes
コンパイル時間 479 ms
コンパイル使用メモリ 63,768 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-20 23:28:21
合計ジャッジ時間 2,962 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 23 ms
4,376 KB
testcase_02 AC 16 ms
4,376 KB
testcase_03 WA -
testcase_04 AC 12 ms
4,380 KB
testcase_05 AC 53 ms
4,380 KB
testcase_06 AC 45 ms
4,380 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 34 ms
4,380 KB
testcase_11 AC 32 ms
4,376 KB
testcase_12 WA -
testcase_13 AC 9 ms
4,380 KB
testcase_14 WA -
testcase_15 AC 47 ms
4,380 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 45 ms
4,384 KB
testcase_20 AC 56 ms
4,380 KB
testcase_21 AC 56 ms
4,376 KB
testcase_22 AC 55 ms
4,380 KB
testcase_23 AC 56 ms
4,376 KB
testcase_24 AC 56 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<algorithm>
#include<vector>

int main(){
    int N;
    std::cin >> N;
    std::vector<int> v(N);
    for(int i = 0; i < N; i++){
        std::cin >> v[i];
    }

    long long high = 1e9;
    long long low = -1e9;
    for(int i = 0; i < 100; i++){
        long long midu = (2 * high + low) / 3;
		long long midl = (high + 2 * low) / 3;

        long long cntu = 0;
		long long cntl = 0;
        for(int j = 0; j < N; j++){
            cntu += std::abs(v[j] - midu);
			cntl += std::abs(v[j] - midl);
        }
		
		if(cntl <= cntu)high = midu;
		else low = midl;
		std::cerr << low << " " << high << std::endl;
    }

    long long ans = 0;
    for(int i = 0; i < N; i++){
       ans += std::abs(v[i] - high); 
    }
    std::cout << ans << std::endl;
}
0