Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define int long long
- #define vi vector<int>
- #define vii vector<vi>
- #define ii pair<int,int>
- #define fi first
- #define sc second
- #define pb push_back
- #define stoi stoll
- #define popcnt __builtin_popcount
- #define getbit(x, k) ((x >> k) & 1)
- #define all(x) (x).begin(),(x).end()
- #define rall(x) (x).rbegin(),(x).rend()
- #define FOR(i,j,k) for(int i=j; i<(int)k; ++i)
- #define look(a) cerr <<#a<<": "<<a<<endl;
- #define look2(a,b) cerr <<#a<<": "<<a<<" | "<<#b<<": "<<b<< endl;
- void solve()
- {
- vi a;
- int x;
- while (cin >> x) a.push_back(x);
- int k = a.back();
- a.pop_back();
- int n = a.size();
- vi b;
- FOR(i,1,n+1) b.push_back(i);
- vi c = b;
- // First line
- int t = 1;
- while (b != a){
- t++;
- next_permutation(all(b));
- }
- cout << t << '\n';
- // Second line
- FOR(i,1,k) next_permutation(all(c));
- for(auto&i:c) cout << i << ' ';
- }
- signed main()
- {
- cin.tie(0)->sync_with_stdio(0);
- freopen("in", "r", stdin);
- freopen("out", "w", stdout);
- int T = 1;
- // cin >> T;
- while (T--) {
- solve();
- cout << '\n';
- }
- cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement