아직 계정이 없으신가요? 회원가입

Dev. Talk

회의실 예약 ㅠㅠㅠㅠㅠ

회원사진bungae104
141 views2022-10-03 22:50

30점 밖에 못받았어요 ㅠㅠㅠㅠ

반례있을까요???


//회의실 배정
//구조체 이용해서 풀면 될 것 같다
/*
3 7
grandeur
avante
sonata
sonata 14 16
grandeur 11 12
avante 15 18
sonata 10 11
avante 9 12
grandeur 16 18
avante 12 15
출력예제1
Room avante:
Not available
-----
Room grandeur:
2 available:
09-11
12-16
-----
Room sonata:
3 available:
09-10
11-14
16-18
*/
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

//globals
int rooms, conferences;
vector<pair<string,vector<bool>>> graph;
vector<pair<string,vector<pair<int,int>>>> total_time_line;

void Input(){
    cin>>rooms>>conferences;
    vector<bool> visited;

    for(int i=0; i<9; i++){
        visited.push_back(false);
    }

    for(int i=0; i<rooms; i++){
        string tmp;
        cin>>tmp;
        graph.push_back({tmp,visited});
    }

    for(int i=0; i<conferences; i++){
        string tmp;
        int st,ed;
        cin>>tmp>>st>>ed;
        for(int j=0; j<graph.size(); j++){
            if(graph[j].first==tmp){
                for(int k=st-9; k<ed-9; k++){
                    graph[j].second[k]=true;
                }
            }
        }
    }
}

void find_empty_room(){
    for(int i=0;i<graph.size(); i++){
        vector<pair<int,int>> time_line;
        int cnt=0;
        int st;
        bool isStart=true;
        for(int j=0; j<9; j++){
            if(!graph[i].second[j] && isStart){
                cnt=0;
                st=j;
                isStart=false;
            }
            else if (graph[i].second[j] && !isStart){
                time_line.push_back({st,st+cnt});
                st=0;
                isStart=true;
            }
            else if(!graph[i].second[j] && !isStart && j==8){
                cnt++;
                time_line.push_back({st,st+cnt});
                isStart=true;
            }
            cnt++;
        }
        total_time_line.push_back({graph[i].first,time_line});
    }

}

void Output(){
    for(int i=0; i<total_time_line.size(); i++){
        if(total_time_line[i].second.size()==0){
            cout<<"Room "<<total_time_line[i].first<<':'<<'\n';
            cout<<"Not available"<<'\n';
            if(i==total_time_line.size()-1){
                cout<<'\n';
            }
            else cout<<"-----"<<'\n';
        }
        else{
            cout<<"Room "<<total_time_line[i].first<<':'<<'\n';
            cout<<total_time_line[i].second.size()<<" available:"<<'\n';
            for(int j=0; j<total_time_line[i].second.size(); j++){
                if(total_time_line[i].second[j].first==0){
                    cout<<"09"<<'-'<<  total_time_line[i].second[j].second+9<<'\n';
                }
                else{
                    cout<<total_time_line[i].second[j].first+9<<'-'<<  total_time_line[i].second[j].second+9<<'\n';
                }
            }
            if(i==total_time_line.size()-1){
                cout<<'\n';
            }
            else cout<<"-----"<<'\n';
        }
    }
}

void Start(){
    //그래프 정렬
    sort(graph.begin(),graph.end());

    //비어있는 방 찾기
    find_empty_room();

    Output();
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    Input();

    Start();
}