# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
418830 | ResiBamboo | Garage (IOI09_garage) | C++17 | 2 ms | 488 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
using str = string; // yay python!
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef vector <ll> vl;
#define FOR(i, a, b) for (int i=a; i<b; i++)
#define F0R(i, a) for (int i=0; i<a; i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
#define vt vector
#define pb push_back
#define all(c) (c).begin(), (c).end()
#define sz(x) (int)size(x)
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
string to_string(char c) {
return string(1, c);
}
string to_string(bool b) {
return b?"true":"false";
}
string to_string(const char* s) {
return string(s);
}
string to_string(string s) {
return s;
}
template<class A> void write(A x) {
cout << to_string(x);
}
template<class H, class... T> void write(const H& h, const T&... t) {
write(h);
write(t...);
}
void print() {
write("\n");
}
template<class H, class... T> void print(const H& h, const T&... t) {
write(h);
if(sizeof...(t))
write(' ');
print(t...);}
const int d4i[4]={-1, 0, 1, 0}, d4j[4]={0, 1, 0, -1};
const int d8i[8]={-1, -1, 0, 1, 1, 1, 0, -1}, d8j[8]={0, 1, 1, 1, 0, -1, -1, -1};
const int mod=1000000007;
//-------------------####Real Programming###------------------
void setIO(string name=""){
ios_base::sync_with_stdio(0); cin.tie(0);
if((int)name.size() > 0){freopen((name+".in").c_str(), "r", stdin);freopen((name+".out").c_str(), "w", stdout);}
}
int open[101]; //the parking lot that are open
queue<int> wait;//the number of cars
int prices[101];//use the number of parking lot to access
int cars[1001];//use the number of cars to access weight
int record[1001];//r[number of car]==the number of parking lot it was at
int N,M;
int findspot(){
FOR(i,1,N+1) if(open[i]) return i;
return -1;
}
void solve(){
int ans=0;
cin>>N>>M;
FOR(i,1,N+1){
cin>>prices[i];
open[i]=1;
}FOR(i,1,M+1){
cin>>cars[i];
}
F0R(i,2*M){
int n; cin>>n;
if (findspot()==-1&&n>0) wait.push(n);
else if(n>0){
int j=findspot();
ans+=cars[n]*prices[j];
open[j]=0;
record[n]=j;
}else if(n<0){
if(!wait.empty()){
ans+=cars[wait.front()]*prices[record[abs(n)]];
record[wait.front()]=record[abs(n)];
wait.pop();
}else{open[record[abs(n)]]=1;}
}
}
cout<<ans<<"\n";
}
int main(){
setIO("");
//int t; cin>>t; while(t--)
solve();
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |