結果
| 問題 |
No.609 Noelちゃんと星々
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2017-12-09 00:10:28 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 25 ms / 2,000 ms |
| コード長 | 373 bytes |
| コンパイル時間 | 615 ms |
| コンパイル使用メモリ | 57,460 KB |
| 最終ジャッジ日時 | 2025-01-05 05:04:05 |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 25 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:9:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
9 | scanf("%d", &n);
| ~~~~~^~~~~~~~~~
main.cpp:12:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
12 | scanf("%d", &a[i]);
| ~~~~~^~~~~~~~~~~~~
ソースコード
#include <cstdio>
#include <vector>
#include <algorithm>
using int64 = long long;
int main() {
int n;
scanf("%d", &n);
std::vector<int> a(n);
for (int i = 0; i < n; ++i) {
scanf("%d", &a[i]);
}
std::sort(a.begin(), a.end());
int64 ret = 0;
for (int i = 0; i < n; ++i) {
ret += std::abs(a[i] - a[n / 2]);
}
printf("%lld\n", ret);
return 0;
}