結果

問題 No.455 冬の大三角
ユーザー hanorver
提出日時 2016-12-06 00:09:44
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 1,382 bytes
コンパイル時間 675 ms
コンパイル使用メモリ 74,600 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-06-29 21:01:44
合計ジャッジ時間 2,512 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 54
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>

int main() {
    int h, w;

    std::cin >> h >> w;

    std::vector<std::string> v(h);

    for (int i = 0; i < h; i++) {
        std::cin >> v[i];
    }

    std::vector<int> count(w);

    for (int i = 0; i < w; i++) {
        int c = 0;
        for (int j = 0; j < h; j++) {
            if (v[j][i] == '*') {
                c++;
            }
        }
        count[i] = c;
    }

    if (*std::max_element(count.begin(), count.end()) == 2) {
        bool change = false;
        for (int i = 0; i < w; i++) {
            if (count[i] == 2) continue;
            for (int j = 0; j < h; j++) {
                if (v[j][i] != '*') {
                    v[j][i] = '*';
                    change = true;
                    break;
                }
            }
            if (change) break;
        }
    } else {
        bool change = false;
        for (int i = 0; i < w; i++) {
            if (count[i] != 1) continue;
            for (int j = 0; j < h; j++) {
                if (v[j][i] != '*') {
                    v[j][i] = '*';
                    change = true;
                    break;
                }
            }
            if (change) break;
        }
    }

    for (int i = 0; i < h; i++) {
        std::cout << v[i] << std::endl;
    }
    
    return 0;
}
0