結果
| 問題 |
No.3016 ハチマキおじさん
|
| コンテスト | |
| ユーザー |
applejam
|
| 提出日時 | 2025-01-25 13:46:50 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 149 ms / 2,000 ms |
| コード長 | 1,317 bytes |
| コンパイル時間 | 3,418 ms |
| コンパイル使用メモリ | 150,448 KB |
| 実行使用メモリ | 20,480 KB |
| 最終ジャッジ日時 | 2025-01-25 22:58:54 |
| 合計ジャッジ時間 | 7,014 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge9 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 31 |
ソースコード
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
using ll = long long;
using mint = modint998244353;
#define rep(i, n) for (int i = 0; i< (int)(n); i++)
int main(){
ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int n; cin >> n;
vector<pair<ll, int>> a(n);
vector<ll> b(n-1), e(n);
rep(i, n){
ll c; cin >> c;
a[i] = {c, i+1};
e[i] = c;
}
rep(i, n-1)cin >> b[i];
sort(a.begin(), a.end());
sort(b.begin(), b.end());
vector<pair<ll, int>> ans(n);
vector<ll> c(n-1), d(n-1);
rep(i, n-1){
c[i] = (i > 0) ? c[i-1] + abs(a[i].first - b[i]) : abs(a[i].first - b[i]);
d[i] = (i > 0) ? d[i-1] + abs(a[i+1].first - b[i]) : abs(a[i+1].first - b[i]);
}
ans[0] = {d[n-2], a[0].second};
ans[n-1] = {c[n-2], a[n-1].second};
for(int i=1; i<n - 1; i++){
ll cost = c[i-1] + d[n-2] - d[i-1];
ans[i] = {cost, a[i].second};
}
sort(ans.begin(), ans.end());
int t = 1; ll tmp = ans[0].first;
while(t < n && ans[t].first == tmp)t++;
set<int> res;
rep(i, t)res.insert(e[ans[i].second-1]);
cout << res.size() << endl;
for(auto p : res)cout << p << " ";
cout << endl;
return 0;
}
applejam