답안 #973020

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
973020 2024-05-01T12:32:58 Z Sammii0 Garage (IOI09_garage) C++17
100 / 100
2 ms 600 KB
#pragma GCC optimize("Ofast","unroll-loops")
// #pragma GCC target("avx2,fma")
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for (__typeof(a) i=(a); i<(b); ++i)
#define iter(it,c) for (__typeof((c).begin()) \
  it = (c).begin(); it != (c).end(); ++it)
#define riter(it,c) for (__typeof((c).rbegin()) \
  it = (c).rbegin(); it != (c).rend(); ++it)
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef long long ll;
#define pb push_back
#define fs first
#define sc second
const int INF = ~(1<<31);

const double EPS = 1e-9;
const double pi = acos(-1);
typedef unsigned long long ull;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
template <class T> T smod(T a, T b) {
        return (a % b + b) % b; }

int main() {
    int n, m;
    cin >> n >> m;

    vector<ll> p(m+1), w(m+1), r(n+1);
    priority_queue<int, vi, greater<int>> pq;
    queue<int> q;
    ll sm = 0;

    rep(i, 0, n) {
      cin >> r[i+1];
      pq.push(i+1);
    }

    rep(i, 0, m) {
      cin >> w[i+1];
    }

    rep(i, 0, 2 * m) {
      int temp;
      cin >> temp;

      if (temp < 0) {
        pq.push(p[abs(temp)]);
      } else {
        q.push(temp);
      }

      while (!q.empty() && !pq.empty()) {
        int front = q.front();
        int place = pq.top();
        q.pop(); pq.pop();
        sm += w[front] * r[place];

        // cout << front << ' ' << place << ' ' << sm << endl;

        p[front] = place;
      }
    }

    cout << sm << endl;


    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 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 432 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 600 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 1 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 2 ms 348 KB Output is correct