結果
問題 | No.3030 Kruskal-Katona |
ユーザー |
|
提出日時 | 2025-02-21 22:17:51 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 3 ms / 2,000 ms |
コード長 | 1,034 bytes |
コンパイル時間 | 2,159 ms |
コンパイル使用メモリ | 196,740 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2025-02-21 22:18:06 |
合計ジャッジ時間 | 3,314 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 27 |
ソースコード
#include <bits/stdc++.h>using namespace std;using ll = long long;template<typename T>T MUL(T a, T b){T res;return __builtin_mul_overflow(a, b, &res)? std::numeric_limits<T>::max() : res;}ll n, k;long long int combination(long long int a, long long int b){long long int ans = 1;b = min(b, a - b);for(int i = 0; i < b; i++){ans = MUL(ans, a - b + i + 1);ans /= i + 1;if(ans > n) return (1ll << 60);}return ans;}int main(){ios::sync_with_stdio(false);cin.tie(0);cin >> n >> k;vector<ll> ans;ll pr = 1ll << 60;for(ll j = k; j >= 1 && n >= 1; j--){ll ok = j, ng = min(n + 1, pr);while(ok + 1 < ng){ll mid = (ok + ng) / 2;(combination(mid, j) <= n ? ok : ng) = mid;}ans.emplace_back(ok);pr = ok;n -= combination(ok, j);}assert(n == 0);for(int i = 0; i < ans.size(); i++){cout << ans[i] << (i + 1 == ans.size() ? '\n' : ' ');}}