Submission #58775

#TimeUsernameProblemLanguageResultExecution timeMemory
58775muradeynGondola (IOI14_gondola)C++14
25 / 100
130 ms6816 KiB
#include "gondola.h"
#include <bits/stdc++.h>

int valid(int n, int inputSeq[])
{
    std::set<int>st;
    int ls = -1,in;
    for (int i = 0;i<n;i++) {
        st.insert(inputSeq[i]);
        if (inputSeq[i] <= n) {
            if (ls == -1) {
                in = i;
                ls = inputSeq[i];
                continue;
            }
            if (inputSeq[i] < ls) {
                if (inputSeq[i] != 1)return 0;
                else if (ls - inputSeq[i] != n - i + in)return 0;
            }
            else {
                if (inputSeq[i] - ls != i - in)return 0;
            }
            in = i;
            ls = inputSeq[i];
        }
    }
    if (st.size() != n)return 0;
    return 1;
}

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

int replacement(int n, int gondolaSeq[], int replacementSeq[])
{
    int in[n],le = 0,idx = -1 , sz = 0;
    std::vector< std::pair<int,int> >v;
    for (int i = 0;i<n;i++) in[i] = i + 1;
    for (int i = 0;i<n;i++) {
        if (gondolaSeq[i] <= n) {
            idx = i;
            in[i] = gondolaSeq[i];
        }
        else {
            v.push_back(std::make_pair(gondolaSeq[i],i));
            sz++;
        }
    }
    int l = idx - 1,r = idx + 1;
    while (l >= 0) {
        if (in[l + 1] == 1)in[l] = n;
        else in[l] = in[l + 1] - 1;
        l--;
    }
    while (r < n) {
        if (in[r - 1] == n)in[r] = 1;
        else in[r] = in[r - 1] + 1;
        r++;
    }
    for (int i = 0;i<sz;i++) {
        if (i == 0) {
            replacementSeq[le++] = in[v[i].second];
            int k = n + 1;
            while (k < v[i].first) {
                replacementSeq[le++] = k;
                k++;
            }
        }
        else {
            replacementSeq[le++] = in[v[i].second];
            int k = v[i - 1].first;
            while (k < v[i].first) {
                replacementSeq[le++] = k;
                k++;
            }
        }
    }
    return le;
}

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

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

Compilation message (stderr)

gondola.cpp: In function 'int valid(int, int*)':
gondola.cpp:27:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     if (st.size() != n)return 0;
         ~~~~~~~~~~^~~~
gondola.cpp:18:52: warning: 'in' may be used uninitialized in this function [-Wmaybe-uninitialized]
                 else if (ls - inputSeq[i] != n - i + in)return 0;
                                              ~~~~~~^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...