Submission #582196

#TimeUsernameProblemLanguageResultExecution timeMemory
582196Drew_곤돌라 (IOI14_gondola)C++17
45 / 100
23 ms2716 KiB
#include "gondola.h"
#include <bits/stdc++.h>
using namespace std;

#define pb push_back
#define mp make_pair
#define f1 first
#define s2 second

using ii = pair<int, int>;

const int MAX = 1e5 + 69;

int valid(int n, int inputSeq[])
{
    int pos = 0;
    for (int i = 1; i < n; ++i)
        if (inputSeq[i] < inputSeq[pos])
            pos = i;

    int ok = true, prv = -1;
    for (int i = pos; i < n && ok; ++i) if (inputSeq[i] <= n)
    {
        if (prv > inputSeq[i])
            ok = false;
        else prv = inputSeq[i];
    }
    for (int i = 0; i < pos && ok; ++i) if (inputSeq[i] <= n)
    {
        if (prv > inputSeq[i])
            ok = false;
        else prv = inputSeq[i];
    }

    return ok;
}

//----------------------

int replacement(int n, int gondolaSeq[], int replacementSeq[])
{
    int ar[MAX];
    {
        int pos = 0;
        for (int i = 1; i < n; ++i)
            if (gondolaSeq[i] < gondolaSeq[pos])
                pos = i;

        if (gondolaSeq[pos] <= n)
            pos = (pos - gondolaSeq[pos] + 1 + n) % n;
        else pos = 0;

        iota(ar+pos, ar+n, 1);
        iota(ar, ar+pos, n-pos+1);
    }

    vector<ii> v;
    for (int i = 0; i < n; ++i)
        v.pb({gondolaSeq[i], i});
    sort(v.begin(), v.end());

    int sz = 0, cur = n+1;
    for (auto &[x, pos] : v)
    {
        while (ar[pos] != x)
        {
            replacementSeq[sz++] = ar[pos];
            ar[pos] = cur++;
        }
    }

    return sz;
}

//----------------------

int countReplacement(int n, int inputSeq[])
{
    return -3;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...