結果
問題 |
No.135 とりあえず1次元の問題
|
ユーザー |
![]() |
提出日時 | 2025-08-14 13:41:00 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 42 ms / 5,000 ms |
コード長 | 1,154 bytes |
コンパイル時間 | 1,198 ms |
コンパイル使用メモリ | 104,896 KB |
実行使用メモリ | 7,716 KB |
最終ジャッジ日時 | 2025-08-14 13:41:03 |
合計ジャッジ時間 | 2,628 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 22 |
ソースコード
#include <iostream> #include <vector> #include <cstdint> #include <algorithm> #include <climits> template <typename T = uint32_t> void radixsort_unsigned(std::vector<T>& arr) { if (arr.empty()) { return; } std::vector<std::vector<T>> buckets(256); for (size_t i = 0; i < sizeof(T); ++i) { for (T num : arr) { uint8_t bucketIndex = (num >> (i * 8)) & 0xFF; buckets[bucketIndex].push_back(num); } size_t arrIndex = 0; for (auto& bucket : buckets) { for (T num : bucket) { arr[arrIndex++] = num; } bucket.clear(); } } } int main() { int n; std::cin >> n; std::vector<uint32_t> x(n); for (int i = 0; i < n; i++) { std::cin >> x[i]; } radixsort_unsigned(x); x.erase(std::unique(x.begin(), x.end()), x.end()); n = int(x.size()); if (n == 1) { std::cout << 0 << std::endl; } else { uint32_t ans = 1e9; for (int i = 0; i < n - 1; i++) { ans = std::min(ans, x[i + 1] - x[i]); } std::cout << ans << std::endl; } }