답안 #228795

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
228795 2020-05-02T15:40:37 Z osaaateiasavtnl Garage (IOI09_garage) C++14
100 / 100
6 ms 384 KB
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ii pair <int, int>
#define app push_back
#define all(a) a.begin(), a.end()
#define bp __builtin_popcount
#define ll long long
#define mp make_pair
#define f first
#define s second
#define Time (double)clock()/CLOCKS_PER_SEC

const int N = 2007;
int c[N], w[N];
bool used[N];
int pos[N];

int n, m, ans = 0;
queue <int> q;
void add(int i) {
    //cout << "add " << i << endl;
    pos[i] = -1;
    for (int j = 1; j <= n; ++j) {
        if (!used[j]) {
            pos[i] = j;
            break;
        }   
    }   
    if (pos[i] != -1) {
        //cout << "place " << i << "->" << pos[i] << ' ' << w[i] * c[pos[i]] << endl;
        used[pos[i]] = 1;
        ans += w[i] * c[pos[i]];
    }   
    else {
        q.push(i);
    }   
    //cout << "exit" << endl;
}   

signed main() {
    #ifdef HOME
    freopen("input.txt", "r", stdin);
    #else
    #define endl '\n'
    ios_base::sync_with_stdio(0); cin.tie(0);
    #endif
    cin >> n >> m;
    for (int i = 1; i <= n; ++i)
        cin >> c[i];
    for (int i = 1; i <= m; ++i)
        cin >> w[i];
    for (int t = 0; t < 2 * m; ++t) {
        int i;
        cin >> i;
        if (i > 0) {
            add(i);
        }   
        else {
            i = -i;
            used[pos[i]] = 0;
            if (q.size()) {
                i = q.front(); q.pop();
                add(i);
            }   
        }   
        //cout << "end " << t << endl;
    }   
    cout << ans << endl;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 6 ms 384 KB Output is correct
11 Correct 5 ms 384 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 5 ms 384 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
19 Correct 5 ms 384 KB Output is correct
20 Correct 5 ms 384 KB Output is correct