結果
| 問題 | No.3804 Crossword Key Filler |
| コンテスト | |
| ユーザー |
tnakao0123
|
| 提出日時 | 2026-11-17 11:22:28 |
| 言語 | C++17 (gcc 15.3.0 + boost 1.92.0 + ACL) |
| 結果 |
AC
不安定
|
| 実行時間 | 2 ms / 2,000 ms |
| + 239µs | |
| コード長 | 2,276 bytes |
| 記録 | |
| コンパイル時間 | 500 ms |
| コンパイル使用メモリ | 88,520 KB |
| 実行使用メモリ | 9,920 KB |
| 最終ジャッジ日時 | 2026-11-17 11:22:32 |
| 合計ジャッジ時間 | 4,233 ms |
|
ジャッジサーバーID (参考情報) |
judge4_0 / judge2_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 50 |
ソースコード
/* -*- coding: utf-8 -*-
*
* 3804.cc: No.3804 Crossword Key Filler - 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);
int qn;
scanf("%d", &qn);
while (qn--) {
int k, d;
char a[MAX_L + 4];
scanf("%d%d%s", &k, &d, &a), k--;
auto [yi, xi] = kps[k];
string sa(a);
if (d == 0) hfill(yi, xi, sa);
else vfill(yi, xi, sa);
printfs(h);
}
return 0;
}
tnakao0123