Submission #1248906

#TimeUsernameProblemLanguageResultExecution timeMemory
1248906feukicGarage (IOI09_garage)C++17
Compilation error
0 ms0 KiB
using namespace std; int findSpace(vector<int>& arr) { for (int i = 0; i < arr.size(); i++) { if (!arr[i]) { return i; } } return -1; } int findSpace(vector<int>& arr, int x) { for (int i = 0; i < arr.size(); i++) { if (arr[i] == x) { return i; } } return -1; } int main() { int n, m; cin >> n >> m; vector<int> prices(n); for (int i = 0; i < n; i++) { cin >> prices[i]; } vector<int> weights(m); for (int i = 0; i < m; i++) { cin >> weights[i]; } long long sum = 0; vector<int> spaces(n, 0); queue<int> cars; for (int i = 0; i < 2 * m; i++) { int x; cin >> x; if (x > 0) { int space = findSpace(spaces); if (space != -1) { spaces[space] = x; sum += prices[space] * weights[x - 1]; } else { cars.push(x); } } else { if (cars.size()) { int space = findSpace(spaces, -x); spaces[space] = cars.front(); sum += prices[space] * weights[-x - 1]; cars.pop(); } else { int space = findSpace(spaces, -x); spaces[space] = 0; } } } cout << sum; }

Compilation message (stderr)

garage.cpp:3:15: error: 'vector' was not declared in this scope
    3 | int findSpace(vector<int>& arr) {
      |               ^~~~~~
garage.cpp:1:1: note: 'std::vector' is defined in header '<vector>'; did you forget to '#include <vector>'?
  +++ |+#include <vector>
    1 | using namespace std;
garage.cpp:3:22: error: expected primary-expression before 'int'
    3 | int findSpace(vector<int>& arr) {
      |                      ^~~
garage.cpp:11:5: error: redefinition of 'int findSpace'
   11 | int findSpace(vector<int>& arr, int x) {
      |     ^~~~~~~~~
garage.cpp:3:5: note: 'int findSpace' previously defined here
    3 | int findSpace(vector<int>& arr) {
      |     ^~~~~~~~~
garage.cpp:11:15: error: 'vector' was not declared in this scope
   11 | int findSpace(vector<int>& arr, int x) {
      |               ^~~~~~
garage.cpp:11:15: note: 'std::vector' is defined in header '<vector>'; did you forget to '#include <vector>'?
garage.cpp:11:22: error: expected primary-expression before 'int'
   11 | int findSpace(vector<int>& arr, int x) {
      |                      ^~~
garage.cpp:11:33: error: expected primary-expression before 'int'
   11 | int findSpace(vector<int>& arr, int x) {
      |                                 ^~~
garage.cpp: In function 'int main()':
garage.cpp:21:5: error: 'cin' was not declared in this scope
   21 |     cin >> n >> m;
      |     ^~~
garage.cpp:1:1: note: 'std::cin' is defined in header '<iostream>'; did you forget to '#include <iostream>'?
  +++ |+#include <iostream>
    1 | using namespace std;
garage.cpp:23:5: error: 'vector' was not declared in this scope
   23 |     vector<int> prices(n);
      |     ^~~~~~
garage.cpp:23:5: note: 'std::vector' is defined in header '<vector>'; did you forget to '#include <vector>'?
garage.cpp:23:12: error: expected primary-expression before 'int'
   23 |     vector<int> prices(n);
      |            ^~~
garage.cpp:25:16: error: 'prices' was not declared in this scope
   25 |         cin >> prices[i];
      |                ^~~~~~
garage.cpp:28:12: error: expected primary-expression before 'int'
   28 |     vector<int> weights(m);
      |            ^~~
garage.cpp:30:16: error: 'weights' was not declared in this scope
   30 |         cin >> weights[i];
      |                ^~~~~~~
garage.cpp:34:12: error: expected primary-expression before 'int'
   34 |     vector<int> spaces(n, 0);
      |            ^~~
garage.cpp:35:5: error: 'queue' was not declared in this scope
   35 |     queue<int> cars;
      |     ^~~~~
garage.cpp:1:1: note: 'std::queue' is defined in header '<queue>'; did you forget to '#include <queue>'?
  +++ |+#include <queue>
    1 | using namespace std;
garage.cpp:35:11: error: expected primary-expression before 'int'
   35 |     queue<int> cars;
      |           ^~~
garage.cpp:42:35: error: 'spaces' was not declared in this scope; did you mean 'space'?
   42 |             int space = findSpace(spaces);
      |                                   ^~~~~~
      |                                   space
garage.cpp:42:41: error: 'findSpace' cannot be used as a function
   42 |             int space = findSpace(spaces);
      |                                         ^
garage.cpp:46:24: error: 'prices' was not declared in this scope
   46 |                 sum += prices[space] * weights[x - 1];
      |                        ^~~~~~
garage.cpp:46:40: error: 'weights' was not declared in this scope
   46 |                 sum += prices[space] * weights[x - 1];
      |                                        ^~~~~~~
garage.cpp:48:17: error: 'cars' was not declared in this scope
   48 |                 cars.push(x);
      |                 ^~~~
garage.cpp:51:17: error: 'cars' was not declared in this scope
   51 |             if (cars.size()) {
      |                 ^~~~
garage.cpp:52:39: error: 'spaces' was not declared in this scope; did you mean 'space'?
   52 |                 int space = findSpace(spaces, -x);
      |                                       ^~~~~~
      |                                       space
garage.cpp:52:38: error: 'findSpace' cannot be used as a function
   52 |                 int space = findSpace(spaces, -x);
      |                             ~~~~~~~~~^~~~~~~~~~~~
garage.cpp:54:24: error: 'prices' was not declared in this scope
   54 |                 sum += prices[space] * weights[-x - 1];
      |                        ^~~~~~
garage.cpp:54:40: error: 'weights' was not declared in this scope
   54 |                 sum += prices[space] * weights[-x - 1];
      |                                        ^~~~~~~
garage.cpp:57:39: error: 'spaces' was not declared in this scope; did you mean 'space'?
   57 |                 int space = findSpace(spaces, -x);
      |                                       ^~~~~~
      |                                       space
garage.cpp:57:38: error: 'findSpace' cannot be used as a function
   57 |                 int space = findSpace(spaces, -x);
      |                             ~~~~~~~~~^~~~~~~~~~~~
garage.cpp:63:5: error: 'cout' was not declared in this scope
   63 |     cout << sum;
      |     ^~~~
garage.cpp:63:5: note: 'std::cout' is defined in header '<iostream>'; did you forget to '#include <iostream>'?