結果
| 問題 |
No.3016 ハチマキおじさん
|
| ユーザー |
|
| 提出日時 | 2025-01-25 13:24:41 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,281 bytes |
| コンパイル時間 | 1,843 ms |
| コンパイル使用メモリ | 199,368 KB |
| 実行使用メモリ | 10,908 KB |
| 最終ジャッジ日時 | 2025-01-25 22:45:42 |
| 合計ジャッジ時間 | 4,197 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 9 WA * 22 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int N; cin >> N;
vector<int> apA(N),apB(N);
for(int t=0; t<N; t++){
int a; cin >> a; a--;
apA.at(a)++;
}
for(int t=0; t<N-1; t++){
int a; cin >> a; a--;
apB.at(a)++;
}
vector<int> A,B;
for(int i=0; i<N; i++){
int del = min(apA.at(i),apB.at(i));
apA.at(i) -= del; apB.at(i) -= del;
while(apA.at(i)--) A.push_back(i);
while(apB.at(i)--) B.push_back(i);
}
int n = B.size();
vector<long long> L(n),R(n);
long long sum = 0;
for(int i=0; i<n; i++){
sum += abs(B.at(i)-A.at(i));
L.at(i) = sum;
}
sum = 0;
for(int i=n-1; i>=0; i--){
sum += abs(B.at(i)-A.at(i+1));
R.at(i) = sum;
}
long long best = 1e18;
vector<int> answer;
for(int i=0; i<=n; i++){
long long l = 0,r = 0;
if(i) l = L.at(i-1);
if(i != n) r = R.at(i);
if(l+r < best) best = l+r,answer = {A.at(i)};
else if(l+r == best) answer.push_back(A.at(i));
}
cout << answer.size() << endl;
for(int i=0; i<answer.size(); i++) cout << answer.at(i)+1 << (i==answer.size()-1?"\n":" ");
}