제출 #866255

#제출 시각아이디문제언어결과실행 시간메모리
866255BulaGarage (IOI09_garage)C++14
100 / 100
2 ms604 KiB
#include <bits/stdc++.h>
using namespace std;

main(){
    int n, m;
    cin >> n >> m;
    vector<int> a(n + 1), b(m + 1);
    for(int i = 1; i <= n; i++) cin >> a[i];
    for(int i = 1; i <= m; i++) cin >> b[i];

    set<int> st;
    queue<int> q;
    map<int, int> mp;
    for(int i = 1; i <= n; i++) st.insert(i);

    int ans = 0;
    for(int i = 1; i <= 2 * m; i++){
        int x;
        cin >> x;
        if(x > 0){
            if(st.size() == 0){
                q.push(x);
            }else{
                if(q.size() == 0){
                    int k = *st.begin();
                    ans += a[k] * b[x];
                    mp[x] = k;
                    st.erase(st.begin());
                }else{
                    int k = *st.begin();
                    int p = q.front();
                    ans += a[k] * b[p];
                    mp[p] = k;
                    st.erase(st.begin());
                    q.pop();
                    q.push(x);
                }
            }
        }else{
            st.insert(mp[abs(x)]);
            if(q.size() > 0){
                int k = *st.begin();
                int p = q.front();
                ans += a[k] * b[p];
                mp[p] = k;
                st.erase(st.begin());
                q.pop();
            }
        }
    }
    cout << ans << endl;
}

컴파일 시 표준 에러 (stderr) 메시지

garage.cpp:4:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
    4 | main(){
      | ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...