답안 #1063904

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1063904 2024-08-18T05:55:05 Z kingjuno Garage (IOI09_garage) C++14
100 / 100
4 ms 548 KB
/*
        * king_juno
       * 2024-08-18  10:57:15
*/
#include <bits/stdc++.h>
using namespace std;

typedef long long int ll;
typedef long double ld;
typedef vector<ll> vl;
typedef map<ll,ll> mapi;

#define fast ios::sync_with_stdio(0);cin.tie(0);
#define fl(i, b) for (int i=0; i<(b); i++)
#define fr(i, a, b) for (int i=0; i<(b); i++)
#define el "\n"
#define sp " "
#define pb push_back
#define spre(x) fixed<<setprecision(x)
#define read(s) fl(i,s.size())cin>>s[i];
#define write(s) fl(i,s.size())cout<<s[i]<<sp;
#define sor(s) sort(s.begin(),s.end());
#define rsor(s) sort(s.rbegin(),s.rend());
#define inf INT_MAX
#define rev(a) reverse(a.begin(),a.end());
#define sumv(a) accumulate(a.begin(),a.end());
#define maxv(a) max_element(a.begin(),a.end());
#define minv(a) min_element(a.begin(),a.end());
#define cnt(a,x) count(a.begin(),a.end(),x);

bool sortsec(const pair<int,int> &a,const pair<int,int> &b)
{
    return (a.second < b.second);
}

int main(){
    ll n,m;
    cin>>n>>m;
    vl ratekg(n);
    read(ratekg);
    vl weight(m);
    read(weight);
    int ve;
    map<int, int> occ, where;
    queue<int> q;
    ll cash=0;
    fl(j, 2*m){
        cin>>ve;
        if(ve<0){
            // cout<<q.size()<<el;
            int pos = where[-ve];
            occ[pos]=0;
            if(q.size()){
                occ[pos]=1;
                int ve = q.front();
                q.pop();
                where[ve]=pos;
                cash+=ratekg[pos-1]*weight[ve-1];
            }
        }
        else{
            for(int i=1;i<=n;i++){
                if(occ[i]==0){
                    occ[i]=1;
                    where[ve]=i;
                    cash+=ratekg[i-1]*weight[ve-1];
                    goto endloop;
                }
            }
            q.push(ve);
            endloop:;
        }
        // cout<<cash<<el;
    }
    cout<<cash;
    return 0;
}

Compilation message

garage.cpp: In function 'int main()':
garage.cpp:14:33: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   14 | #define fl(i, b) for (int i=0; i<(b); i++)
      |                                 ^
garage.cpp:20:17: note: in expansion of macro 'fl'
   20 | #define read(s) fl(i,s.size())cin>>s[i];
      |                 ^~
garage.cpp:40:5: note: in expansion of macro 'read'
   40 |     read(ratekg);
      |     ^~~~
garage.cpp:14:33: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   14 | #define fl(i, b) for (int i=0; i<(b); i++)
      |                                 ^
garage.cpp:20:17: note: in expansion of macro 'fl'
   20 | #define read(s) fl(i,s.size())cin>>s[i];
      |                 ^~
garage.cpp:42:5: note: in expansion of macro 'read'
   42 |     read(weight);
      |     ^~~~
# 결과 실행 시간 메모리 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 348 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 2 ms 348 KB Output is correct
18 Correct 3 ms 548 KB Output is correct
19 Correct 4 ms 344 KB Output is correct
20 Correct 2 ms 528 KB Output is correct