結果
| 問題 |
No.837 Noelちゃんと星々2
|
| コンテスト | |
| ユーザー |
MarcusAureliusAntoninus
|
| 提出日時 | 2019-06-14 22:03:58 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 39 ms / 2,000 ms |
| コード長 | 773 bytes |
| コンパイル時間 | 1,904 ms |
| コンパイル使用メモリ | 199,188 KB |
| 最終ジャッジ日時 | 2025-01-07 04:31:47 |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 29 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:8:36: warning: format ‘%lld’ expects argument of type ‘long long int*’, but argument 2 has type ‘long int*’ [-Wformat=]
8 | for (auto& e: Y) scanf("%lld", &e);
| ~~~^ ~~
| | |
| | long int*
| long long int*
| %ld
main.cpp:29:20: warning: format ‘%lld’ expects argument of type ‘long long int’, but argument 2 has type ‘int64_t’ {aka ‘long int’} [-Wformat=]
29 | printf("%lld\n", min);
| ~~~^ ~~~
| | |
| | int64_t {aka long int}
| long long int
| %ld
main.cpp:6:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
6 | scanf("%d", &N);
| ~~~~~^~~~~~~~~~
main.cpp:8:31: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
8 | for (auto& e: Y) scanf("%lld", &e);
| ~~~~~^~~~~~~~~~~~
ソースコード
#include <bits/stdc++.h>
int main()
{
int N;
scanf("%d", &N);
std::vector<int64_t> Y(N);
for (auto& e: Y) scanf("%lld", &e);
std::sort(Y.begin(), Y.end());
if (Y.front() == Y.back())
{
puts("1");
return 0;
}
std::vector<int64_t> Y_sum(Y);
for (int i{1}; i < N; i++) Y_sum[i] += Y_sum[i - 1];
// right]
int64_t min{1ll << 60};
for (int right{}; right < N - 1; right++)
{
int64_t sum{};
int mid1{(right + 1) / 2}, mid2{(N - (right + 1)) / 2 + right + 1};
sum += (mid1 + 1) * Y[mid1] - Y_sum[mid1] + (Y_sum[right] - Y_sum[mid1]) - (right - mid1) * Y[mid1];
sum += (mid2 - right) * Y[mid2] - (Y_sum[mid2] - Y_sum[right]) + (Y_sum[N - 1] - Y_sum[mid2]) - (N - 1 - mid2) * Y[mid2];
min = std::min(min, sum);
}
printf("%lld\n", min);
return 0;
}
MarcusAureliusAntoninus