제출 #1261936

#제출 시각아이디문제언어결과실행 시간메모리
1261936sokratisi동굴 (IOI13_cave)C++20
컴파일 에러
0 ms0 KiB
#include "cave.h" #include <bits/stdc++.h> using namespace std; set<int> use; int n; array<int> s, d; pair<int, int> bsearch(int i) { vector<int> t; for (auto u: use) t.push_back(u); int cntrl = tryCombination(s); if (cntrl == -1) cntrl = n+2; int l = 0, r = t.size()-1; while(l < r) { int m = (l + r) / 2; int ts[n]; for (int i = 0; i < n; i++) ts[i] = s[i]; for (int i = l; i <= m; i++) { ts[t[i]] = 1-ts[t[i]]; } int ans = tryCombination(ts); if (ans == -1) ans = n + 2; if (cntrl == i && ans > i) r = m; else if (cntrl > i && ans == i) r = m; else l = m + 1; } int corpos; if (cntrl > i) corpos = s[t[l]]; else corpos = 1 - s[t[l]]; return {t[l], corpos}; } void exploreCave(int x) { n = x; s.resize(n); d.resize(n); s.fill(0); for (int i = 0; i < n; i++) use.insert(i); for (int i = 0; i < n; i++) { pair<int, int> ans = bsearch(i, s); use.erase(ans.first); s[ans.first] = ans.second; d[ans.first] = i; } answer(s, d); }

컴파일 시 표준 에러 (stderr) 메시지

cave.cpp:8:10: error: wrong number of template arguments (1, should be 2)
    8 | array<int> s, d;
      |          ^
In file included from /usr/include/c++/11/tuple:39,
                 from /usr/include/c++/11/functional:54,
                 from /usr/include/c++/11/pstl/glue_algorithm_defs.h:13,
                 from /usr/include/c++/11/algorithm:74,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:65,
                 from cave.cpp:2:
/usr/include/c++/11/array:95:12: note: provided for 'template<class _Tp, long unsigned int _Nm> struct std::array'
   95 |     struct array
      |            ^~~~~
cave.cpp: In function 'std::pair<int, int> bsearch(int)':
cave.cpp:14:32: error: invalid conversion from 'int' to 'int*' [-fpermissive]
   14 |     int cntrl = tryCombination(s);
      |                                ^
      |                                |
      |                                int
In file included from cave.cpp:1:
cave.h:8:24: note:   initializing argument 1 of 'int tryCombination(int*)'
    8 | int tryCombination(int S[]);
      |                    ~~~~^~~
cave.cpp:21:46: error: invalid types 'int[int]' for array subscript
   21 |         for (int i = 0; i < n; i++) ts[i] = s[i];
      |                                              ^
cave.cpp:32:30: error: invalid types 'int[__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type {aka int}]' for array subscript
   32 |     if (cntrl > i) corpos = s[t[l]];
      |                              ^
cave.cpp:33:24: error: invalid types 'int[__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type {aka int}]' for array subscript
   33 |     else corpos = 1 - s[t[l]];
      |                        ^
cave.cpp: In function 'void exploreCave(int)':
cave.cpp:39:7: error: request for member 'resize' in 's', which is of non-class type 'int'
   39 |     s.resize(n); d.resize(n);
      |       ^~~~~~
cave.cpp:39:20: error: request for member 'resize' in 'd', which is of non-class type 'int'
   39 |     s.resize(n); d.resize(n);
      |                    ^~~~~~
cave.cpp:40:7: error: request for member 'fill' in 's', which is of non-class type 'int'
   40 |     s.fill(0);
      |       ^~~~
cave.cpp:43:37: error: no matching function for call to 'bsearch(int&, int&)'
   43 |         pair<int, int> ans = bsearch(i, s);
      |                              ~~~~~~~^~~~~~
In file included from /usr/include/stdlib.h:833,
                 from /usr/include/c++/11/bits/std_abs.h:38,
                 from /usr/include/c++/11/cmath:47,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:41,
                 from cave.cpp:2:
/usr/include/x86_64-linux-gnu/bits/stdlib-bsearch.h:20:1: note: candidate: 'void* bsearch(const void*, const void*, size_t, size_t, __compar_fn_t)'
   20 | bsearch (const void *__key, const void *__base, size_t __nmemb, size_t __size,
      | ^~~~~~~
/usr/include/x86_64-linux-gnu/bits/stdlib-bsearch.h:20:1: note:   candidate expects 5 arguments, 2 provided
cave.cpp:10:16: note: candidate: 'std::pair<int, int> bsearch(int)'
   10 | pair<int, int> bsearch(int i) {
      |                ^~~~~~~
cave.cpp:10:16: note:   candidate expects 1 argument, 2 provided
cave.cpp:45:10: error: invalid types 'int[int]' for array subscript
   45 |         s[ans.first] = ans.second;
      |          ^
cave.cpp:46:10: error: invalid types 'int[int]' for array subscript
   46 |         d[ans.first] = i;
      |          ^
cave.cpp:48:12: error: invalid conversion from 'int' to 'int*' [-fpermissive]
   48 |     answer(s, d);
      |            ^
      |            |
      |            int
In file included from cave.cpp:1:
cave.h:9:17: note:   initializing argument 1 of 'void answer(int*, int*)'
    9 | void answer(int S[], int D[]);
      |             ~~~~^~~
cave.cpp:48:15: error: invalid conversion from 'int' to 'int*' [-fpermissive]
   48 |     answer(s, d);
      |               ^
      |               |
      |               int
In file included from cave.cpp:1:
cave.h:9:26: note:   initializing argument 2 of 'void answer(int*, int*)'
    9 | void answer(int S[], int D[]);
      |                      ~~~~^~~