結果
| 問題 | No.3803 Crossword Key Checker |
| コンテスト | |
| ユーザー |
tnakao0123
|
| 提出日時 | 2026-11-17 11:16:46 |
| 言語 | C++17 (gcc 15.3.0 + boost 1.92.0 + ACL) |
| 結果 |
AC
不安定
|
| 実行時間 | 2 ms / 2,000 ms |
| + 549µs | |
| コード長 | 2,378 bytes |
| 記録 | |
| コンパイル時間 | 499 ms |
| コンパイル使用メモリ | 88,564 KB |
| 実行使用メモリ | 9,924 KB |
| 最終ジャッジ日時 | 2026-11-17 11:16:50 |
| 合計ジャッジ時間 | 3,488 ms |
|
ジャッジサーバーID (参考情報) |
judge3_0 / judge1_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 47 |
ソースコード
/* -*- coding: utf-8 -*-
*
* 3803.cc: No.3803 Crossword Key Checker - 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_K = 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];
string rs[MAX_K], cs[MAX_K];
/* 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;
}
/* main */
int main() {
int h, w;
scanf("%d%d", &h, &w);
for (int i = 0; i < h; i++) scanf("%s", fs[i]);
int k;
scanf("%d", &k);
for (int i = 0; i < k; i++) {
char r[MAX_W + 4], c[MAX_H + 4];
scanf("%s%s", r, c);
rs[i] = string(r), cs[i] = string(c);
}
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);
//if (k != (int)kps.size()) { puts("No"); return 0; }
for (int i = 0; i < k; i++) {
auto [yi, xi] = kps[i];
if (! hfill(yi, xi, rs[i]) || ! vfill(yi, xi, cs[i])) {
puts("No"); return 0;
}
}
puts("Yes");
return 0;
}
tnakao0123