結果

問題 No.3805 Crossword Key Maker
コンテスト
ユーザー tnakao0123
提出日時 2026-11-17 11:28:20
言語 C++17
(gcc 15.3.0 + boost 1.92.0 + ACL)
コンパイル:
g++-15 -O2 -fplugin=/usr/lib/yukicoder/noavx512-gcc15.so -lm -std=c++17 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 2 ms / 2,000 ms
+ 46µs
コード長 2,294 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 448 ms
コンパイル使用メモリ 88,092 KB
実行使用メモリ 9,868 KB
最終ジャッジ日時 2026-11-17 11:28:24
合計ジャッジ時間 3,400 ms
ジャッジサーバーID
(参考情報)
judge5_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 43
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

/* -*- coding: utf-8 -*-
 *
 * 3805.cc:  No.3805 Crossword Key Maker - yukicoder
 */

#include<cstdio>
#include<string>
#include<vector>
#include<algorithm>
#include<utility>

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<int,int>;
using vpii = vector<pii>;

/* 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;
}
0