Submission #1243475

#TimeUsernameProblemLanguageResultExecution timeMemory
1243475inkvizytorGondola (IOI14_gondola)C++17
55 / 100
12 ms2108 KiB
#include "gondola.h"
#include <bits/stdc++.h>
using namespace std;

int valid(int n, int inputSeq[])
{
    int p = 0;
    for (int i = 0; i < n; i++) {
        if (inputSeq[i] <= n) {
            p = (inputSeq[i]+n-i)%n;
            break;
        }
    }
    if (p == 0) {
        sort(inputSeq, inputSeq+n);
        for (int i = 1; i < n; i++) {
            if (inputSeq[i] == inputSeq[i-1]) {
                return 0;
            }
        }
        return 1;
    }
    for (int i = 0; i < n; i++) {
        if (inputSeq[i] <= n && inputSeq[i]%n != p%n) {
            return 0;
        }
        p++;
    }
    sort(inputSeq, inputSeq+n);
    for (int i = 1; i < n; i++) {
        if (inputSeq[i] == inputSeq[i-1]) {
            return 0;
        }
    }
    return 1;
}

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

int replacement(int n, int gondolaSeq[], int replacementSeq[])
{
    int p = 0;
    for (int i = 0; i < n; i++) {
        if (gondolaSeq[i] <= n) {
            p = i-(gondolaSeq[i]-1);
            if (p < 0) {
                p+=n;
            }
            break;
        }
    }
    vector<pair<int, int>> x;
    for (int i = 0; i < n; i++) {
        if (gondolaSeq[i] > n) {
            x.push_back({gondolaSeq[i], i});
        }
    }
    sort(x.begin(), x.end());
    int w = n, in = 0;
    for (auto i : x) {
        int k = i.second-p+1;
        if (k <= 0) {
            k += n;
        }
        replacementSeq[in] = k;
        in++;
        w++;
        while (w < i.first) {
            replacementSeq[in] = w;
            in++;
            w++;
        }
    }
    return in;
}

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

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