結果

問題 No.86 TVザッピング(2)
ユーザー krotonkroton
提出日時 2014-12-05 00:56:01
言語 C++11
(gcc 13.3.0)
結果
WA  
実行時間 -
コード長 2,991 bytes
コンパイル時間 608 ms
コンパイル使用メモリ 58,284 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-06-11 15:40:04
合計ジャッジ時間 1,614 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 26 WA * 4
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
using namespace std;

int H, W;
string mat[111];
int acc_x[111][111], acc_y[111][111];

int get_y(int x, int yt, int ys){
    if(ys > yt)return 100000;
    return acc_y[x][yt+1] - acc_y[x][ys];
}

int get_x(int y, int xt, int xs){
    if(xs > xt)return 100000;
    return acc_x[y][xt+1] - acc_x[y][xs];
}

string solve(){
    int top = 111, bot = -1, lef = 111, rig = -1;
    int tot = 0;
    
    for(int y=0;y<H;y++)for(int x=0;x<W;x++){
        if(mat[y][x] == '.'){
            top = min(top, y);
            bot = max(bot, y);
            lef = min(lef, x);
            rig = max(rig, x);
            
            ++tot;
        }
    }
    
    if(bot - top < 1 || rig - lef < 1){
        return "NO";
    }
    
    for(int y=0;y<H;y++){
        for(int x=0;x<W;x++)acc_x[y][x+1] = acc_x[y][x] + (mat[y][x] == '.');
    }
    for(int x=0;x<W;x++){
        for(int y=0;y<H;y++)acc_y[x][y+1] = acc_y[x][y] + (mat[y][x] == '.');
    }
    
    // 4角形
    {
        int sum = 0;
        sum += get_x(top, rig, lef);
        sum += get_x(bot, rig, lef);
        sum += get_y(lef, bot, top);
        sum += get_y(rig, bot, top);
        sum -= 4;
        
        if(sum == tot)return "YES";
    }
    
    // 6角形
    for(int y=0;y<H;y++)for(int x=0;x<W;x++)if(mat[y][x] == '.'){
        {
            int sum = 0;
            sum += get_x(top, rig, x);
            sum += get_x(bot, rig, lef);
            sum += get_y(lef, bot, y);
            sum += get_y(rig, bot, top);
            sum += get_y(x, y, top);
            sum += get_x(y, x, lef);
            sum -= 6;
            
            if(sum == tot)return "YES";
        }
        {
            int sum = 0;
            sum += get_x(top, x, lef);
            sum += get_x(bot, rig, lef);
            sum += get_y(lef, bot, top);
            sum += get_y(rig, bot, y);
            sum += get_y(x, y, top);
            sum += get_x(y, rig, x);
            sum -= 6;
            
            if(sum == tot)return "YES";
        }
        {
            int sum = 0;
            sum += get_x(top, rig, lef);
            sum += get_x(bot, rig, x);
            sum += get_y(lef, y, top);
            sum += get_y(rig, bot, top);
            sum += get_y(x, bot, y);
            sum += get_x(y, x, lef);
            sum -= 6;
            
            if(sum == tot)return "YES";
        }
        {
            int sum = 0;
            sum += get_x(top, rig, lef);
            sum += get_x(bot, x, lef);
            sum += get_y(lef, bot, top);
            sum += get_y(rig, y, top);
            sum += get_y(x, bot, y);
            sum += get_x(y, rig, x);
            sum -= 6;
            
            if(sum == tot)return "YES";
        }
    }
    
    return "NO";
}

int main(){
    cin >> H >> W;
    for(int i=0;i<H;i++)cin >> mat[i];
    
    cout << solve() << endl;
    return 0;
}
0