-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path15729.cpp
More file actions
43 lines (39 loc) · 762 Bytes
/
15729.cpp
File metadata and controls
43 lines (39 loc) · 762 Bytes
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
// 15729. 방탈출
// 2021.07.01
// 그리디 알고리즘
#include<iostream>
using namespace std;
int arr[1000001];
int main()
{
int n;
int ans = 0;
cin >> n;
for (int i = 0; i < n; i++)
{
cin >> arr[i];
}
for (int i = 0; i < n; i++)
{
if (arr[i] == 1)
{
ans++;
for (int j = 0; j < 3; j++)
{
if (i + j < n)
{
if (arr[i + j] == 0)
{
arr[i + j] = 1;
}
else
{
arr[i + j] = 0;
}
}
}
}
}
cout << ans << endl;
return 0;
}