Submission #1276824

#TimeUsernameProblemLanguageResultExecution timeMemory
1276824Tien_Noobmedians (balkan11_medians)C++20
100 / 100
14 ms4088 KiB
//Make CSP great again
//Vengeance
#include <bits/stdc++.h>
#define TASK "TESTCODE"
using namespace std;
const int N = 1e5;
int a[N + 1], n;
bool visited[2 * N];
int find_first()
{
    static int st = 1;
    while(visited[st])
    {
        ++st;
    }
    visited[st] = true;
    return st;
}
int find_last()
{
    static int st = 2 * n - 1;
    while(visited[st])
    {
        --st;
    }
    visited[st] = true;
    return st;
}
void read()
{
    cin >> n;
    for (int i = 1; i <= n; ++ i)
    {
        cin >> a[i];
    }
}
void solve()
{
    cout << a[1] << ' ';
    visited[a[1]] = true;
    for (int i = 2; i <= n; ++ i)
    {
        if (a[i] == a[i - 1])
        {
            cout << find_first() << ' ' << find_last() << ' ';
        }
        else if (a[i] > a[i - 1])
        {
            if (visited[a[i]])
            {
                cout << find_last() << ' ' << find_last() << ' ';
            }
            else 
            {
                visited[a[i]] = true;
                cout << a[i] << ' ' << find_last() << ' ';
            }
        }
        else 
        {
            if (visited[a[i]])
            {
                cout << find_first() << ' ' << find_first() << ' ';
            }
            else 
            {
                visited[a[i]] = true;
                cout << a[i] << ' ' << find_first() << ' ';
            }
        }
    }
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    if (fopen(TASK".INP", "r"))
    {
        freopen(TASK".INP", "r", stdin);
        //freopen(TASK".OUT", "w", stdout);
    }
    int t = 1;
    bool typetest = false;
    if (typetest)
    {
        cin >> t;
    }
    for (int __ = 1; __ <= t; ++ __)
    {
        //cout << "Case " << __ << ": ";
        read();
        solve();
    }
}

Compilation message (stderr)

medians.cpp: In function 'int main()':
medians.cpp:79:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   79 |         freopen(TASK".INP", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...