답안 #212276

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
212276 2020-03-22T16:25:20 Z jk89 Garage (IOI09_garage) C++14
100 / 100
7 ms 512 KB
#include <cstdio>
#include <vector>
#include <algorithm>
#include <set>
#include <queue>

using namespace std;

#define f first
#define s second

const int MAXN = 1e2 + 3;
const int MAXM = 2e3 + 3;

int c[MAXN];
int w[MAXM];
int msc[MAXM];
set<int> q;
queue<int> kol;

int main() {
    int n, m, x;
    int wyn = 0;
    scanf("%d %d", &n, &m);
    for (int i = 1; i <= n; i++) {
        scanf("%d", &c[i]);
        q.insert(i);
    }
    for (int i = 1; i <= m; i++)
        scanf("%d", &w[i]);
    for (int i = 1; i <= 2 * m; i++) {
        scanf("%d", &x);
        if (x > 0) {
            if (q.empty())
                kol.push(x);
            else {
                wyn += w[x] * c[*q.begin()];
                msc[x] = *q.begin();
                q.erase(q.begin());
            }
        }
        else {
            x = -x;
            q.insert(msc[x]);
            if (!kol.empty()) {
                q.erase(q.begin());
                wyn += w[kol.front()] * c[msc[x]];
                msc[kol.front()] = msc[x];
                kol.pop();
            }
        }
    }
    printf("%d", wyn);
    return 0;
}

Compilation message

garage.cpp: In function 'int main()':
garage.cpp:24:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d", &n, &m);
     ~~~~~^~~~~~~~~~~~~~~~~
garage.cpp:26:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", &c[i]);
         ~~~~~^~~~~~~~~~~~~
garage.cpp:30:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", &w[i]);
         ~~~~~^~~~~~~~~~~~~
garage.cpp:32:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", &x);
         ~~~~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 256 KB Output is correct
2 Correct 6 ms 512 KB Output is correct
3 Correct 5 ms 256 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
6 Correct 4 ms 384 KB Output is correct
7 Correct 5 ms 256 KB Output is correct
8 Correct 4 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 4 ms 256 KB Output is correct
11 Correct 4 ms 256 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 6 ms 384 KB Output is correct
17 Correct 6 ms 432 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
19 Correct 5 ms 384 KB Output is correct
20 Correct 7 ms 384 KB Output is correct