Submission #1001910

# Submission time Handle Problem Language Result Execution time Memory
1001910 2024-06-19T08:29:48 Z codexistent Gondola (IOI14_gondola) C++14
Compilation error
0 ms 0 KB
#include <iostream>
#include <set>
#include <gondola.h>
using namespace std;
#define FOR(i, a, b) for(int i = a; i <= b; i++)
 
int diff(int n, int a, int b){
    if(b >= a) return b - a;
    else return (n - a) + b;
}
 
int valid(int n, int inputSeq[]){
    pair<int, int> prev = make_pair(-1, 0);
    set<int> s;
    FOR(i, 0, n - 1){
        if(inputSeq[i] <= n){
            if(prev.first == -1){
                prev = make_pair(i, inputSeq[i]);
            }else{
                if((((prev.second + diff(n, prev.first, i)) % n) == 0 ? n : ((prev.second + diff(n, prev.first, i)) % n)) != inputSeq[i]) return 0;
                prev = make_pair(i, inputSeq[i]);
            }
        }else{
            if(s.find(inputSeq[i]) != s.end()) return 0;
            s.insert(inputSeq[i]);
        }
    }
 
    return 1;
}
 
int replacement(int n, int gondolaSeq[], int replacementSeq[]){
    int idx = -1, mx = -1;
    vector<pair<int, int>> v;
    FOR(i, 0, n - 1){
        if(gondolaSeq[i] <= n){
            idx = gondolaSeq[i] - i;
            if(idx <= 0) idx += n;
        }else{
            v.push_back(make_pair(gondolaSeq[i], i));
        }
        mx = max(mx, gondolaSeq[i]);
    }
    sort(v.begin(), v.end());

    if(idx == -1) idx = 1;
    FOR(i, 0, v.size() - 1) replacementSeq[i] = idx + v[i].second;
    FOR(i, v.size(), mx - n) replacementSeq[i] = replacementSeq[i - 1];
    return mx - n;
}
 
int countReplacement(int n, int inputSeq[]){
    return 1;
}

Compilation message

gondola.cpp: In function 'int replacement(int, int*, int*)':
gondola.cpp:34:5: error: 'vector' was not declared in this scope
   34 |     vector<pair<int, int>> v;
      |     ^~~~~~
gondola.cpp:4:1: note: 'std::vector' is defined in header '<vector>'; did you forget to '#include <vector>'?
    3 | #include <gondola.h>
  +++ |+#include <vector>
    4 | using namespace std;
gondola.cpp:34:25: error: expected primary-expression before '>' token
   34 |     vector<pair<int, int>> v;
      |                         ^~
gondola.cpp:34:28: error: 'v' was not declared in this scope
   34 |     vector<pair<int, int>> v;
      |                            ^
gondola.cpp:44:5: error: 'sort' was not declared in this scope; did you mean 'qsort'?
   44 |     sort(v.begin(), v.end());
      |     ^~~~
      |     qsort