Submission #582220

#TimeUsernameProblemLanguageResultExecution timeMemory
582220Drew_곤돌라 (IOI14_gondola)C++17
55 / 100
18 ms3148 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 = 250069;

int valid(int n, int inputSeq[])
{
    bitset<MAX> vst;
    for (int i = 0; i < n; ++i)
    {
        if (vst[inputSeq[i]])
            return 0;
        vst[inputSeq[i]] = true;
    }

    int pos = -1;
    for (int i = 0; i < n; ++i) if (inputSeq[i] <= n)
    {
        int tmp = (inputSeq[i] - i + n) % n;
        if (pos == -1) pos = tmp;
        if (pos != tmp) return 0;
    }
    return 1;
}

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

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...