# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
587989 | MohamedFaresNebili | Garage (IOI09_garage) | C++14 | 1 ms | 388 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
/// #pragma GCC optimize ("Ofast")
/// #pragma GCC target ("avx2")
/// #pragma GCC optimize("unroll-loops")
using namespace std;
using ll = long long;
using ii = pair<ll, ll>;
using vi = vector<int>;
#define ff first
#define ss second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define lb lower_bound
#define int ll
const int MOD = 1000 * 1000 * 1000 + 7;
int32_t main() {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int N, M; cin >> N >> M; int R[N], W[M]; bool leave[M];
queue<int> Q; int A[N], B[M]; int res = 0;
for(int l = 0; l < N; l++)
cin >> R[l], A[l] = -1;
for(int l = 0; l < M; l++)
cin >> W[l], B[l] = -1, leave[l] = 0;
for(int _ = 0; _ < 2 * M; _++) {
int U; cin >> U;
if(U > 0) { U--; Q.push(U); }
else {
U++; U = -U; leave[U] = 1;
if(B[U] == -1) continue;
A[B[U]] = -1; B[U] = -1;
}
while(!Q.empty()) {
int V = Q.front(); bool ok = 0;
if(leave[V]) { Q.pop(); continue; }
for(int l = 0; l < N; l++) {
if(A[l] != -1) continue;
A[l] = V, B[V] = l;
ok = 1; res += R[l] * W[V];
break;
}
if(ok) Q.pop();
else break;
}
}
cout << res << "\n";
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |