Submission #759713

# Submission time Handle Problem Language Result Execution time Memory
759713 2023-06-16T15:45:36 Z raysh07 Gondola (IOI14_gondola) C++17
55 / 100
24 ms 5148 KB
#include "gondola.h"
#include <bits/stdc++.h>
using namespace std;

int valid(int n, int a[])
{
    set <int> st;
    for (int i = 0; i < n; i++) st.insert(a[i]);
    
    if (st.size() != n) return 0;
    
    vector <int> b;
    for (int i = 0; i < n; i++){
        if (a[i] <= n) b.push_back(a[i]);
    }
    
    for (int i = 1; i < b.size(); i++){
        int need = b[i - 1] + 1;
        if (need > n) need = 1;
        
        if (b[i] != need) return 0;
    }
    
    return 1;
}

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

int replacement(int n, int a[], int b[])
{
    int mx = 0;
    for (int i = 0; i < n; i++) mx = max(mx, a[i]);
    
    int mn = 1e6;
    int c[n];
    for (int i = 0; i < n; i++) mn = min(mn, a[i]);
    
    if (mn > n){
        for (int i = 0; i < n; i++) c[i] = i + 1;
    } else {
        int p = -1;
        for (int i = 0; i < n; i++){
            if (a[i] <= n) p = i;
        }
        
        c[p] = a[p];
        for (int i = p + 1; i < n; i++){
            c[i] = c[i - 1] + 1;
            if (c[i] > n) c[i] = 1;
        }
        
        if (p != 0){
            c[0] = c[n - 1] + 1;
            if (c[0] > n) c[0] = 1;
            
            for (int i = 1; i < p; i++){
                c[i] = c[i - 1] + 1;
                if (c[i] > n) c[i] = 1;
            }
        }
    }
    
    int l = 0;
    set <pair<int, int>> st;
    for (int i = 0; i < n; i++){
        if (c[i] != a[i]){
            st.insert(make_pair(a[i], i));
        }
    }
    
    int repl = n + 1;
    while (st.size()){
        auto u = *st.begin();
        b[l++] = c[u.second];
        c[u.second] = repl++;
        if (c[u.second] == a[u.second]) st.erase(u);
    }
    
    return l;
}

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

int countReplacement(int n, int inputSeq[])
{
    return -3;
}

Compilation message

gondola.cpp: In function 'int valid(int, int*)':
gondola.cpp:10:19: warning: comparison of integer expressions of different signedness: 'std::set<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   10 |     if (st.size() != n) return 0;
      |         ~~~~~~~~~~^~~~
gondola.cpp:17:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   17 |     for (int i = 1; i < b.size(); i++){
      |                     ~~^~~~~~~~~~
# 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 8 ms 2564 KB Output is correct
7 Correct 19 ms 3564 KB Output is correct
8 Correct 14 ms 4560 KB Output is correct
9 Correct 5 ms 1620 KB Output is correct
10 Correct 23 ms 5148 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 9 ms 2516 KB Output is correct
7 Correct 19 ms 3668 KB Output is correct
8 Correct 14 ms 4480 KB Output is correct
9 Correct 5 ms 1620 KB Output is correct
10 Correct 18 ms 5104 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 9 ms 2004 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 24 ms 5032 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 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 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 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 308 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 308 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 1 ms 304 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 280 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 304 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 6 ms 1264 KB Output is correct
12 Correct 7 ms 1508 KB Output is correct
13 Correct 20 ms 2836 KB Output is correct
14 Correct 6 ms 1364 KB Output is correct
15 Correct 18 ms 3060 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Integer -3 violates the range [0, 1000000008]
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Integer -3 violates the range [0, 1000000008]
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Integer -3 violates the range [0, 1000000008]
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Integer -3 violates the range [0, 1000000008]
2 Halted 0 ms 0 KB -