회원가입
로그인
Toggle navigation
문제
문제
전체 문제
문제 출처
단계별로 풀어보기
알고리즘 분류
추가된 문제
문제 순위
문제
푼 사람이 한 명인 문제
아무도 못 푼 문제
최근 제출된 문제
최근 풀린 문제
랜덤
출처
ICPC
Olympiad
한국정보올림피아드
한국정보올림피아드시․도지역본선
전국 대학생 프로그래밍 대회 동아리 연합
대학교 대회
카카오 코드 페스티벌
Coder's High
ICPC
Regionals
World Finals
Korea Regional
Africa and the Middle East Regionals
Europe Regionals
Latin America Regionals
North America Regionals
South Pacific Regionals
문제집
대회
채점 현황
게시판
그룹
더 보기
재채점 기록
블로그
도움말
전체
공지
자유
질문
오타/오역/요청
게시판 공지
홍보
업데이트
solved.ac
글쓰기
질문 도움말
자주묻는 질문
시간초과 질문..
8980번 - 택배
kimmgsa
1년 전
0
시간초과 문제가 생기는데 어떻게 접근해야할까요... 도와주세용
#include <iostream> #include <vector> #include <algorithm> typedef std::pair<int, int> loading_status; int main() { int N,C,M; std::cin >> N >> C; std::cin >> M; std::vector<loading_status> loading_info[2001]; std::vector<loading_status> onTruck; int start, goal, box_num; for(int i =0; i<M; i++) { std::cin >> start >> goal >> box_num; loading_info[start].push_back({goal,box_num}); } int capacity = C; int transferred_box = 0; int current_load = 0; for(int i = 1; i<=N; i++) { for (auto it = onTruck.begin(); it != onTruck.end(); ) { if (it->first == i) { transferred_box += it->second; current_load -= it->second; it = onTruck.erase(it); } else { ++it; } } //실어야할 박스 정보 for(auto &box : loading_info[i]) { int cur_capa = capacity - current_load; if(cur_capa > 0) { int load_direct = std::min(box.second,cur_capa); onTruck.push_back({box.first, load_direct}); current_load += load_direct; box.second -= load_direct; } if(box.second > 0) // 여전히 적재할 것이 있다면 { //실린 박스 정보 for(auto &load : onTruck) { if(box.second == 0) break; //교체 가능한 박스 찾기 if(box.first < load.first && box.second > 0) {//실린 박스 개수와 실을 박스 개수 비교 int trade_num = load.second - box.second; if(trade_num >= 0) { load.second -= box.second; onTruck.push_back({box}); box.second = 0; } else // 교환할 박스가 초과 {//초과한 만큼 빼고 교환 load.first = box.first; load.second = box.second + trade_num; box.second -= load.second; } } } } std::sort(onTruck.begin(), onTruck.end(), [](const loading_status &a, const loading_status &b){ return a.first > b.first; }); } //태울것이 있는데 용량 부족하다면 내가 태운 것들 목적지목적지 확인 //std::cout << i <<',' << truck.second << ',' << unload_box << std::endl; } std::cout << transferred_box << std::endl; }
댓글을 작성하려면
로그인
해야 합니다.
kimmgsa 1년 전
시간초과 문제가 생기는데 어떻게 접근해야할까요... 도와주세용