結果
問題 | No.2118 遺伝的有限集合の数え上げ |
ユーザー |
![]() |
提出日時 | 2022-11-04 21:40:15 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 25 ms / 2,000 ms |
コード長 | 849 bytes |
コンパイル時間 | 841 ms |
コンパイル使用メモリ | 103,000 KB |
実行使用メモリ | 34,432 KB |
最終ジャッジ日時 | 2024-07-18 19:23:03 |
合計ジャッジ時間 | 2,130 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 37 |
ソースコード
#include <iostream>#include <vector>#include <algorithm>#include <map>#include <queue>#include <set>#include <random>#include <iomanip>using namespace std;typedef long long ll;#define rep(i, n) for(int i = 0; i < (n); i++)template<class T>using vi = vector<T>;template<class T>using vii = vector<vi<T>>;template<class T>using viii = vector<vii<T>>;void chmax(ll & x, ll y) { x = max(x, y); }void rec(int n, vi<string>& ans) {if (n == 0) return;if ((int)ans[n].size()) return;ans[n].push_back('{');bool ok = false;for (int i = 0; i <= 20; i++) {if (n >> i & 1) {if (ok) ans[n].push_back(',');rec(i, ans);ans[n] += ans[i];ok = true;}}ans[n].push_back('}');return;}int main(){int n;cin >> n;vi<string> ans(n + 1);ans[0] = "{}";rec(n, ans);cout << ans[n] << endl;return 0;}