Skip to content

Instantly share code, notes, and snippets.

@niklasjang
Created April 19, 2020 02:48
Show Gist options
  • Select an option

  • Save niklasjang/58f8473df7a1db9d3ef5735d3aab6940 to your computer and use it in GitHub Desktop.

Select an option

Save niklasjang/58f8473df7a1db9d3ef5735d3aab6940 to your computer and use it in GitHub Desktop.
[PS][그리디]/[BOJ][15729][방탈출]
#include <iostream>
using namespace std;
int n;
int cur[1000000];
int btn[1000000];
void show(void) {
for (int i = 0; i < n; i++) {
cout << cur[i] << ' ';
}
cout << "\n";
}
void press(int x) {
for (int j = x; j < x + 3; j++) {
if (j >= n) break;
cur[j] = !cur[j];
}
}
int main(void) {
cin >> n;
for (int i = 0; i < n; i++) cin >> btn[i];
int save = 0, i=0, ans=0;
while (i< n) {
for (; i < n; i++) {
if (cur[i] == btn[i]) continue;
press(i);
ans++;
//show();
}
}
cout << ans << "\n";
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment