Submission #1007514

# Submission time Handle Problem Language Result Execution time Memory
1007514 2024-06-25T05:34:03 Z The_Samurai Gondola (IOI14_gondola) C++17
75 / 100
31 ms 5208 KB
#include "gondola.h"
#include "bits/stdc++.h"
using namespace std;
using ll = long long;

int valid(int n, int a[]) {
    int last = -1;
    set<int> st;
    for (int i = 0; i < 2 * n; i++) {
        if (a[i % n] > n) continue;
        st.insert(a[i % n]);
        if (last != -1 and (a[last % n] + i - last - 1) % n != a[i % n] - 1) return 0;
        last = i;
    }
    return st.size() == n;
}

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

int replacement(int n, int a[], int replacementSeq[]) {
    const int N = 2e5 + 5;
    vector<int> owns(N, -1), old(n);
    int any = -1, last = -1;
    for (int i = 0; i < n; i++) {
        if (a[i] <= n) continue;
        owns[a[i]] = i;
        if (any == -1 or a[any] < a[i]) any = i;
    }
    for (int i = 0; i < 2 * n; i++) {
        if (a[i % n] <= n) last = i;
        if (last == -1) continue;
        old[i % n] = (a[last % n] + i - last - 1) % n + 1;
    }
    if (last == -1) {
        for (int i = 0; i < n; i++) old[i] = i + 1;
    }
    int mx = *max_element(a, a + n), z = 0;
    for (int i = n + 1; i <= mx; i++) {     
        if (owns[i] != -1) {
            replacementSeq[z++] = old[owns[i]];
            old[owns[i]] = i;
        } else {
            replacementSeq[z++] = old[any];
            old[any] = i;
        }
    }
    return z;
}

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

const int mod = 1e9 + 9;

int countReplacement(int n, int a[]) {
    int last = -1;
    set<int> st;
    for (int i = 0; i < 2 * n; i++) {
        st.insert(a[i % n]);
        if (a[i % n] > n) continue;
        if (last != -1 and (a[last % n] + i - last - 1) % n != a[i % n] - 1) return 0;
        last = i;
    }
    if (st.size() != n) return 0;
    const int N = 3e5 + 5;
    vector<int> owns(N, -1);
    ll ans = 1, left = 0;
    for (int i = 0; i < n; i++) {
        if (a[i] > n) owns[a[i]] = i, left++;
    }
    int mx = *max_element(a, a + n);
    for (int i = n + 1; i <= mx; i++) {
        if (owns[i] != -1) left--;
        else ans = ans * left % mod;
    }
    return ans;
}

Compilation message

gondola.cpp: In function 'int valid(int, int*)':
gondola.cpp:15:22: warning: comparison of integer expressions of different signedness: 'std::set<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   15 |     return st.size() == n;
      |            ~~~~~~~~~~^~~~
gondola.cpp: In function 'int countReplacement(int, int*)':
gondola.cpp:63:19: warning: comparison of integer expressions of different signedness: 'std::set<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   63 |     if (st.size() != n) return 0;
      |         ~~~~~~~~~~^~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 9 ms 2140 KB Output is correct
7 Correct 5 ms 604 KB Output is correct
8 Correct 17 ms 3992 KB Output is correct
9 Correct 5 ms 1372 KB Output is correct
10 Correct 22 ms 4444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 9 ms 2252 KB Output is correct
7 Correct 5 ms 604 KB Output is correct
8 Correct 15 ms 3968 KB Output is correct
9 Correct 8 ms 1372 KB Output is correct
10 Correct 22 ms 4612 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 2 ms 348 KB Output is correct
14 Correct 0 ms 400 KB Output is correct
15 Correct 6 ms 696 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1116 KB Output is correct
2 Correct 1 ms 1116 KB Output is correct
3 Correct 1 ms 1116 KB Output is correct
4 Correct 1 ms 1116 KB Output is correct
5 Correct 1 ms 1116 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1112 KB Output is correct
2 Correct 1 ms 1116 KB Output is correct
3 Correct 0 ms 1116 KB Output is correct
4 Correct 0 ms 1116 KB Output is correct
5 Correct 1 ms 1112 KB Output is correct
6 Correct 0 ms 1116 KB Output is correct
7 Correct 1 ms 1116 KB Output is correct
8 Correct 1 ms 1116 KB Output is correct
9 Correct 1 ms 1116 KB Output is correct
10 Correct 1 ms 1116 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1116 KB Output is correct
2 Correct 1 ms 1116 KB Output is correct
3 Correct 1 ms 1116 KB Output is correct
4 Correct 0 ms 1116 KB Output is correct
5 Correct 0 ms 1192 KB Output is correct
6 Correct 0 ms 1116 KB Output is correct
7 Correct 1 ms 1116 KB Output is correct
8 Correct 1 ms 1116 KB Output is correct
9 Correct 1 ms 1116 KB Output is correct
10 Correct 1 ms 1116 KB Output is correct
11 Correct 6 ms 1628 KB Output is correct
12 Correct 7 ms 1812 KB Output is correct
13 Correct 7 ms 1628 KB Output is correct
14 Correct 6 ms 1628 KB Output is correct
15 Correct 15 ms 2324 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1372 KB Output is correct
2 Correct 1 ms 1628 KB Output is correct
3 Correct 1 ms 1372 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1372 KB Output is correct
2 Correct 1 ms 1628 KB Output is correct
3 Correct 1 ms 1372 KB Output is correct
4 Correct 1 ms 1628 KB Output is correct
5 Correct 1 ms 1628 KB Output is correct
6 Correct 1 ms 1628 KB Output is correct
7 Correct 1 ms 1372 KB Output is correct
8 Correct 1 ms 1628 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1628 KB Output is correct
2 Correct 1 ms 1628 KB Output is correct
3 Correct 1 ms 1372 KB Output is correct
4 Correct 1 ms 1372 KB Output is correct
5 Correct 1 ms 1628 KB Output is correct
6 Correct 1 ms 1628 KB Output is correct
7 Correct 1 ms 1372 KB Output is correct
8 Correct 1 ms 1624 KB Output is correct
9 Correct 30 ms 5204 KB Output is correct
10 Correct 24 ms 4688 KB Output is correct
11 Correct 9 ms 2652 KB Output is correct
12 Correct 11 ms 2908 KB Output is correct
13 Incorrect 4 ms 1884 KB Output isn't correct
14 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1628 KB Output is correct
2 Correct 1 ms 1628 KB Output is correct
3 Correct 1 ms 1372 KB Output is correct
4 Correct 1 ms 1372 KB Output is correct
5 Correct 1 ms 1372 KB Output is correct
6 Correct 1 ms 1628 KB Output is correct
7 Correct 1 ms 1372 KB Output is correct
8 Correct 1 ms 1372 KB Output is correct
9 Correct 31 ms 5208 KB Output is correct
10 Correct 24 ms 4700 KB Output is correct
11 Correct 8 ms 2652 KB Output is correct
12 Correct 11 ms 2904 KB Output is correct
13 Incorrect 3 ms 1884 KB Output isn't correct
14 Halted 0 ms 0 KB -