結果
| 問題 |
No.3363 Two Closest Numbers
|
| コンテスト | |
| ユーザー |
risujiroh
|
| 提出日時 | 2025-11-17 21:28:07 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,670 bytes |
| コンパイル時間 | 3,174 ms |
| コンパイル使用メモリ | 299,472 KB |
| 実行使用メモリ | 7,852 KB |
| 最終ジャッジ日時 | 2025-11-17 21:28:14 |
| 合計ジャッジ時間 | 5,769 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 53 WA * 6 |
ソースコード
#if __INCLUDE_LEVEL__ == 0
#include __BASE_FILE__
using Mint = atcoder::modint998244353;
void Solve() {
int n;
IN(n);
vector<int> a(n);
IN(a);
ranges::sort(a);
if (n % 2) {
Mint ans = 0;
for (int e : a | views::take((n + 1) / 2)) {
ans *= 10;
ans += e;
}
Mint tmp = 0;
for (int e : Rev(a) | views::take((n - 1) / 2)) {
tmp *= 10;
tmp += e;
}
ans -= tmp;
OUT(ans);
return;
}
vector<int> odd;
for (int x : Rep1(1, 9)) {
if (ranges::count(a, x) % 2) {
odd.push_back(x);
}
}
assert(Sz(odd) % 2 == 0);
if (odd.empty()) {
OUT(0);
return;
}
int ans = INF;
do {
int cur = 0;
for (int i = 0; i < Sz(odd); i += 2) {
cur *= 10;
cur += (odd[i] - odd[i + 1]);
}
SetMin(ans, abs(cur));
} while (ranges::next_permutation(odd).found);
OUT(ans);
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
Solve();
}
#elif __INCLUDE_LEVEL__ == 1
#include <bits/stdc++.h>
#include <atcoder/modint.hpp>
template <class T> concept MyRange = std::ranges::range<T> && !std::convertible_to<T, std::string_view>;
template <class T> concept MyTuple = std::__is_tuple_like<T>::value && !MyRange<T>;
namespace std {
istream& operator>>(istream& is, MyRange auto&& r) {
for (auto&& e : r) is >> e;
return is;
}
istream& operator>>(istream& is, MyTuple auto&& t) {
apply([&](auto&... xs) { (is >> ... >> xs); }, t);
return is;
}
ostream& operator<<(ostream& os, MyRange auto&& r) {
auto sep = "";
for (auto&& e : r) os << exchange(sep, " ") << e;
return os;
}
ostream& operator<<(ostream& os, MyTuple auto&& t) {
auto sep = "";
apply([&](auto&... xs) { ((os << exchange(sep, " ") << xs), ...); }, t);
return os;
}
template <class T, atcoder::internal::is_modint_t<T>* = nullptr>
istream& operator>>(istream& is, T& x) {
int v;
is >> v;
x = T::raw(v);
return is;
}
template <class T, atcoder::internal::is_modint_t<T>* = nullptr>
ostream& operator<<(ostream& os, const T& x) {
return os << x.val();
}
} // namespace std
using namespace std;
#define LAMBDA2(x, y, ...) ([&](auto&& x, auto&& y) -> decltype(auto) { return __VA_ARGS__; })
#define Rev views::reverse
#define Rep(...) [](int l, int r) { return views::iota(min(l, r), r); }(__VA_ARGS__)
#define Rep1(...) [](int l, int r) { return Rep(l, r + 1); }(__VA_ARGS__)
#define Sz(r) int(size(r))
#define SetMin(...) LAMBDA2(x, y, y < x && (x = y, 1))(__VA_ARGS__)
#define INF (INT_MAX / 2)
#define IN(...) (cin >> forward_as_tuple(__VA_ARGS__))
#define OUT(...) (cout << forward_as_tuple(__VA_ARGS__) << '\n')
#endif // __INCLUDE_LEVEL__ == 1
risujiroh