# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
717654 | ZeroCool | Garage (IOI09_garage) | C++14 | 2 ms | 340 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define ll long long
#define inf INT_MAX
#define endl '\n'
using namespace std;
const int mxn = 20;
void solve(){
int n, m;
long long result = 0;
cin>>n>>m;
vector<int>r(n + 1), w(m + 1);
for(int i = 1;i <= n;++i)cin>>r[i];
for(int i = 1;i <= m;++i)cin>>w[i];
vector<int>p(n + 1);
queue<int>q;
for(int i = 0;i < 2 * m;++i){
int c;
cin>>c;
bool park = false;
if(c > 0){
for(int j = 1;j <= n;++j){
if(!p[j]){
p[j] = c;
result += w[c] * r[j];
park = true;
break;
}
}
if(!park){
q.push(c);
}
}
else{
for(int j = 1;j <= n;++j){
if(-c == p[j]){
p[j] = 0;
break;
}
}
if(!q.empty()){
int cur = q.front();
q.pop();
for(int j = 1;j <= n;++j){
if(!p[j]){
p[j] = cur;
result += w[cur] * r[j];
break;
}
}
}
}
}
cout<<result<<endl;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t = 1;
//cin>>t;
while(t--) solve();
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |