답안 #392275

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
392275 2021-04-20T18:33:32 Z nishuz Garage (IOI09_garage) C++17
100 / 100
1 ms 332 KB
// #pragma GCC optimize("Ofast,unroll-loops")
// #pragma GCC target("avx,avx2,sse,sse2")
 
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace __gnu_pbds;
using namespace std;
 
#define ll long long
#define ld long double
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
#define eb emplace_back
#define F first
#define S second
#define mp make_pair
#define random mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
 
template <typename T> using oset = tree <pair <T, T>, null_type, less <pair <T, T>>, rb_tree_tag, tree_order_statistics_node_update>;

template <typename Container>
void Print(Container& container, int starting) {
    auto Start = container.begin(), End = container.end();
    while (Start != End) cout << *(Start++) << " ";
    cout << '\n';
}
 
template <typename T>
void print(T&& t) {cout << t << '\n';}
 
template <typename T, typename... Args>
void print(T&& t, Args&&... args) {
    cout << t << " ";
    print(forward<Args>(args)...);
}

inline void solve() {
    int n, m, ans = 0;
    cin >> n >> m;
    int s[n], w[m], p[m];
    set <int> spots;
    for (int i = 0; i < n; ++i) {
        cin >> s[i];
        spots.insert(i);
    }
    for (int i = 0; i < m; ++i) cin >> w[i];
    queue <int> q;
    for (int i = 0; i < 2 * m; ++i) {
        int x;
        cin >> x;
        if (x > 0) {
            --x;
            q.emplace(x);
        } else {
            spots.insert(p[-x - 1]);
        }
        while (!q.empty() && !spots.empty()) {
            int cur = q.front();
            ans += (w[cur] * s[p[cur] = *spots.begin()]);
            spots.erase(spots.begin());
            q.pop();
        }
    }
    print(ans);
}
 
int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int T = 1;
    // cin >> T;
    for (int test = 1; test <= T; ++test) {
        // cout << "Case #" << test << ": ";
        solve();
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct