백준의 불 끄기 문제랑 동일하다. 문제를 풀면 플래그가 나온다.
#include <iostream>
#include <vector>
using namespace std;
#define MAXX 10
#define MAXY 5
#define INF 1e9
bool arr[150][150], tmp_arr[150][150];
int dx[] = { 0,0,1,-1 };
int dy[] = { 1,-1,0,0 };
int ans = INF;
bool outrange(int x, int y) {
if (x < 0 || x >= MAXX || y < 0 || y >= MAXY) return 1;
return 0;
}
void toggle(int x, int y) {
for (int i = 0; i < 4; i++)
{
int nx = x + dx[i];
int ny = y + dy[i];
if (!outrange(nx, ny)) tmp_arr[nx][ny] = !tmp_arr[nx][ny];
}
tmp_arr[x][y] = !tmp_arr[x][y];
}
void init() {
for (int i = 0; i < MAXX; i++)
for (int j = 0; j < MAXY; j++)
tmp_arr[i][j] = arr[i][j];
}
bool islight() {
for (int i = 0; i < MAXX; i++)
for (int j = 0; j < MAXY; j++)
if (tmp_arr[i][j]) return 1;
return 0;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
for (int i = 0; i < MAXX; i++) {
for (int j = 0; j < MAXY; j++)
{
char c; cin >> c;
if (c == 'O') arr[i][j] = 1;
}
}
for (int step = 0; step < (1<< MAXY); step++)
{
int cnt = 0;
init();
vector<pair<int, int> > v;
for (int bit = 0; bit < MAXY; bit++)
{
if (step & (1 << bit)) {
cnt++;
toggle(0, bit);
v.push_back({0, bit});
}
}
for (int x = 1; x < MAXX; x++)
{
for (int y = 0; y < MAXY; y++)
{
if (tmp_arr[x - 1][y]) {
toggle(x, y);
v.push_back({x, y});
cnt++;
}
}
}
if (!islight()) {
for (auto x : v) {
cout << x.first << ' ' << x.second << '\\n';
}
return 0;
}
}
cout << "Fucking Fail" << '\\n';
}