답안 #870140

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
870140 2023-11-07T03:39:59 Z inawah Garage (IOI09_garage) C++14
100 / 100
1 ms 600 KB
#include <cstdio>
#include <queue>
using namespace std;

#define MAXN 105
#define MAXM 2005
int r[MAXN], w[MAXM], p[MAXM];
queue<int> q;
bool vis[MAXN];

int main() {
    int N, M;
    scanf("%d %d\n", &N, &M);
    for (int i = 1; i <= N; ++i) {
        scanf("%d\n", &r[i]);
    }
    for (int i = 1; i <= M; ++i) {
        scanf("%d\n", &w[i]);
    }
    int ans = 0;
    for (int i = 1; i <= 2*M; ++i) {
        int a;
        scanf("%d\n", &a);
        if (a > 0) {
            int j;
            for (j = 1; j <= N && vis[j]; ++j);
            if (j <= N) {
                vis[j] = true;
                p[a] = j;
            } else {
                q.push(a);
            }
        } else {
            vis[p[-a]] = false;
            if (!q.empty()) {
                int f = q.front();
                p[f] = p[-a];
                vis[p[f]] = true;
                q.pop();
            }
            ans += w[-a]*r[p[-a]];
        }
    }
    printf("%d\n", ans);
    return 0;
}

Compilation message

garage.cpp: In function 'int main()':
garage.cpp:13:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   13 |     scanf("%d %d\n", &N, &M);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~
garage.cpp:15:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   15 |         scanf("%d\n", &r[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\n", &w[i]);
      |         ~~~~~^~~~~~~~~~~~~~~
garage.cpp:23:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   23 |         scanf("%d\n", &a);
      |         ~~~~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 436 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 428 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 600 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 440 KB Output is correct