제출 #717662

#제출 시각아이디문제언어결과실행 시간메모리
717662EntityPlanttGarage (IOI09_garage)C++14
100 / 100
1 ms340 KiB
#include <cstdio> #include <cstring> #include <queue> int main() { int r = 0, m, n, i, x, j; scanf("%d%d", &n, &m); int rate[n + 5], weight[m + 5], parked[n + 5], where[m + 5], spacesLeft = n; memset(parked, 0, sizeof(parked)); memset(where, 0, sizeof(where)); for (i = 0; i < n; i++) { scanf("%d", rate + i); } for (i = 1; i <= m; i++) { scanf("%d", weight + i); } std::queue <int> wait; for (i = 0; i < 2 * m; i++) { scanf("%d", &x); if (x > 0) { // Arrival if (spacesLeft) { for (j = 0; j < n; j++) { if (!parked[j]) { // Found parking place parked[j] = x; spacesLeft--; r += rate[j] * weight[x]; // printf("Added %d to sum\n", rate[j] * weight[x]); where[x] = j; break; } } } else { // Add to the queue // printf("Added %d to queue\n", x); wait.push(x); } } else { // Departure x *= -1; j = where[x]; parked[j] = 0; spacesLeft++; if (!wait.empty()) { // Park a car from the queue parked[j] = wait.front(); where[wait.front()] = j; r += rate[j] * weight[wait.front()]; // printf("Added %d to sum\n", rate[j] * weight[wait.front()]); spacesLeft--; wait.pop(); } } } printf("%d", r); return 0; }

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

garage.cpp: In function 'int main()':
garage.cpp:6:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    6 |     scanf("%d%d", &n, &m);
      |     ~~~~~^~~~~~~~~~~~~~~~
garage.cpp:11:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   11 |         scanf("%d", rate + i);
      |         ~~~~~^~~~~~~~~~~~~~~~
garage.cpp:14:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   14 |         scanf("%d", weight + i);
      |         ~~~~~^~~~~~~~~~~~~~~~~~
garage.cpp:18:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   18 |         scanf("%d", &x);
      |         ~~~~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...