#include
using namespace std;
int N, M, H;
int map[30]????;
int best = 4;
int is_it_ok() {
int st;
for (int i = 0; i
st = i;
for (int j = 0; j
if (st != i) return 0;
}
return 1;
}
void dfs(int pos, int cnt) {
int x, y;
if (cnt >= best) return;
if (is_it_ok() == 1) {
if (best > cnt) best = cnt;
return;
}
if (pos < (N - 1)*H && cnt
while (1) {
x = pos % (N - 1);
y = pos / (N - 1);
if (map[y][x] == 0 && map[y][x + 1] == 0) {
map[y][x] = 1;
map[y][x + 1] = -1;
dfs(pos + 1, cnt + 1);
map[y][x] = 0;
map[y][x + 1] = 0;
}
pos++;
if (pos == (N - 1)*H) break;
}
}
}
int main(void) {
cin >> N >> M >> H;
int a, b;
for (int i = 0; i
cin >> a >> b;
a--;
b--;
map[a][b] = 1;
map[a][b + 1] = -1;
}
dfs(0, 0);
if (best == 4) cout << -1;
else cout <
}
이렇게 짰는데
처리시간이 300ms이나 나오네요 0ms 솔 하신 분도 계시던데 개선을 어떻게 해야될까요?
복붙해서 올려놓고 지 코드가 제대로 써졌는지 확인도 안하네 시발새끼가 - dc App
그래놓고 남들보고 읽으라는거냐 디질래? - dc App
0ms는 네 머리로는 생각이 불가능한 풀이란다