Submission #1268918

#TimeUsernameProblemLanguageResultExecution timeMemory
1268918kawhietGondola (IOI14_gondola)C++20
25 / 100
6 ms1096 KiB
#include <bits/stdc++.h>
#include "gondola.h"
using namespace std;

int valid(int n, int inputSeq[]) {
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        a[i] = inputSeq[i];
        a[i] %= n;
        if (a[i] == 0) {
            a[i] = n;
        }
    }
    for (int i = 1; i < n; i++) {
        if (a[i] % n != (a[i - 1] + 1) % n) {
            return 0;
        }
    }
    return 1;
}

int replacement(int n, int gondolaSeq[], int replacementSeq[]) {
    vector<pair<int, int>> a(n);
    vector<int> b(n);
    for (int i = 0; i < n; i++) {
        a[i] = {gondolaSeq[i], i};
        b[i] = gondolaSeq[i] % n;
        if (b[i] == 0) {
            b[i] = n;
        }
    }
    vector<int> val(n);
    iota(val.begin(), val.end(), 1);
    for (int i = 0; i < n; i++) {
        if (b[i] <= n) {
            val[i] = b[i];
            for (int j = i - 1; j >= 0; j--) {
                val[j] = val[j + 1] - 1;
                if (val[j] == 0) {
                    val[j] = n;
                }
            }
            for (int j = i + 1; j < n; j++) {
                val[j] = val[j - 1] + 1;
                if (val[j] == n + 1) {
                    val[j] = 1;
                }
            }
        }
        break;
    }
    sort(a.begin(), a.end());
    int x = n, j = 0;
    for (auto [k, i] : a) {
        while (k > x) {
            x++;
            replacementSeq[j++] = val[i];
            val[i] += x;
        }
    }
    return x - n;
}

int countReplacement(int n, int inputSeq[]) {
    return 0;
}
#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...