/* -*- coding: utf-8 -*- * * 3805.cc: No.3805 Crossword Key Maker - yukicoder */ #include #include #include #include #include using namespace std; /* constant */ const int MAX_H = 100; const int MAX_W = 100; const int MAX_L = max(MAX_H, MAX_W); /* typedef */ using pii = pair; using vpii = vector; /* global variables */ char fs[MAX_H][MAX_W]; int hcs[MAX_H][MAX_W + 1], vcs[MAX_H + 1][MAX_W]; /* subroutines */ bool is_hkey(int h, int w, int y, int x) { return hcs[y][x] >= 2 && (x == 0 || fs[y][x - 1] == '#'); } bool is_vkey(int h, int w, int y, int x) { return vcs[y][x] >= 2 && (y == 0 || fs[y - 1][x] == '#'); } bool is_key(int h, int w, int y, int x) { return is_hkey(h, w, y, x) || is_vkey(h, w, y, x); } vpii gen_kps(int h, int w) { vpii kps; for (int y = 0; y < h; y++) for (int x = 0; x < w; x++) if (is_key(h, w, y, x)) kps.push_back({y, x}); return kps; } bool hfill(int y, int x, string &s) { if (s[0] == '-') return true; int l = (int)s.size(); if (hcs[y][x] != l) return false; for (int i = 0; i < l; i++, x++) { if (fs[y][x] == '.') fs[y][x] = s[i]; else if (fs[y][x] != s[i]) return false; } return true; } bool vfill(int y, int x, string &s) { if (s[0] == '-') return true; int l = (int)s.size(); if (vcs[y][x] != l) return false; for (int i = 0; i < l; i++, y++) { if (fs[y][x] == '.') fs[y][x] = s[i]; else if (fs[y][x] != s[i]) return false; } return true; } void printfs(int h) { for (int i = 0; i < h; i++) puts(fs[i]); } /* main */ int main() { int h, w; scanf("%d%d", &h, &w); for (int i = 0; i < h; i++) scanf("%s", fs[i]); for (int i = 0; i < h; i++) for (int j = w - 1; j >= 0; j--) hcs[i][j] = (fs[i][j] == '.') ? hcs[i][j + 1] + 1 : 0; for (int j = 0; j < w; j++) for (int i = h - 1; i >= 0; i--) vcs[i][j] = (fs[i][j] == '.') ? vcs[i + 1][j] + 1 : 0; auto kps = gen_kps(h, w); printf("%d\n", (int)kps.size()); for (auto [yi, xi]: kps) { string ha = is_hkey(h, w, yi, xi) ? string(hcs[yi][xi], 'a') : "-"; string va = is_vkey(h, w, yi, xi) ? string(vcs[yi][xi], 'a') : "-"; printf("%s %s\n", ha.c_str(), va.c_str()); } return 0; }