# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
587989 | MohamedFaresNebili | Garage (IOI09_garage) | C++14 | 1 ms | 388 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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... |