20055번 컨베이어 벨트 위의 로봇

동도리동·2021년 10월 18일
0

코딩테스트

목록 보기
66/76

쉬운 문제였는데, 문제 설명이 난해해 푸는데 오래걸렸다. 요런것도 잘해야겠지...

#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>

using namespace std;
int n, k;
int go(vector<pair<int, bool> > con) {
	int ans = 0;
	int sum = 0;
	while (1) {
		ans++;
		con[n - 1].second = false;
		rotate(con.rbegin(), con.rbegin() + 1, con.rend());
		con[n - 1].second = false;
		for (int i = n-2; i >=0; i--) {
			if (con[i].second==true&&con[i + 1].first >= 1 && con[i + 1].second == false) {
				con[i + 1].first--;
				con[i + 1].second = true;
				con[i].second = false;
				
			}
		}
		con[n - 1].second = false;
		if (con[0].first >= 1) {
			con[0].first--;
			con[0].second = true;
		}
		sum = 0;
		for (int i = 0; i < 2 * n; i++) {
			if (con[i].first == 0) sum++;
		}
		if (sum >= k) return ans;
	}
}
int main() {
	//freopen("in1.txt", "rt", stdin);
	cin >> n >> k;
	vector<pair<int, bool> > con(2 * n);
	for (int i = 0; i < 2 * n; i++) {
		int x;
		cin >> x;
		con[i].first = x;
		con[i].second = false;
	}
	cout <<go(con) << '\n';
	return 0;
}
profile
긍정코딩세상

0개의 댓글

관련 채용 정보