답안 #776931

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
776931 2023-07-08T12:00:40 Z mdub Garage (IOI09_garage) C++14
100 / 100
2 ms 340 KB
#include <bits/stdc++.h>

using namespace std;

int main () {
  int n, m; cin >> n >> m;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  vector<int> b(m);
  for (int i =0 ; i < m; i++) {
    cin >> b[i];
  }
  queue<int> q;
  vector<int> departures(m);
  vector<bool> used(m, false);
  int ans = 0;
  for (int i = 0; i < 2*m; i++) {
    int num; cin >> num;
    if (num > 0) {
      q.push(num-1);
    }
    else {
      used[departures[abs(num)-1]] = false;
    }
    
      
      for (int j = 0; j < n; j++) {
	if (!used[j]) {
	  if (q.size()) {
	    used[j] = true;
	    ans += a[j] * b[q.front()];
	    departures[q.front()] = j;
	    q.pop();
	  }
	  
	}
      }
      
    
  }
  cout << ans << '\n';
    
				
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 300 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 296 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 304 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 300 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 2 ms 212 KB Output is correct
17 Correct 2 ms 212 KB Output is correct
18 Correct 2 ms 340 KB Output is correct
19 Correct 2 ms 312 KB Output is correct
20 Correct 2 ms 340 KB Output is correct