結果

問題 No.459 C-VS for yukicoder
ユーザー kimiyuki
提出日時 2016-12-10 09:10:55
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 15 ms / 2,000 ms
コード長 1,275 bytes
コンパイル時間 470 ms
コンパイル使用メモリ 54,508 KB
実行使用メモリ 6,824 KB
最終ジャッジ日時 2024-11-29 00:30:32
合計ジャッジ時間 3,126 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 58
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <vector>
#include <array>
#define repeat(i,n) for (int i = 0; (i) < int(n); ++(i))
using namespace std;
int main() {
    // input
    int h, w, n; scanf("%d%d%d", &h, &w, &n);
    vector<int> a(w);
    repeat (y,h) repeat (x,w) {
        char c; scanf(" %c", &c);
        if (c =='#') a[x] += 1;
    }
    vector<int> c(n);
    vector<vector<int> > c_inv(w-2);
    repeat (i,n) {
        scanf("%d", &c[i]);
        c_inv[c[i]].push_back(i);
    }
    // solve
    vector<array<int,3> > b(n);
    repeat (x,w-2) {
        for (int i : c_inv[x]) {
            repeat (dx,3) {
                if (a[x + dx]) {
                    a[x + dx] -= 1;
                    b[i][dx] += 1;
                    break;
                }
            }
        }
    }
    repeat (x,w) {
        repeat (dx,3) if (0 <= x-dx and x-dx < w-2) {
            for (int i : c_inv[x-dx]) {
                while (a[x] and b[i][dx] < 3) {
                    a[x] -= 1;
                    b[i][dx] += 1;
                }
            }
        }
    }
    // output
    for (auto & it : b) {
        repeat (y,3) {
            repeat (x,3) {
                printf("%c", 3-y-1 < it[x] ? '#' : '.');
            }
            printf("\n");
        }
    }
    return 0;
}
0