# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
542417 | AJ00 | Garage (IOI09_garage) | C++14 | 1 ms | 340 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>
using namespace std;
#define int long long
int rate[100],par[100],weight[2001],alloted[2001],n;
deque<int> waiting;
int find(int x,int y){
if (x == par[x]){
par[x] = x+1;
return x;
}
if (x == n-1){
waiting.push_back(y);
return -1;
}
return find(par[x],y);
}
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
int t=1,m,x,cur;
// cin >> t;
while (t--){
cin >> n >> m;
for (int i = 0; i < n; i++){
cin >> rate[i];
par[i] = i;
}
for (int i = 1; i <= m; i++){
cin >> weight[i];
}
int ans = 0;
for (int i = 0; i < 2*m; i++){
cin >> x;
//x--;
if (x < 0){
x = abs(x);
par[alloted[x]] = alloted[x];
if (!waiting.empty()){
cur = waiting.front();
alloted[cur] = alloted[x];
waiting.pop_front();
ans += (weight[cur]*rate[alloted[cur]]);
}
}
else {
cur = find(0,x);
if (cur == -1){
continue;
}
alloted[x] = cur;
ans += (weight[x]*rate[cur]);
}
}
cout << ans << "\n";
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |