답안 #598043

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
598043 2022-07-17T12:49:51 Z jhnah917 Art Collections (BOI22_art) C++17
컴파일 오류
0 ms 0 KB
#include "art.h"
#include <bits/stdc++.h>

bool compare(vector<int> &ord, int a, int b){
    if(a == b) return false;
    int pa = find(ord.begin(), ord.end(), a) - ord.begin();
    int pb = find(ord.begin(), ord.end(), b) - ord.begin();
    int t1 = publish(ord);
    swap(ord[pa], ord[pb]);
    int t2 = publish(ord);
    swap(ord[pa], ord[pb]);
    return t1 < t2;
}

void merge_sort(vector<int> &ord, int s, int e){
    if(s >= e) return;
    int m = (s + e) / 2;
    merge_sort(ord, s, m);
    merge_sort(ord, m+1, e);

    vector<int> tmp(ord.size());
    int i = s, j = m+1, k = s;
    while(i <= m && j <= e){
        if(compare(ord, ord[i], ord[j])) tmp[k++] = ord[i++];
        else tmp[k++] = ord[j++];
    }
    while(i <= m) tmp[k++] = ord[i++];
    while(j <= e) tmp[k++] = ord[j++];
    for(k=s; k<=e; k++) ord[k] = tmp[k];
}

void solve(int n){
    vector<int> ord(n);
    iota(ord.begin(), ord.end(), 1);
    merge_sort(ord, 0, n-1);
    answer(ord);
}

Compilation message

art.cpp:4:14: error: 'vector' was not declared in this scope
    4 | bool compare(vector<int> &ord, int a, int b){
      |              ^~~~~~
art.cpp:4:14: note: suggested alternatives:
In file included from /usr/include/c++/10/vector:67,
                 from art.h:1,
                 from art.cpp:1:
/usr/include/c++/10/bits/stl_vector.h:389:11: note:   'std::vector'
  389 |     class vector : protected _Vector_base<_Tp, _Alloc>
      |           ^~~~~~
In file included from art.h:1,
                 from art.cpp:1:
/usr/include/c++/10/vector:86:13: note:   'std::pmr::vector'
   86 |       using vector = std::vector<_Tp, polymorphic_allocator<_Tp>>;
      |             ^~~~~~
art.cpp:4:21: error: expected primary-expression before 'int'
    4 | bool compare(vector<int> &ord, int a, int b){
      |                     ^~~
art.cpp:4:32: error: expected primary-expression before 'int'
    4 | bool compare(vector<int> &ord, int a, int b){
      |                                ^~~
art.cpp:4:39: error: expected primary-expression before 'int'
    4 | bool compare(vector<int> &ord, int a, int b){
      |                                       ^~~
art.cpp:4:44: error: expression list treated as compound expression in initializer [-fpermissive]
    4 | bool compare(vector<int> &ord, int a, int b){
      |                                            ^
art.cpp:15:6: error: variable or field 'merge_sort' declared void
   15 | void merge_sort(vector<int> &ord, int s, int e){
      |      ^~~~~~~~~~
art.cpp:15:17: error: 'vector' was not declared in this scope
   15 | void merge_sort(vector<int> &ord, int s, int e){
      |                 ^~~~~~
art.cpp:15:17: note: suggested alternatives:
In file included from /usr/include/c++/10/vector:67,
                 from art.h:1,
                 from art.cpp:1:
/usr/include/c++/10/bits/stl_vector.h:389:11: note:   'std::vector'
  389 |     class vector : protected _Vector_base<_Tp, _Alloc>
      |           ^~~~~~
In file included from art.h:1,
                 from art.cpp:1:
/usr/include/c++/10/vector:86:13: note:   'std::pmr::vector'
   86 |       using vector = std::vector<_Tp, polymorphic_allocator<_Tp>>;
      |             ^~~~~~
art.cpp:15:24: error: expected primary-expression before 'int'
   15 | void merge_sort(vector<int> &ord, int s, int e){
      |                        ^~~
art.cpp:15:35: error: expected primary-expression before 'int'
   15 | void merge_sort(vector<int> &ord, int s, int e){
      |                                   ^~~
art.cpp:15:42: error: expected primary-expression before 'int'
   15 | void merge_sort(vector<int> &ord, int s, int e){
      |                                          ^~~
art.cpp: In function 'void solve(int)':
art.cpp:33:5: error: 'vector' was not declared in this scope
   33 |     vector<int> ord(n);
      |     ^~~~~~
art.cpp:33:5: note: suggested alternatives:
In file included from /usr/include/c++/10/vector:67,
                 from art.h:1,
                 from art.cpp:1:
/usr/include/c++/10/bits/stl_vector.h:389:11: note:   'std::vector'
  389 |     class vector : protected _Vector_base<_Tp, _Alloc>
      |           ^~~~~~
In file included from art.h:1,
                 from art.cpp:1:
/usr/include/c++/10/vector:86:13: note:   'std::pmr::vector'
   86 |       using vector = std::vector<_Tp, polymorphic_allocator<_Tp>>;
      |             ^~~~~~
art.cpp:33:12: error: expected primary-expression before 'int'
   33 |     vector<int> ord(n);
      |            ^~~
art.cpp:34:10: error: 'ord' was not declared in this scope
   34 |     iota(ord.begin(), ord.end(), 1);
      |          ^~~
art.cpp:34:5: error: 'iota' was not declared in this scope; did you mean 'std::iota'?
   34 |     iota(ord.begin(), ord.end(), 1);
      |     ^~~~
      |     std::iota
In file included from /usr/include/c++/10/numeric:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:84,
                 from art.cpp:2:
/usr/include/c++/10/bits/stl_numeric.h:88:5: note: 'std::iota' declared here
   88 |     iota(_ForwardIterator __first, _ForwardIterator __last, _Tp __value)
      |     ^~~~
art.cpp:35:5: error: 'merge_sort' was not declared in this scope
   35 |     merge_sort(ord, 0, n-1);
      |     ^~~~~~~~~~
interface.cpp: In function 'int publish(std::vector<int>)':
interface.cpp:20:17: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   20 |     if(v.size() != N) {
      |        ~~~~~~~~~^~~~
interface.cpp: In function 'void answer(std::vector<int>)':
interface.cpp:36:17: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   36 |     if(v.size() != N) {
      |        ~~~~~~~~~^~~~