Submission #781025

# Submission time Handle Problem Language Result Execution time Memory
781025 2023-07-12T15:57:19 Z vjudge1 Gondola (IOI14_gondola) C++17
100 / 100
43 ms 7148 KB
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include "gondola.h"
#define MAX 250000
#define MOD 1000000009
using namespace std;
set <int> s;
vector <pair <int, int>> v;
int valid(int n, int inputSeq[])
{
    int posOrig = -1;
    for (int i = 0; i < n; i++)
    {
        if (s.find(inputSeq[i]) != s.end())
            return 0;
        if (inputSeq[i] <= n)
            posOrig = i;
        s.insert(inputSeq[i]);
    }
    if (posOrig == -1)
        return 1;
    int pos = posOrig;
    for (int i = 1; i <= n; i++)
    {
        if (inputSeq[pos] <= n && (inputSeq[pos] - inputSeq[posOrig] + n) % n != (pos - posOrig + n) % n)
            return 0;
        pos = (pos + 1) % n;
    }
    return 1;
}
int replacement(int n, int gondolaSeq[], int replacementSeq[])
{
    int posOrig = -1;
    for (int i = 0; i < n; i++)
        if (gondolaSeq[i] <= n)
            posOrig = i;
    if (posOrig == -1)
        for (int i = 0; i < n; i++)
            v.push_back({gondolaSeq[i], i + 1});
    else
    {
        int pos = posOrig;
        int g = gondolaSeq[posOrig];
        for (int i = 1; i <= n; i++)
        {
            if (gondolaSeq[pos] > n)
                v.push_back({gondolaSeq[pos], g});
            pos = (pos + 1) % n;
            if (g == n - 1)
                g = n;
            else
                g = (g + 1) % n;
        }
    }
    sort(v.begin(), v.end());
    int l = 0, nn = n + 1;
    for (auto it : v)
    {
        replacementSeq[l] = it.second;
        l++;
        nn++;
        while (nn <= it.first)
        {
            replacementSeq[l] = nn - 1;
            l++;
            nn++;
        }
    }
    return l;
}
int fastPow(int base, int exp)
{
    int ans = 1;
    while (exp != 0)
        if (exp % 2 == 0)
        {
            exp = exp / 2;
            base = 1LL * base * base % MOD;
        }
        else
        {
            exp--;
            ans = 1LL * ans * base % MOD;
        }
    return ans;
}
int countReplacement(int n, int inputSeq[])
{
    if (valid(n, inputSeq) == 0)
        return 0;
    int posOrig = -1;
    for (int i = 0; i < n; i++)
        if (inputSeq[i] <= n)
            posOrig = i;
    int ans;
    if (posOrig == -1)
    {
        ans = n;
        for (int i = 0; i < n; i++)
            v.push_back({inputSeq[i], i + 1});
    }
    else
    {
        ans = 1;
        int pos = posOrig;
        int g = inputSeq[posOrig];
        for (int i = 1; i <= n; i++)
        {
            if (inputSeq[pos] > n)
                v.push_back({inputSeq[pos], g});
            pos = (pos + 1) % n;
            if (g == n - 1)
                g = n;
            else
                g = (g + 1) % n;
        }
    }
    sort(v.begin(), v.end());
    int cntGreater = v.size(), aux = n;
    for (auto it : v)
    {
        ans = 1LL * ans * fastPow(cntGreater, it.first - aux - 1) % MOD;
        cntGreater--;
        aux = it.first;
    }
    return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 12 ms 2124 KB Output is correct
7 Correct 7 ms 596 KB Output is correct
8 Correct 20 ms 3888 KB Output is correct
9 Correct 6 ms 1364 KB Output is correct
10 Correct 24 ms 4464 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 12 ms 2200 KB Output is correct
7 Correct 6 ms 616 KB Output is correct
8 Correct 20 ms 3856 KB Output is correct
9 Correct 6 ms 1364 KB Output is correct
10 Correct 24 ms 4468 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 11 ms 2004 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 28 ms 4556 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 6 ms 496 KB Output is correct
12 Correct 8 ms 596 KB Output is correct
13 Correct 11 ms 1408 KB Output is correct
14 Correct 7 ms 596 KB Output is correct
15 Correct 15 ms 2384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 31 ms 4692 KB Output is correct
10 Correct 24 ms 4052 KB Output is correct
11 Correct 9 ms 1752 KB Output is correct
12 Correct 15 ms 1996 KB Output is correct
13 Correct 3 ms 724 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 30 ms 4680 KB Output is correct
10 Correct 24 ms 3984 KB Output is correct
11 Correct 9 ms 1752 KB Output is correct
12 Correct 11 ms 1996 KB Output is correct
13 Correct 3 ms 724 KB Output is correct
14 Correct 37 ms 5696 KB Output is correct
15 Correct 43 ms 7148 KB Output is correct
16 Correct 7 ms 1748 KB Output is correct
17 Correct 29 ms 4732 KB Output is correct
18 Correct 15 ms 3100 KB Output is correct