結果

問題 No.3804 Crossword Key Filler
ユーザー t98slider
提出日時 2026-11-14 15:37:43
言語 C++23
(gcc 15.3.0 + boost 1.92.0 + ACL)
コンパイル:
g++-15 -O2 -fplugin=/usr/lib/yukicoder/noavx512-gcc15.so -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 2 ms / 2,000 ms
+ 271µs
コード長 2,422 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 2,614 ms
コンパイル使用メモリ 354,364 KB
実行使用メモリ 9,924 KB
最終ジャッジ日時 2026-11-14 15:37:49
合計ジャッジ時間 5,970 ms
ジャッジサーバーID
(参考情報)
judge4_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 50
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include<bits/stdc++.h>
using namespace std;
using ll = long long;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin.tie(0);
    int h, w;
    cin >> h >> w;
    vector<string> A(h), B(w, string(h, '?'));
    vector<pair<int,int>> ans;
    for(int y = 0; y < h; y++){
        auto &&ss = A[y];
        cin >> ss;
        for(int i = 0; i < w; ){
            int p = i;
            while(i < w && ss[i] == ss[p]) i++;
            if(ss[p] == '#') continue;
            if(i - p >= 2) ans.emplace_back(y, p);
        }
    }
    for(int y = 0; y < h; y++){
        for(int x = 0; x < w; x++){
            B[x][y] = A[y][x];
        }
    }
    for(int x = 0; x < w; x++){
        auto &&ss = B[x];
        for(int i = 0; i < h; ){
            int p = i;
            while(i < h && ss[i] == ss[p]) i++;
            if(ss[p] == '#') continue;
            if(i - p >= 2) ans.emplace_back(p, x);
        }
    }
    sort(ans.begin(), ans.end());
    ans.erase(unique(ans.begin(), ans.end()), ans.end());

    auto add_w = [&](int y, int x, string s){
        // if(s == "-") return (x + 1 < w && A[y][x + 1] == '.' ? false : true);
        int sz = s.size();
        for(int dx = 0; dx < sz; dx++){
            if(x + dx >= w) return false;
            if(A[y][x + dx] == '#') return false;
            if(A[y][x + dx] == '.'){
                A[y][x + dx] = s[dx];
            }else{
                if(A[y][x + dx] != s[dx]) return false;
            }
        }
        if(x + sz < w && A[y][x + sz] != '#') return false;
        return true;
    };
    auto add_h = [&](int y, int x, string s){
        // if(s == "-") return (y + 1 < h && A[y + 1][x] == '.' ? false : true);
        int sz = s.size();
        for(int dy = 0; dy < sz; dy++){
            if(y + dy >= h) return false;
            if(A[y + dy][x] == '#') return false;
            if(A[y + dy][x] == '.'){
                A[y + dy][x] = s[dy];
            }else{
                if(A[y + dy][x] != s[dy]) return false;
            }
        }
        if(y + sz < h && A[y + sz][x] != '#') return false;
        return true;
    };

    int k;
    cin >> k;
    for(int i = 0; i < k; i++){
        int p, d;
        string s;
        cin >> p >> d >> s;
        auto [y, x] = ans[p - 1];
        if(d == 0) add_w(y, x, s);
        else add_h(y, x, s);
        for(auto &&ss : A) cout << ss << '\n';
    }
}
0