Submission #58772

# Submission time Handle Problem Language Result Execution time Memory
58772 2018-07-19T09:59:59 Z muradeyn Gondola (IOI14_gondola) C++14
Compilation error
0 ms 0 KB
#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;
    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];
            break;
        }
        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++;
    }
    cout<<sz<<endl;
    for (int i = 0;i<sz;i++) {
        std::cout<<i<<" "<<sz<<" "<<v[i].first<<" "<<v[i].second<<std::endl;
        if (i == 0) {
            int k = in[v[i].second];
            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++;
            }
        }
    }
    std::cout<<le<<std::endl;
    for (int i = 0;i<le;i++) std::cout<<replacementSeq[i]<<" ";
    return l;
}

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

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

Compilation message

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: In function 'int replacement(int, int*, int*)':
gondola.cpp:60:5: error: 'cout' was not declared in this scope
     cout<<sz<<endl;
     ^~~~
gondola.cpp:60:5: note: suggested alternative:
In file included from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:75:0,
                 from gondola.cpp:2:
/usr/include/c++/7/iostream:61:18: note:   'std::cout'
   extern ostream cout;  /// Linked to standard output
                  ^~~~
gondola.cpp:60:15: error: 'endl' was not declared in this scope
     cout<<sz<<endl;
               ^~~~
gondola.cpp:60:15: note: suggested alternative:
In file included from /usr/include/c++/7/istream:39:0,
                 from /usr/include/c++/7/sstream:38,
                 from /usr/include/c++/7/complex:45,
                 from /usr/include/c++/7/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:52,
                 from gondola.cpp:2:
/usr/include/c++/7/ostream:590:5: note:   'std::endl'
     endl(basic_ostream<_CharT, _Traits>& __os)
     ^~~~