結果

問題 No.86 TVザッピング(2)
ユーザー krotonkroton
提出日時 2014-12-05 01:00:23
言語 C++11
(gcc 11.4.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 3,146 bytes
コンパイル時間 489 ms
コンパイル使用メモリ 58,040 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-02 08:48:09
合計ジャッジ時間 1,757 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 WA -
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 3 ms
4,376 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 1 ms
4,376 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 1 ms
4,380 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 2 ms
4,380 KB
testcase_25 AC 1 ms
4,380 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 2 ms
4,376 KB
testcase_28 AC 2 ms
4,380 KB
testcase_29 AC 2 ms
4,380 KB
testcase_30 AC 1 ms
4,376 KB
testcase_31 AC 2 ms
4,380 KB
testcase_32 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
using namespace std;

const int INF = 100000;

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 INF;

    int cnt = acc_y[x][yt+1] - acc_y[x][ys];
    if(cnt != yt - ys + 1)return INF;

    return cnt;
}

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

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