結果
| 問題 | No.3363 Two Closest Numbers |
| コンテスト | |
| ユーザー |
a01sa01to
|
| 提出日時 | 2025-12-06 01:14:55 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 852 bytes |
| 記録 | |
| コンパイル時間 | 3,177 ms |
| コンパイル使用メモリ | 281,416 KB |
| 実行使用メモリ | 7,852 KB |
| 最終ジャッジ日時 | 2025-12-06 01:15:02 |
| 合計ジャッジ時間 | 7,251 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 29 WA * 30 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
using ll = long long;
using ull = unsigned long long;
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
int n;
cin >> n;
vector<int> a(n);
rep(i, n) cin >> a[i];
vector<int> cnt(10, 0);
rep(i, n) cnt[a[i]]++;
vector<int> rem, us;
rep(i, 10) {
if (cnt[i] % 2 == 1) rem.push_back(i);
if (cnt[i] >= 2) us.push_back(i);
}
int ans = 1e9;
int minim = us.empty() ? 0 : *min_element(us.begin(), us.end());
do {
int x = 0, y = 0;
if (rem.size() % 2 == 1) y = minim;
rep(i, rem.size()) {
if (i < rem.size() / 2)
x = x * 10 + rem[i];
else
y = y * 10 + rem[i];
}
ans = min(ans, abs(x - y));
} while (next_permutation(rem.begin(), rem.end()));
cout << ans << '\n';
return 0;
}
a01sa01to