[SWEA] 9280 진용이네 주차타워

Time Lapse :NONE

9280.cpp

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#include<iostream>
#include <vector>
#include <algorithm>
#include <memory.h>
using namespace std;
int N,M;
vector<int> answer;
vector<int> fee;
vector<int> weight;
vector<int> inout;
int is_full[100];
int place[2001];

bool get_in(int num){
for (int j = 0; j < N; j++) {
if (is_full[j]==0) {
answer[answer.size()-1] += weight[num-1]*fee[j];
is_full[j] = num;
place[num]=j;
inout.erase(inout.begin());
return true;
}
}
return false;
}

void test(){
fee.clear();
weight.clear();
inout.clear();
fee.resize(N);
weight.resize(M);
inout.resize(2*M);
memset(is_full,0,sizeof(is_full));
answer.push_back(0);
for(int i=0;i<N;i++)
cin>>fee[i];
for(int i=0;i<M;i++)
cin>>weight[i];
for(int i=0;i<2*M;i++)
cin>>inout[i];
int use = 0;
while(inout.size()!=0) {
if (use < N) {
int num = inout[0];
if (num > 0) {
get_in(num);
++use;
}
else {
is_full[place[num*-1]]=0;
--use;
inout.erase(inout.begin());
}
}
else{
for(int i=0;i<inout.size()-1;i++){
if(inout[i]<0){
is_full[place[inout[i]*-1]] = 0;
inout.erase(inout.begin()+i);
--use;
break;
}
}
}
}
}


int main(int argc, char** argv)
{
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int test_case;
int T;
cin>>T;
for(test_case = 1; test_case <= T; ++test_case)
{

cin>>N>>M;
test();

}

for(int i=0;i<answer.size();i++)
cout<<"#"<<i+1<<" "<<answer[i]<<endl;
return 0;//정상종료시 반드시 0을 리턴해야합니다.
}
Author: Song Hayoung
Link: https://songhayoung.github.io/2020/08/04/PS/SWEA/9280/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.