Submission #152323

# Submission time Handle Problem Language Result Execution time Memory
152323 2019-09-07T14:41:50 Z miello Garage (IOI09_garage) C++11
100 / 100
3 ms 380 KB
#include <bits/stdc++.h>
#define mkp make_pair
#define pb push_back
#define emb emplace_back
#define em emplace
#define ii pair<int,int>
#define iii pair<int ,ii>
#define f first
#define s second
#define all(x) x.begin(),x.end()
#define allc(x) x.begin(),x.end(),cmp
#define optimizar_io ios_base::sync_with_stdio(false);cin.tie(NULL);

using namespace std;
const int INF = 0x3f3f3f3f;
const int MXN = 2005;

int cost[MXN] , w[MXN] , l[MXN];
bool chk[MXN];
queue<int> q;

int main(){
    int n , m;
    scanf("%d %d",&n,&m);
    for(int i = 1 ; i <= n ; i++){
        scanf("%d",&cost[i]);
    }
    for(int i = 1 ; i <= m ; i++){
        scanf("%d",&w[i]);
    }
    int ans = 0;
    for(int i = 0 ; i < 2 * m ; i++){
        int x;
        scanf("%d",&x);
        if(x < 0){
            x = abs(x);
            // printf("%d %d %d\n",x,cost[l[x]] , l[x]);
            ans += cost[l[x]] * w[x];
            chk[l[x]] = 0;
            if(q.size()){
                int u = q.front();
                chk[l[x]] = 1;
                l[u] = l[x];
                q.pop();
            }
        }else{
            bool non = 0;
            for(int j = 1 ; j <= n ; j++){
                if(!chk[j]){
                    non = 1;
                    chk[j] = 1;
                    l[x] = j;
                    break;
                }
            }
            if(!non){
                q.push(x);
            }
        }
    }
    printf("%d",ans);
}

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",&cost[i]);
         ~~~~~^~~~~~~~~~~~~~~
garage.cpp:29:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d",&w[i]);
         ~~~~~^~~~~~~~~~~~
garage.cpp:34:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d",&x);
         ~~~~~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 256 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 380 KB Output is correct
14 Correct 2 ms 276 KB Output is correct
15 Correct 3 ms 376 KB Output is correct
16 Correct 3 ms 376 KB Output is correct
17 Correct 3 ms 376 KB Output is correct
18 Correct 3 ms 376 KB Output is correct
19 Correct 3 ms 376 KB Output is correct
20 Correct 3 ms 376 KB Output is correct