結果
| 問題 | No.3805 Crossword Key Maker |
| ユーザー |
|
| 提出日時 | 2026-10-06 16:51:56 |
| 言語 | C++17 (gcc 15.3.0 + boost 1.92.0 + ACL) |
| 結果 |
AC
不安定
|
| 実行時間 | 2 ms / 2,000 ms |
| + 269µs | |
| コード長 | 1,974 bytes |
| 記録 | |
| コンパイル時間 | 1,406 ms |
| コンパイル使用メモリ | 228,580 KB |
| 実行使用メモリ | 9,904 KB |
| 最終ジャッジ日時 | 2026-11-14 14:31:32 |
| 合計ジャッジ時間 | 3,953 ms |
|
ジャッジサーバーID (参考情報) |
judge1_0 / judge2_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 43 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int H, W;
cin >> H >> W;
vector<string> S(H);
for (auto &s : S) cin >> s;
// key[i][j]:
// 1 = horizontal clue starts here
// 2 = vertical clue starts here
// 3 = both
vector<vector<int>> key(H, vector<int>(W, 0));
for (int i = 0; i < H; ++i) {
for (int j = 0; j < W; ++j) {
if (S[i][j] != '.') continue;
// Horizontal clue
bool left_black_or_out =
(j == 0 || S[i][j - 1] == '#');
bool right_white =
(j + 1 < W && S[i][j + 1] == '.');
if (left_black_or_out && right_white) {
key[i][j] |= 1;
}
// Vertical clue
bool up_black_or_out =
(i == 0 || S[i - 1][j] == '#');
bool down_white =
(i + 1 < H && S[i + 1][j] == '.');
if (up_black_or_out && down_white) {
key[i][j] |= 2;
}
}
}
vector<pair<int, int>> starts;
// 上の行から、同じ行では左から順番に追加される。
for (int i = 0; i < H; ++i) {
for (int j = 0; j < W; ++j) {
if (key[i][j] != 0) {
starts.emplace_back(i, j);
}
}
}
cout << starts.size() << '\n';
for (auto [i, j] : starts) {
string R = "-", C = "-";
// 横のカギ
if (key[i][j] & 1) {
R = "";
int y = j;
while (y < W && S[i][y] == '.') {
R += 'a';
++y;
}
}
// 縦のカギ
if (key[i][j] & 2) {
C = "";
int x = i;
while (x < H && S[x][j] == '.') {
C += 'a';
++x;
}
}
cout << R << ' ' << C << '\n';
}
return 0;
}