답안 #717662

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
717662 2023-04-02T10:28:46 Z EntityPlantt Garage (IOI09_garage) C++14
100 / 100
1 ms 340 KB
#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;
}

Compilation message

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);
      |         ~~~~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 292 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 288 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 292 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct