답안 #53449

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
53449 2018-06-30T04:43:29 Z 시제연(#2016) Garage (IOI09_garage) C++11
100 / 100
3 ms 756 KB
#include <bits/stdc++.h>
using namespace std;

const int N = 100, M = 2000;

int n, m, a[N], c[N], w[M], p[M], r;
queue<int> q;

int main(){
    scanf("%d%d", &n, &m);
    for(int i = 0; i < n; i++) scanf("%d", a + i);
    for(int i = 0; i < m; i++) scanf("%d", w + i);
    for(m *= 2; m--; ){
        int x;
        scanf("%d", &x);
        if(x < 0){
            x *= -1; x--;
            c[p[x]] = 0;
            if(!q.empty()){
                c[p[x]] = 1;
                p[q.front()] = p[x];
                r += a[p[x]] * w[q.front()];
                q.pop();
            }
        }
        else{
            x--;
            int s = 0;
            for(int i = 0; i < n; i++){
                if(!c[i]){
                    c[i] = 1;
                    p[x] = i;
                    r += a[i] * w[x];
                    s = 1;
                    break;
                }
            }
            if(!s) q.push(x);
        }
    }
    printf("%d\n", r);
}

Compilation message

garage.cpp: In function 'int main()':
garage.cpp:10: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:11:37: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     for(int i = 0; i < n; i++) scanf("%d", a + i);
                                ~~~~~^~~~~~~~~~~~~
garage.cpp:12:37: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     for(int i = 0; i < m; i++) scanf("%d", w + i);
                                ~~~~~^~~~~~~~~~~~~
garage.cpp:15: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 2 ms 248 KB Output is correct
2 Correct 2 ms 356 KB Output is correct
3 Correct 2 ms 408 KB Output is correct
4 Correct 2 ms 412 KB Output is correct
5 Correct 2 ms 460 KB Output is correct
6 Correct 2 ms 468 KB Output is correct
7 Correct 2 ms 544 KB Output is correct
8 Correct 2 ms 544 KB Output is correct
9 Correct 2 ms 544 KB Output is correct
10 Correct 2 ms 544 KB Output is correct
11 Correct 2 ms 620 KB Output is correct
12 Correct 2 ms 620 KB Output is correct
13 Correct 2 ms 620 KB Output is correct
14 Correct 2 ms 636 KB Output is correct
15 Correct 2 ms 636 KB Output is correct
16 Correct 3 ms 636 KB Output is correct
17 Correct 3 ms 756 KB Output is correct
18 Correct 3 ms 756 KB Output is correct
19 Correct 3 ms 756 KB Output is correct
20 Correct 3 ms 756 KB Output is correct