Submission #243261

# Submission time Handle Problem Language Result Execution time Memory
243261 2020-06-30T16:14:30 Z Kubin Gondola (IOI14_gondola) C++11
100 / 100
40 ms 5368 KB
#include <bits/stdc++.h>
#include <ext/numeric>
#ifndef XHOVA
#include "gondola.h"
#endif

using namespace std;
using __gnu_cxx::power;

void normalize(int n, int A[])
{
    int k = -1;
    for(int i = 0; i < n and k == -1; i++)
        if(A[i] <= n)
            k = (n + i - (A[i]-1)) % n;
    if(k != -1)
        rotate(A, A + k, A + n);
}

int valid(int n, int A[])
{
    normalize(n, A);
    for(int i = 0; i < n; i++)
        if(A[i] <= n and A[i]-1 != i)
            return false;
    return unordered_set<int>(A, A + n).size() == (size_t)n;
}

int replacement(int n, int A[], int out[])
{
    normalize(n, A);
    vector<pair<int, int>> re;
    for(int i = 0; i < n; i++)
        if(A[i] > n)
            re.emplace_back(A[i], i);
    sort(re.begin(), re.end());

    vector<int> B(n);
    iota(B.begin(), B.end(), 1);
    int l = 0;
    for(auto [x, i] : re)
        while(n+l < x)
            out[l++] = B[i], B[i] = n+l;
    return l;
}

constexpr uint64_t Mod = 1e9 + 9;
struct mod_multiplies : multiplies<uint64_t>
{
    uint64_t operator() (uint64_t a, uint64_t b) { return (a * b) % Mod; }
} Z;

int countReplacement(int n, int A[])
{
    if(not valid(n, A))
        return 0;

    vector<int> re;
    for(int i = 0; i < n; i++)
        if(A[i] > n)
            re.push_back(A[i]);
    sort(re.begin(), re.end());

    uint64_t result = n == (int)re.size() ? n : 1;

    vector<int> B(n);
    iota(B.begin(), B.end(), 1);
    int l = 1;
    for(int k = 0; k < (int) re.size(); k++)
    {
        result *= power(uint64_t(re.size() - k), re[k] - (n+l), Z);
        result %= Mod;
        l = re[k] - n + 1;
    }

    return result;
}

Compilation message

gondola.cpp: In function 'int replacement(int, int*, int*)':
gondola.cpp:41:14: warning: decomposition declaration only available with -std=c++1z or -std=gnu++1z
     for(auto [x, i] : re)
              ^
# Verdict Execution time Memory Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 4 ms 256 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 5 ms 256 KB Output is correct
3 Correct 5 ms 256 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 4 ms 256 KB Output is correct
6 Correct 12 ms 1952 KB Output is correct
7 Correct 16 ms 640 KB Output is correct
8 Correct 19 ms 3456 KB Output is correct
9 Correct 9 ms 1280 KB Output is correct
10 Correct 20 ms 3968 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 256 KB Output is correct
3 Correct 4 ms 256 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 13 ms 1920 KB Output is correct
7 Correct 16 ms 640 KB Output is correct
8 Correct 18 ms 3456 KB Output is correct
9 Correct 9 ms 1280 KB Output is correct
10 Correct 21 ms 3968 KB Output is correct
11 Correct 5 ms 256 KB Output is correct
12 Correct 5 ms 256 KB Output is correct
13 Correct 10 ms 512 KB Output is correct
14 Correct 4 ms 256 KB Output is correct
15 Correct 16 ms 640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
4 Correct 4 ms 256 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 4 ms 256 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 4 ms 256 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 4 ms 256 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
4 Correct 5 ms 256 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
6 Correct 5 ms 256 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 6 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 14 ms 896 KB Output is correct
12 Correct 16 ms 1024 KB Output is correct
13 Correct 21 ms 1288 KB Output is correct
14 Correct 14 ms 1024 KB Output is correct
15 Correct 25 ms 2296 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 4 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 256 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 256 KB Output is correct
7 Correct 4 ms 256 KB Output is correct
8 Correct 5 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 4 ms 256 KB Output is correct
5 Correct 4 ms 256 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 28 ms 3968 KB Output is correct
10 Correct 26 ms 3456 KB Output is correct
11 Correct 12 ms 1408 KB Output is correct
12 Correct 16 ms 1664 KB Output is correct
13 Correct 7 ms 640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 256 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 256 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 256 KB Output is correct
8 Correct 5 ms 256 KB Output is correct
9 Correct 28 ms 3968 KB Output is correct
10 Correct 24 ms 3328 KB Output is correct
11 Correct 12 ms 1408 KB Output is correct
12 Correct 14 ms 1664 KB Output is correct
13 Correct 7 ms 640 KB Output is correct
14 Correct 39 ms 4728 KB Output is correct
15 Correct 40 ms 5368 KB Output is correct
16 Correct 11 ms 1280 KB Output is correct
17 Correct 28 ms 3712 KB Output is correct
18 Correct 20 ms 2304 KB Output is correct