(백준) 연속된 K개 전구들의 불 끄기
#include <iostream>
#include <queue>
using namespace std;
bool light[100000];
queue<int> dk;
bool cmpFactor = true;
bool insomnia = false;
int main() {
FILE * empty; freopen_s(&empty, "input.txt", "r", stdin);
int N, K, c = 0, i;
cin >> N >> K;
for (int i = 0; i < N; i++) {
cin >> light[i];
}
for (i = 0; i < N; i++) {
if (!dk.empty() && dk.front() == i) cmpFactor ^= 1, dk.pop();
if (light[i] == cmpFactor) {
dk.push(i + K);
cmpFactor ^= 1;
c++;
}
}
bool flag = true;
while (!dk.empty()) {
if (i < dk.front())
{
flag = false;
}
dk.pop();
}
flag ? (cout << c << endl) : (cout << "Insomnia" << endl);
return 0;
}
#include <queue>
using namespace std;
bool light[100000];
queue<int> dk;
bool cmpFactor = true;
bool insomnia = false;
int main() {
FILE * empty; freopen_s(&empty, "input.txt", "r", stdin);
int N, K, c = 0, i;
cin >> N >> K;
for (int i = 0; i < N; i++) {
cin >> light[i];
}
for (i = 0; i < N; i++) {
if (!dk.empty() && dk.front() == i) cmpFactor ^= 1, dk.pop();
if (light[i] == cmpFactor) {
dk.push(i + K);
cmpFactor ^= 1;
c++;
}
}
bool flag = true;
while (!dk.empty()) {
if (i < dk.front())
{
flag = false;
}
dk.pop();
}
flag ? (cout << c << endl) : (cout << "Insomnia" << endl);
return 0;
}
댓글
댓글 쓰기