제출 #699788

#제출 시각아이디문제언어결과실행 시간메모리
699788grossly_overconfident버섯 세기 (IOI20_mushrooms)C++17
컴파일 에러
0 ms0 KiB
#include "mushrooms.h" int count_mushrooms(int n) { if (n < 220){ int a = 1; for (int i = 1; i < n; ++i){ a += 1 - use_machine({ 0, i }); } return a; } vector<int> a(1, 0); vector<int> b; if (use_machine({ 0, 1 }) == 1){ b.push_back(1); } else{ a.push_back(1); } if (use_machine({ 0, 2 }) == 1){ b.push_back(2); } else{ a.push_back(2); } for (int i = 3; i <= 150; i += 2){ if (a.size() > b.size()){ int h = use_machine({ i, a[0], i + 1, a[1]}); if (h % 2){ a.push_back(i); } else{ b.push_back(i); } if (h < 2){ a.push_back(i + 1); } else{ b.push_back(i + 1); } } else{ int h = use_machine({ i, b[0], i + 1, b[1]}); if (h % 2){ b.push_back(i); } else{ a.push_back(i); } if (h < 2){ b.push_back(i + 1); } else{ a.push_back(i + 1); } } } int i = 151; int tally = a.size(); while (true){ if (a.size() < b.size()){ vector<int> p; int w = i; for (int j = 0; j < b.size(); ++j){ p.push_back(i); p.push_back(b[j]); i++; if (i == n){ break; } } h = use_machine(p); if (h % 2 == 0){ b.push_back(w); tally += h / 2; } else{ a.push_back(w); tally++; tally += (h - 1) / 2; } if (i == n){ return tally; } } else{ vector<int> p; int w = i; for (int j = 0; j < a.size(); ++j){ p.push_back(i); p.push_back(a[j]); i++; if (i == n){ break; } } h = use_machine(p); if (h % 2 == 0){ a.push_back(w); tally++; tally += (i - w) - (h / 2); } else{ b.push_back(w); tally += (i - w) - ((h - 1) / 2); } if (i == n){ return tally; } } if (i == n){ return tally; } } }

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

mushrooms.cpp: In function 'int count_mushrooms(int)':
mushrooms.cpp:11:2: error: 'vector' was not declared in this scope
   11 |  vector<int> a(1, 0);
      |  ^~~~~~
mushrooms.cpp:11:2: note: suggested alternatives:
In file included from /usr/include/c++/10/vector:67,
                 from mushrooms.h:1,
                 from mushrooms.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 mushrooms.h:1,
                 from mushrooms.cpp:1:
/usr/include/c++/10/vector:86:13: note:   'std::pmr::vector'
   86 |       using vector = std::vector<_Tp, polymorphic_allocator<_Tp>>;
      |             ^~~~~~
mushrooms.cpp:11:9: error: expected primary-expression before 'int'
   11 |  vector<int> a(1, 0);
      |         ^~~
mushrooms.cpp:12:9: error: expected primary-expression before 'int'
   12 |  vector<int> b;
      |         ^~~
mushrooms.cpp:14:3: error: 'b' was not declared in this scope
   14 |   b.push_back(1);
      |   ^
mushrooms.cpp:17:3: error: 'a' was not declared in this scope
   17 |   a.push_back(1);
      |   ^
mushrooms.cpp:20:3: error: 'b' was not declared in this scope
   20 |   b.push_back(2);
      |   ^
mushrooms.cpp:23:3: error: 'a' was not declared in this scope
   23 |   a.push_back(2);
      |   ^
mushrooms.cpp:26:7: error: 'a' was not declared in this scope
   26 |   if (a.size() > b.size()){
      |       ^
mushrooms.cpp:26:18: error: 'b' was not declared in this scope
   26 |   if (a.size() > b.size()){
      |                  ^
mushrooms.cpp:27:47: error: could not convert '{i, <expression error>, (i + 1), <expression error>}' from '<brace-enclosed initializer list>' to 'std::vector<int>'
   27 |    int h = use_machine({ i, a[0], i + 1, a[1]});
      |                                               ^
      |                                               |
      |                                               <brace-enclosed initializer list>
mushrooms.cpp:42:47: error: could not convert '{i, <expression error>, (i + 1), <expression error>}' from '<brace-enclosed initializer list>' to 'std::vector<int>'
   42 |    int h = use_machine({ i, b[0], i + 1, b[1]});
      |                                               ^
      |                                               |
      |                                               <brace-enclosed initializer list>
mushrooms.cpp:58:14: error: 'a' was not declared in this scope
   58 |  int tally = a.size();
      |              ^
mushrooms.cpp:60:18: error: 'b' was not declared in this scope
   60 |   if (a.size() < b.size()){
      |                  ^
mushrooms.cpp:61:11: error: expected primary-expression before 'int'
   61 |    vector<int> p;
      |           ^~~
mushrooms.cpp:64:5: error: 'p' was not declared in this scope
   64 |     p.push_back(i);
      |     ^
mushrooms.cpp:71:4: error: 'h' was not declared in this scope
   71 |    h = use_machine(p);
      |    ^
mushrooms.cpp:71:20: error: 'p' was not declared in this scope
   71 |    h = use_machine(p);
      |                    ^
mushrooms.cpp:87:11: error: expected primary-expression before 'int'
   87 |    vector<int> p;
      |           ^~~
mushrooms.cpp:90:5: error: 'p' was not declared in this scope
   90 |     p.push_back(i);
      |     ^
mushrooms.cpp:97:4: error: 'h' was not declared in this scope
   97 |    h = use_machine(p);
      |    ^
mushrooms.cpp:97:20: error: 'p' was not declared in this scope
   97 |    h = use_machine(p);
      |                    ^