93002024-02-20 11:39:06zsebiKombináció (50)cpp17Hibás válasz 41/503ms3584 KiB
// ulesrend2.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

#include <iostream>
#include <queue>

#define ll long long 
using namespace std;
vector<int>stati, comb,elo,uto;
ll n, k,j;
void eloz()
{
    for (int i = k; i >= 1; --i)
    {
        j = comb[i] - 1;
        while (stati[j])
        {
            --j;
        }
        if (j > comb[i - 1]&&j<comb[i+1])
        {
            elo[i] = j;
            break;
        }
    }
}
void utana()
{
    for (int i = k; i >= 1; --i)
    {
         j = comb[i] + 1;
        while (j<n &&stati[j])
        {
            ++j;
        }
        if (j<=n && j > comb[i - 1]&&j<comb[i+1])
        {
            uto[i] = j;
            break;
        }
    }
}
int main()
{
    cin >> n >> k;
    stati.assign(n + 1, 0);
    comb.assign(k + 2, 101);
    elo.assign(k + 1, 0);
    uto.assign(k + 1, 0);
    for (int i = 1; i <= k; ++i)
    {
        cin >> comb[i];
        stati[comb[i]] = 1;
    }
    comb[0] = 0;
    eloz();
    utana();
    for (int i = 1; i <= k; ++i)
    {
        if (elo[i])cout << elo[i] << " ";
        else cout << comb[i]<<" ";
    }
    cout << "\n";
    for (int i = 1; i <= k; ++i)
    {
        if (uto[i])cout << uto [i] << " ";
        else cout << comb[i]<<" ";
    }

    return 0;
}

// Run program: Ctrl + F5 or Debug > Start Without Debugging menu
// Debug program: F5 or Debug > Start Debugging menu

// Tips for Getting Started: 
//   1. Use the Solution Explorer window to add/manage files
//   2. Use the Team Explorer window to connect to source control
//   3. Use the Output window to see build output and other messages
//   4. Use the Error List window to view errors
//   5. Go to Project > Add New Item to create new code files, or Project > Add Existing Item to add existing code files to the project
//   6. In the future, to open this project again, go to File > Open > Project and select the .sln file
RészfeladatÖsszpontTesztVerdiktIdőMemória
base41/50
1Elfogadva0/03ms1876 KiB
2Hibás válasz0/03ms2068 KiB
3Elfogadva2/23ms2292 KiB
4Elfogadva2/22ms2376 KiB
5Részben helyes1/23ms2512 KiB
6Részben helyes1/23ms2748 KiB
7Részben helyes1/22ms2808 KiB
8Elfogadva2/23ms2964 KiB
9Részben helyes1/22ms3056 KiB
10Részben helyes2/43ms3084 KiB
11Elfogadva4/43ms3076 KiB
12Elfogadva4/43ms3208 KiB
13Elfogadva4/42ms3292 KiB
14Elfogadva4/43ms3300 KiB
15Elfogadva4/43ms3304 KiB
16Elfogadva6/63ms3508 KiB
17Részben helyes3/63ms3584 KiB