Submission #311619

# Submission time Handle Problem Language Result Execution time Memory
311619 2020-10-10T19:23:27 Z ipaljak Garage (IOI09_garage) C++14
100 / 100
2 ms 384 KB
#include <bits/stdc++.h>

using namespace std;

const int MAXN = 105;
const int MAXM = 2010;

int n, m;
int r[MAXN], w[MAXM], park[MAXM];

set<int> sp;

int main(void) {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; ++i) scanf("%d", &r[i]);
  for (int i = 0; i < m; ++i) scanf("%d", &w[i]);

  for (int i = 0; i < n; ++i) sp.insert(i);

  queue<int> q;

  int sol = 0;
  for (int i = 0; i < 2 * m; ++i) {
    int x;
    scanf("%d", &x);
    if (x > 0) {
      --x;
      if (sp.empty()) {
        q.push(x);
        continue;
      }
      sol += r[*sp.begin()] * w[x];
      park[x] = *sp.begin();
      sp.erase(sp.begin());
    } else {
      x = abs(x); --x;
      sp.insert(park[x]);
      if (!q.empty()) {
        int x = q.front(); q.pop();
        sol += r[*sp.begin()] * w[x];
        park[x] = *sp.begin();
        sp.erase(sp.begin());
      }
    }
  }

  printf("%d\n", sol);
  return 0;
}

Compilation message

garage.cpp: In function 'int main()':
garage.cpp:14:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   14 |   scanf("%d%d", &n, &m);
      |   ~~~~~^~~~~~~~~~~~~~~~
garage.cpp:15:36: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   15 |   for (int i = 0; i < n; ++i) scanf("%d", &r[i]);
      |                               ~~~~~^~~~~~~~~~~~~
garage.cpp:16:36: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   16 |   for (int i = 0; i < m; ++i) scanf("%d", &w[i]);
      |                               ~~~~~^~~~~~~~~~~~~
garage.cpp:25:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   25 |     scanf("%d", &x);
      |     ~~~~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 256 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 2 ms 384 KB Output is correct
18 Correct 2 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 2 ms 384 KB Output is correct