/
3445030
/
test
Обзор
Документация
Войти
/
3445030
/
test
Код
Запросы
0
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
1
62 строки
1 KB
3445030
update 1
10 апр 2024, 05:38
10 апр 2024, 05:38
26c0d47
Код
Авторство
О чём код?
#include <stdio.h> #define SIZE 64 int h, w; char matr[SIZE][SIZE]; int hasRow[SIZE], hasCol[SIZE], hasAdd[2*SIZE], hasSub[2*SIZE]; int Solve(int r) { if (r == h) { return 1; } for (int c = 0; c < w; c++) { if (matr[r][c] == '.') continue; if (hasRow[r] || hasCol[c] || hasAdd[r+c] || hasSub[r-c + SIZE]) continue; hasRow[r]++; hasCol[c]++; hasAdd[r+c]++; hasSub[r-c + SIZE]++; char old = matr[r][c]; matr[r][c] = 'X'; if (Solve(r+1)) return 1; matr[r][c] = old; hasRow[r]--; hasCol[c]--; hasAdd[r+c]--; hasSub[r-c + SIZE]--; } return 0; } int main() { freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); scanf("%d%d", &h, &w); for (int i = 0; i < h; i++) scanf("%s", matr[i]); if (!Solve(0)) { printf("NO\n"); return 0; } printf("YES\n"); for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) if (matr[i][j] == '?') matr[i][j] = '.'; printf("%s\n", matr[i]); } return 0; }