답안 #1028729

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1028729 2024-07-20T07:48:10 Z vjudge1 Garage (IOI09_garage) C++17
100 / 100
1 ms 476 KB
#include <bits/stdc++.h>

#define _CRT_SECURE_NO_DEPRECATE
#define LSOne(S) ((S) & -(S))
using namespace std;

typedef long long ll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
const int INF = 1e9;
const long long LLINF = 4e18;
const double EPS = 1e-9;

/************************* Collection *****************************************/

// memset(memo, -1, sizeof memo);
// initialize DP memoization table with -1
// memset(arr, 0, sizeof arr); to clear array of integers
// set<T> s(a.begin(), a.end());
// a.resize(n, val);
// unique(a.begin(), a.end()) return new end pointer

/*************************** Sort *********************************************/
// binary_search(a.begin(), a.end(), value); // bool value return

/*************************** Misc *********************************************/
// index = (index + n - 1) % n; // index--; if (index < 0) index = n - 1;
// int ans = (int)((double)d + 0.5); // for rounding to nearest integer or
// round()

/************************************** Format ********************************/
// Format String "%a.*lf" - set precision
// Format String "%a.blf" - b digit after ., a field precision
// Format String "%[0-9]", "%[a-zA-Z]"
// Format String "%3000[^\n]" input string upto 3000 and endline
// Space before %c consume whitespace
// %% print %
// sscanf, fgets, memmove, snprintf, strsep, isalpha, isnumber, isalnum,
// string(begin(), end()), string(num, char), string.append(),
// string.push_back(), string.find(), string.find_first_of(), find_last_of(),
// find_first_not_of(), find_last_not_of(), distance(), find()

/************************************** Permutation ***************************/
// next_permutation(s.begin(), s.end());
// prev_permutation(s.begin(), s.end());

/*************************************** Algo*********************************/
// replace(begin(), end(), val1, replace)

int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  vi a(n);
  vi w(m);
  vii t(m);
  vi p(m);
  long long res = 0;
  queue<int> q;
  set<int> st;
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
    st.insert(i);
  }
  for (int i = 0; i < m; i++) {
    scanf("%d", &w[i]);
  }
  for (int i = 0; i < 2 * m; i++) {
    int tmp;
    scanf("%d", &tmp);
    if (tmp > 0) {
      tmp -= 1;
      if (st.size() == 0) {
        q.push(tmp);
      } else {
        p[tmp] = *st.begin();
        st.erase(st.begin());
        res += a[p[tmp]] * w[tmp];
      }
    } else {
      tmp = -tmp;
      tmp -= 1;
      if (q.size() > 0) {
        int k = q.front();
        q.pop();
        p[k] = p[tmp];
        res += a[p[tmp]] * w[k];
      } else {
        st.insert(p[tmp]);
      }
    }
  }
  printf("%lld\n", res);
  return 0;
}

Compilation message

garage.cpp: In function 'int main()':
garage.cpp:53:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   53 |   scanf("%d%d", &n, &m);
      |   ~~~~~^~~~~~~~~~~~~~~~
garage.cpp:62:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   62 |     scanf("%d", &a[i]);
      |     ~~~~~^~~~~~~~~~~~~
garage.cpp:66:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   66 |     scanf("%d", &w[i]);
      |     ~~~~~^~~~~~~~~~~~~
garage.cpp:70:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   70 |     scanf("%d", &tmp);
      |     ~~~~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 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 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 476 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 1 ms 348 KB Output is correct