28242023-01-28 14:05:161478Kombináció (50)cpp17Részben helyes 48/503ms3968 KiB
#include <bits/stdc++.h>
#include <random>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> p32;
typedef pair<ll, ll> p64;
typedef pair<double, double> pdd;
typedef vector<ll> v64;
typedef vector<int> v32;
typedef vector<vector<int>> vv32;
typedef vector<vector<ll>> vv64;
typedef vector<vector<p64>> vvp64;
typedef vector<p64> vp64;
typedef vector<p32> vp32;
ll MOD = 998244353;
double eps = 1e-12;
#define forn(i, e) for (ll i = 0; i < e; i++)
#define forsn(i, s, e) for (ll i = s; i < e; i++)
#define rforn(i, s) for (ll i = s; i >= 0; i--)
#define rforsn(i, s, e) for (ll i = s; i >= e; i--)
#define ln "\n"
#define dbg(x) cout << #x << " = " << x << ln
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define INF 2e18
#define fast_cin()                    \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())

int main()
{
    fast_cin();
    //ifstream cin("in.txt");

    int n;
    cin >> n;

    int m;
    cin >> m;

    vector<bool> defaultState(n + 1);
    for (int i = 1; i <= m; i++)
    {
        int temp;
        cin >> temp;
        defaultState[temp] = 1;
    }

    // kisebb
    vector<bool> temp = defaultState;
    int ones = n, zeros = n;
    while (temp[ones] == 0)
    {
        ones--;
    }
    if (ones == m)
    {
        for (int i = n - m + 1; i <= n; i++)
        {
            cout << i << " ";
        }
        cout << ln;
    }
    else
    {
        while (ones >= 2 && temp[ones] == 1 && temp[ones - 1] != 0)
        {
            swap(temp[ones], temp[zeros]);
            ones--;
            zeros--;
        }
        swap(temp[ones - 1], temp[ones]);

        for (int i = 1; i <= n; i++)
        {
            if (temp[i])
            {
                cout << i << " ";
            }
        }
        cout << ln;
    }

    // nagyobb
    temp = defaultState;
    ones = n;
    zeros = n;
    while (temp[zeros] == 1)
    {
        zeros--;
    }
    if (zeros == m)
    {
        for (int i = 1; i <= m; i++)
        {
            cout << i << " ";
        }
        cout << ln;
    }
    else
    {
        while (zeros >= 2 && temp[zeros] == 0 && temp[zeros - 1] != 1)
        {
            swap(temp[zeros], temp[ones]);
            zeros--;
            ones--;
        }
        swap(temp[zeros - 1], temp[zeros]);

        for (int i = 1; i <= n; i++)
        {
            if (temp[i])
            {
                cout << i << " ";
            }
        }
        cout << ln;
    }

    return 0;
}
RészfeladatÖsszpontTesztVerdiktIdőMemória
base48/50
1Elfogadva0/03ms1828 KiB
2Elfogadva0/02ms2164 KiB
3Elfogadva2/22ms2236 KiB
4Elfogadva2/22ms2432 KiB
5Elfogadva2/22ms2640 KiB
6Elfogadva2/22ms2716 KiB
7Elfogadva2/22ms2716 KiB
8Elfogadva2/22ms2812 KiB
9Elfogadva2/22ms3016 KiB
10Részben helyes2/42ms3212 KiB
11Elfogadva4/42ms3324 KiB
12Elfogadva4/42ms3532 KiB
13Elfogadva4/42ms3728 KiB
14Elfogadva4/42ms3732 KiB
15Elfogadva4/42ms3840 KiB
16Elfogadva6/62ms3968 KiB
17Elfogadva6/62ms3940 KiB