제출 #1270074

#제출 시각아이디문제언어결과실행 시간메모리
1270074kawhiet곤돌라 (IOI14_gondola)C++20
60 / 100
11 ms2244 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);
    for (int i = 0; i < n; i++) {
        a[i] = {gondolaSeq[i], i};
    }
    vector<int> val(n);
    iota(val.begin(), val.end(), 1);
    for (int i = 0; i < n; i++) {
        if (gondolaSeq[i] <= n) {
            val[i] = gondolaSeq[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 j = 0, res = 0, x = n;
    for (auto [k, i] : a) {
        bool first = 1;
        while (k > x) {
            res++;
            if (first) {
                first = 0;
                replacementSeq[j++] = val[i];
            }
            else {
                replacementSeq[j++] = x;
            }
            x++;
        }
    }
    return res;
}

const int mod = 1e9 + 7;

int power(int a, int b) {
    int res = 1;
    while (b >= 1) {
        if (b & 1) {
            res = (1LL * res * a) % mod;
        }
        a = (1LL * a * a) % mod;
        b >>= 1;
    }
    return res;
}

int countReplacement(int n, int inputSeq[]) {
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        a[i] = inputSeq[i];
    }
    vector<int> b;
    for (int i = 0; i < n; i++) {
        if (a[i] > n) {
            b.push_back(a[i]);
        }
    }
    sort(b.begin(), b.end());
    int cnt = b.size();
    int res = (cnt == n ? n : 1);
    int cur = n;
    for (auto x : b) {
        res = 1LL * res * power(cnt, x - cur - 1);
        cnt--;
        cur = x;
    }
    return res;
}
#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...