結果
問題 | No.609 Noelちゃんと星々 |
ユーザー | kichirb3 |
提出日時 | 2018-03-24 10:53:06 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 985 bytes |
コンパイル時間 | 686 ms |
コンパイル使用メモリ | 79,164 KB |
実行使用メモリ | 4,504 KB |
最終ジャッジ日時 | 2023-09-07 08:23:05 |
合計ジャッジ時間 | 2,529 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge12 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 17 ms
4,376 KB |
testcase_01 | WA | - |
testcase_02 | WA | - |
testcase_03 | AC | 9 ms
4,376 KB |
testcase_04 | WA | - |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | AC | 11 ms
4,376 KB |
testcase_08 | AC | 4 ms
4,380 KB |
testcase_09 | AC | 8 ms
4,376 KB |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | AC | 15 ms
4,376 KB |
testcase_13 | WA | - |
testcase_14 | AC | 2 ms
4,376 KB |
testcase_15 | WA | - |
testcase_16 | AC | 21 ms
4,380 KB |
testcase_17 | AC | 17 ms
4,376 KB |
testcase_18 | AC | 7 ms
4,376 KB |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | WA | - |
testcase_23 | WA | - |
testcase_24 | WA | - |
ソースコード
// No.609 Noelちゃんと星々 // https://yukicoder.me/problems/no/609 // #include <iostream> #include <vector> #include <cmath> #include <algorithm> using namespace std; long long int solve(vector<int> &stars, int N); long long calc_score(int n, vector<int>& stars); int main() { std::cin.tie(nullptr); std::ios::sync_with_stdio(false); unsigned int N; cin >> N; vector<int> stars(N); for (int i = 0; i < N; ++i) cin >> stars[i]; long long ans = solve(stars, N); cout << ans << endl; } long long int solve(vector<int> &stars, int N) { sort(stars.begin(), stars.end()); int median; if (N % 2 == 1) median = stars[N/2]; else median = (stars[N/2] + stars[N/2 + 1]) / 2; long long ans = calc_score(median, stars); return ans; } long long calc_score(int n, vector<int>& stars) { long long ans = 0; for (auto s: stars) { ans += abs(s - n); } return ans; }