summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--file.cc117
1 files changed, 117 insertions, 0 deletions
diff --git a/file.cc b/file.cc
new file mode 100644
index 0000000..0710c40
--- /dev/null
+++ b/file.cc
@@ -0,0 +1,117 @@
+#define USE_ORDERED_STATISTICS
+#define BIG_BIGINT
+
+#include <bits/stdc++.h>
+
+#ifdef USE_ORDERED_STATISTICS
+ #include <ext/pb_ds/assoc_container.hpp>
+ #include <ext/pb_ds/tree_policy.hpp>
+ using namespace __gnu_pbds;
+#endif
+
+using namespace std;
+
+typedef long long int ll;
+#ifdef BIG_BIGINT
+ typedef __int128_t bigint;
+#else
+ typedef ll bigint;
+#endif
+typedef pair<int, int> pi;
+typedef pair<ll, ll> pl;
+typedef vector<int> vi;
+typedef vector<ll> vl;
+typedef vector<vi> vvi;
+typedef vector<vl> vvl;
+typedef vector<pi> vpi;
+typedef vector<pl> vpl;
+typedef vector<vpi> vvpi;
+typedef vector<vpl> vvpl;
+typedef set<int> si;
+typedef multiset<int> msi;
+typedef set<ll> sl;
+typedef multiset<ll> msl;
+typedef long double ld;
+template<class T> using func = function<T>;
+
+#ifdef USE_ORDERED_STATISTICS
+ typedef tree<
+ pl,
+ null_type,
+ less<pl>,
+ rb_tree_tag,
+ tree_order_statistics_node_update>
+ ordered_set;
+#endif
+
+#define clrcin cin.ignore(numeric_limits<streamsize>::max(),'\n');
+#define GOGOGO ios::sync_with_stdio(false); cin.tie(nullptr);
+#define BYEBYE return 0;
+
+#define all(cn) (cn).begin(), (cn).end()
+#define rep(i, n) for (int i = 0; i < n; ++i)
+#define csz(c) ((int)c.size())
+#define mp make_pair
+#define eb emplace_back
+#define fi first
+#define se second
+
+#define popcnt __builtin_popcount
+#define popcntll __builtin_popcount_ll
+
+
+const int INFI = 1e9 + 5;
+const ll INFL = 1e18 + 5;
+mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
+auto dist = uniform_int_distribution<int>(0, INFI);
+auto distll = uniform_int_distribution<ll>(0, INFL);
+int rnd() { return dist(rng); }
+ll rndl() { return distll(rng); }
+#define pb pop_back
+#define vvc vector<vector<char>>
+#define back push_back
+using namespace std;
+
+void print(const vvc& partition) {
+ for (const auto& subset : partition) {
+ cout << "{ ";
+ for (char item : subset) {
+ cout << item << " ";
+ }
+ cout << "} ";
+ }
+ cout << endl;
+}
+void help(vvc& cp,
+ const string& elements, int n, int k, int idx) {
+ if (idx == n) {
+ if (k == 0 || cp.size() == k) {
+ print(cp);
+ }
+ return;
+ }
+ for (int i = 0; i < cp.size(); ++i) {
+ cp[i].back(elements[idx]);
+ help(cp, elements, n, k, idx + 1);
+ cp[i].pb();
+ }
+ if (k == 0 || cp.size() < k) {
+ cp.back({elements[idx]});
+ help(cp, elements, n, k, idx + 1);
+ cp.pb();
+ }
+}
+
+void gen(const string& elements, int k = 0) {
+ vvc cp;
+ help(cp, elements, elements.size(), k, 0);
+}
+
+int main() {
+ string elements = "abc";
+ gen(elements, 2);
+ gen(elements);
+
+ return 0;
+}
+