Submission #587119

# Submission time Handle Problem Language Result Execution time Memory
587119 2022-07-01T10:44:38 Z Jomnoi Gondola (IOI14_gondola) C++17
100 / 100
44 ms 5508 KB
#include <bits/stdc++.h>
#include "gondola.h"
using namespace std;

const int MOD = 1e9 + 9;

int valid(int n, int inputSeq[]) {
    set <int> s;
    int pos = -1;
    for(int i = 0; i < n; i++) {
        s.insert(inputSeq[i]);
        if(inputSeq[i] <= n) {
            pos = i;
        }
    }
    
    if(s.size() < n) {
        return 0;
    }
    if(pos == -1) {
        return 1;
    }

    int start = (inputSeq[pos] - pos - 1 + 2 * n) % n + 1;
    for(int i = 0; i < n; i++) {
        if(inputSeq[i] <= n and inputSeq[i] != (start + i - 1) % n + 1) {
            return 0;
        }
    }
    return 1;
}

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

int replacement(int n, int gondolaSeq[], int replacementSeq[]) {
    map <int, int> location;
    int start = 1, max_val = 0;
    for(int i = 0; i < n; i++) {
        if(gondolaSeq[i] <= n) {
            start = (gondolaSeq[i] - i - 1 + 2 * n) % n + 1;
        }

        max_val = max(max_val, gondolaSeq[i]);
        location[gondolaSeq[i]] = i;
    }

    int j = n + 1, len = 0;
    for(int i = n + 1; i <= max_val; i++) {
        if(!location.count(i)) {
            continue;
        }

        replacementSeq[len++] = (location[i] + start - 1) % n + 1;
        while(j < i) {
            if(!location.count(j)) {
                replacementSeq[len++] = j;
            }
            j++;
        }
    }
    return len;
}

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

long long expo(int x, int y) {
    if(y == 0) {
        return 1;
    }

    long long res = expo(x, y / 2);
    res = res * res % MOD;
    if(y % 2 == 1) {
        res = res * x % MOD;
    }
    return res;
}

int countReplacement(int n, int inputSeq[]) {
    if(valid(n, inputSeq) == 0) {
        return 0;
    }

    vector <int> newGondola;
    for(int i = 0; i < n; i++) {
        if(inputSeq[i] > n) {
            newGondola.push_back(inputSeq[i]);
        }
    }


    sort(newGondola.begin(), newGondola.end());

    long long ans = 1;
    int prev = n;
    for(int i = 0; i < newGondola.size(); i++) {
        ans = ans * expo(newGondola.size() - i, newGondola[i] - prev - 1) % MOD;
        prev = newGondola[i];
    }

    if(newGondola.size() == n) {
        ans = ans * n % MOD;
    }
    return ans;
}

Compilation message

gondola.cpp: In function 'int valid(int, int*)':
gondola.cpp:17:17: warning: comparison of integer expressions of different signedness: 'std::set<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   17 |     if(s.size() < n) {
      |        ~~~~~~~~~^~~
gondola.cpp: In function 'int countReplacement(int, int*)':
gondola.cpp:96:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   96 |     for(int i = 0; i < newGondola.size(); i++) {
      |                    ~~^~~~~~~~~~~~~~~~~~~
gondola.cpp:101:26: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
  101 |     if(newGondola.size() == n) {
      |        ~~~~~~~~~~~~~~~~~~^~~~
# 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 1 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 1 ms 224 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 9 ms 2132 KB Output is correct
7 Correct 23 ms 3528 KB Output is correct
8 Correct 17 ms 3848 KB Output is correct
9 Correct 6 ms 1440 KB Output is correct
10 Correct 22 ms 4436 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 14 ms 2172 KB Output is correct
7 Correct 30 ms 3636 KB Output is correct
8 Correct 17 ms 3904 KB Output is correct
9 Correct 6 ms 1364 KB Output is correct
10 Correct 22 ms 4404 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 29 ms 4664 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 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 0 ms 212 KB Output is correct
7 Correct 1 ms 340 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 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 1 ms 340 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 19 ms 4272 KB Output is correct
12 Correct 22 ms 4804 KB Output is correct
13 Correct 26 ms 2644 KB Output is correct
14 Correct 21 ms 4244 KB Output is correct
15 Correct 29 ms 2844 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 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 1 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 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 1 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 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 31 ms 3920 KB Output is correct
10 Correct 24 ms 3412 KB Output is correct
11 Correct 9 ms 1440 KB Output is correct
12 Correct 13 ms 1620 KB Output is correct
13 Correct 2 ms 612 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 5 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 1 ms 212 KB Output is correct
9 Correct 31 ms 4000 KB Output is correct
10 Correct 26 ms 3372 KB Output is correct
11 Correct 8 ms 1364 KB Output is correct
12 Correct 13 ms 1620 KB Output is correct
13 Correct 2 ms 596 KB Output is correct
14 Correct 41 ms 4808 KB Output is correct
15 Correct 44 ms 5508 KB Output is correct
16 Correct 7 ms 1296 KB Output is correct
17 Correct 30 ms 3664 KB Output is correct
18 Correct 16 ms 2324 KB Output is correct