結果
問題 |
No.3016 ハチマキおじさん
|
ユーザー |
![]() |
提出日時 | 2025-01-28 16:09:51 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 105 ms / 2,000 ms |
コード長 | 1,259 bytes |
コンパイル時間 | 964 ms |
コンパイル使用メモリ | 62,036 KB |
実行使用メモリ | 9,244 KB |
最終ジャッジ日時 | 2025-01-28 16:09:58 |
合計ジャッジ時間 | 6,978 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 31 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:33:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 33 | scanf("%d", &n); | ~~~~~^~~~~~~~~~ main.cpp:34:36: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 34 | for (int i = 0; i < n; i++) scanf("%d", as + i); | ~~~~~^~~~~~~~~~~~~~ main.cpp:35:40: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 35 | for (int i = 0; i < n - 1; i++) scanf("%d", bs + i); | ~~~~~^~~~~~~~~~~~~~
ソースコード
/* -*- coding: utf-8 -*- * * 3016.cc: No.3016 繝上メ繝槭く縺翫§縺輔s - yukicoder */ #include<cstdio> #include<vector> #include<algorithm> using namespace std; /* constant */ const int MAX_N = 200000; const long long LINF = 1LL << 62; /* typedef */ using ll = long long; using vi = vector<int>; /* global variables */ int as[MAX_N], bs[MAX_N]; ll fds[MAX_N], bds[MAX_N]; /* subroutines */ /* main */ int main() { int n; scanf("%d", &n); for (int i = 0; i < n; i++) scanf("%d", as + i); for (int i = 0; i < n - 1; i++) scanf("%d", bs + i); sort(as, as + n); sort(bs, bs + n - 1); for (int i = 0; i < n - 1; i++) fds[i + 1] = fds[i] + abs(as[i] - bs[i]); bds[n - 1] = 0; for (int i = n - 2; i >= 0; i--) bds[i] = bds[i + 1] + abs(as[i + 1] - bs[i]); ll mins = LINF; vi ls; for (int i = 0; i < n; i++) { ll s = fds[i] + bds[i]; if (mins > s) mins = s, ls.assign(1, as[i]); else if (mins == s) ls.push_back(as[i]); } //printf(" mins=%lld\n", mins); sort(ls.begin(), ls.end()); ls.erase(unique(ls.begin(), ls.end()), ls.end()); int t = ls.size(); printf("%d\n", t); for (int i = 0; i < t; i++) printf("%d%c", ls[i], (i + 1 < t) ? ' ' : '\n'); return 0; }