Submission #392267

# Submission time Handle Problem Language Result Execution time Memory
392267 2021-04-20T18:17:33 Z nishuz Garage (IOI09_garage) C++17
5 / 100
2 ms 464 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;
    vector <int> s(n + 1), w(m + 1), p(n + 1);
    set <int> spots;
    for (int i = 1; i <= n; ++i) {
        cin >> s[i];
        spots.insert(i);
    }
    for (int i = 1; i <= m; ++i) cin >> w[i];
    queue <int> q;
    for (int i = 0; i < 2 * m; ++i) {
        int x;
        cin >> x;
        if (x > 0) {
            q.emplace(x);
        } else {
            x *= -1;
            spots.insert(p[x]);
            p[x] = 0;
        }
        while (!q.empty() && !spots.empty()) {
            int cur = q.front();
            auto place = spots.begin();
            spots.erase(place);
            p[cur] = *place;
            ans += (w[cur] * s[*place]);
            q.pop();
        }
    }
    while (!q.empty() && !spots.empty()) {
        int cur = q.front();
        auto place = spots.begin();
        spots.erase(place);
        p[cur] = *place;
        ans += (w[cur] * s[*place]);
        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();
    }
}
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 460 KB Execution killed with signal 6
2 Runtime error 1 ms 332 KB Execution killed with signal 11
3 Correct 1 ms 204 KB Output is correct
4 Runtime error 1 ms 332 KB Execution killed with signal 11
5 Runtime error 1 ms 464 KB Execution killed with signal 6
6 Runtime error 1 ms 460 KB Execution killed with signal 6
7 Runtime error 1 ms 460 KB Execution killed with signal 6
8 Runtime error 1 ms 332 KB Execution killed with signal 11
9 Runtime error 1 ms 460 KB Execution killed with signal 6
10 Runtime error 2 ms 460 KB Execution killed with signal 6
11 Runtime error 1 ms 332 KB Execution killed with signal 11
12 Runtime error 1 ms 332 KB Execution killed with signal 11
13 Runtime error 1 ms 332 KB Execution killed with signal 11
14 Runtime error 1 ms 460 KB Execution killed with signal 6
15 Runtime error 1 ms 460 KB Execution killed with signal 11
16 Runtime error 1 ms 460 KB Execution killed with signal 11
17 Runtime error 2 ms 460 KB Execution killed with signal 6
18 Runtime error 1 ms 460 KB Execution killed with signal 11
19 Runtime error 1 ms 460 KB Execution killed with signal 6
20 Runtime error 1 ms 460 KB Execution killed with signal 11