結果

問題 No.609 Noelちゃんと星々
ユーザー tnakao0123
提出日時 2017-12-10 00:45:53
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 29 ms / 2,000 ms
コード長 1,235 bytes
コンパイル時間 755 ms
コンパイル使用メモリ 86,992 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-11-30 06:00:41
合計ジャッジ時間 2,376 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 25
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:53:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   53 |   scanf("%d", &n);
      |   ~~~~~^~~~~~~~~~
main.cpp:55:36: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   55 |   for (int i = 0; i < n; i++) scanf("%d", &ys[i]);
      |                               ~~~~~^~~~~~~~~~~~~~

ソースコード

diff #
プレゼンテーションモードにする

/* -*- coding: utf-8 -*-
*
* 609.cc: No.609 Noel - yukicoder
*/
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
using namespace std;
/* constant */
const int MAX_N = 100000;
const int INF = 1 << 30;
/* typedef */
typedef long long ll;
typedef long double ld;
/* global variables */
int ys[MAX_N];
/* subroutines */
ll dsum(int n, int ty) {
ll sum = 0.0;
for (int i = 0; i < n; i++) sum += abs(ty - ys[i]);
return sum;
}
/* main */
int main() {
int n;
scanf("%d", &n);
for (int i = 0; i < n; i++) scanf("%d", &ys[i]);
sort(ys, ys + n);
int l = 0, r = n - 1;
while (l + 2 < r) {
int k0 = (l * 2 + r) / 3;
int k1 = (l + r * 2) / 3;
ll d0 = dsum(n, ys[k0]);
ll d1 = dsum(n, ys[k1]);
if (d0 >= d1) l = k0;
else r = k1;
}
ll minsum = dsum(n, ys[l]);
for (ll k = l + 1; k <= r; k++) {
ll sum = dsum(n, ys[k]);
if (minsum > sum) minsum = sum;
}
printf("%lld\n", minsum);
return 0;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0