結果
| 問題 | No.3363 Two Closest Numbers |
| コンテスト | |
| ユーザー |
a01sa01to
|
| 提出日時 | 2025-12-06 01:23:28 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,062 bytes |
| 記録 | |
| コンパイル時間 | 3,092 ms |
| コンパイル使用メモリ | 284,380 KB |
| 実行使用メモリ | 7,852 KB |
| 最終ジャッジ日時 | 2025-12-06 01:23:35 |
| 合計ジャッジ時間 | 6,078 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge6 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 53 WA * 6 |
ソースコード
#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;
#include <atcoder/modint>
using mint = atcoder::modint998244353;
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
int n;
cin >> n;
vector<int> a(n);
rep(i, n) cin >> a[i];
if (n % 2 == 1) {
sort(a.begin(), a.end());
mint x = 0, y = 0;
rep(i, (n + 1) / 2) x = x * 10 + a[i];
reverse(a.begin(), a.end());
rep(i, n / 2) y = y * 10 + a[i];
cout << (x - y).val() << '\n';
}
else {
vector<int> cnt(10, 0);
rep(i, n) cnt[a[i]]++;
vector<int> rem;
rep(i, 10) if (cnt[i] % 2 == 1) rem.push_back(i);
assert(rem.size() % 2 == 0);
int ans = 1e9;
do {
int x = 0, y = 0;
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