結果

問題 No.640 76本のトロンボーン
ユーザー PachicobuePachicobue
提出日時 2018-02-11 19:34:53
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 4 ms / 2,000 ms
コード長 4,398 bytes
コンパイル時間 2,199 ms
コンパイル使用メモリ 211,940 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-27 23:00:59
合計ジャッジ時間 2,956 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 3 ms
4,376 KB
testcase_07 AC 4 ms
4,376 KB
testcase_08 AC 4 ms
4,376 KB
testcase_09 AC 4 ms
4,376 KB
testcase_10 AC 3 ms
4,376 KB
testcase_11 AC 3 ms
4,380 KB
testcase_12 AC 3 ms
4,380 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 3 ms
4,376 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int N;
vector<vector<bool>> ok;
int yoko1(const int i)
{
    auto copy = ok;
    for (int j = 0; j < N - 1; j++) {
        if (copy[i][j]) {
            copy[i][j] = false;
        } else {
            return 0;
        }
    }
    int ans = 1;
    for (int j = 0; j < N; j++) {
        bool f = true;
        for (int i = 1; i < N - 1; i++) {
            if (not copy[i][j]) {
                f = false;
                break;
            }
        }
        if (f and (copy[0][j] or copy[N - 1][j])) {
            ans++;
        }
    }
    return ans;
}
int yoko2(const int i)
{
    auto copy = ok;
    for (int j = 1; j < N; j++) {
        if (copy[i][j]) {
            copy[i][j] = false;
        } else {
            return 0;
        }
    }
    int ans = 1;
    for (int j = 0; j < N; j++) {
        bool f = true;
        for (int i = 1; i < N - 1; i++) {
            if (not copy[i][j]) {
                f = false;
                break;
            }
        }
        if (f and (copy[0][j] or copy[N - 1][j])) {
            ans++;
        }
    }
    return ans;
}
int tate1(const int j)
{
    auto copy = ok;
    for (int i = 0; i < N - 1; i++) {
        if (copy[i][j]) {
            copy[i][j] = false;
        } else {
            return 0;
        }
    }
    int ans = 1;
    for (int i = 0; i < N; i++) {
        bool f = true;
        for (int j = 1; j < N - 1; j++) {
            if (not copy[i][j]) {
                f = false;
                break;
            }
        }
        if (f and (copy[i][0] or copy[i][N - 1])) {
            ans++;
        }
    }
    return ans;
}
int tate2(const int j)
{
    auto copy = ok;
    for (int i = 1; i < N; i++) {
        if (copy[i][j]) {
            copy[i][j] = false;
        } else {
            return 0;
        }
    }
    int ans = 1;
    for (int i = 0; i < N; i++) {
        bool f = true;
        for (int j = 1; j < N - 1; j++) {
            if (not copy[i][j]) {
                f = false;
                break;
            }
        }
        if (f and (copy[i][0] or copy[i][N - 1])) {
            ans++;
        }
    }
    return ans;
}

int YOKO1()
{
    int ans = 0;
    for (int j = 0; j < N; j++) {
        bool f = true;
        for (int i = 1; i < N - 1; i++) {
            if (not ok[i][j]) {
                f = false;
                break;
            }
        }
        if (f and (ok[0][j] or ok[N - 1][j])) {
            ans++;
        }
    }
    return ans;
}
int YOKO2()
{
    int ans = 0;
    for (int j = 0; j < N; j++) {
        bool f = true;
        for (int i = 1; i < N - 1; i++) {
            if (not ok[i][j]) {
                f = false;
                break;
            }
        }
        if (f and (ok[0][j] or ok[N - 1][j])) {
            ans++;
        }
    }
    return ans;
}
int TATE1()
{
    int ans = 0;
    for (int i = 0; i < N; i++) {
        bool f = true;
        for (int j = 1; j < N - 1; j++) {
            if (not ok[i][j]) {
                f = false;
                break;
            }
        }
        if (f and (ok[i][0] or ok[i][N - 1])) {
            ans++;
        }
    }
    return ans;
}
int TATE2()
{
    int ans = 0;
    for (int i = 0; i < N; i++) {
        bool f = true;
        for (int j = 1; j < N - 1; j++) {
            if (not ok[i][j]) {
                f = false;
                break;
            }
        }
        if (f and (ok[i][0] or ok[i][N - 1])) {
            ans++;
        }
    }
    return ans;
}


int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N;
    ok.resize(N, vector<bool>(N));
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            char c;
            cin >> c;
            ok[i][j] = c == '.';
        }
    }
    bool spe = true;
    for (int i = 0; i < N; i++) {
        if (not ok[i][0]) {
            spe = false;
break;
        }
        if (not ok[i][N - 1]) {
            spe = false;
break;        
}
        if (not ok[0][i]) {
            spe = false;
break;        
}
        if (not ok[N - 1][i]) {
            spe = false;
break;        
}
    }
    int ans = max({TATE1(), TATE2(), YOKO1(), YOKO2()});
    if (spe) {
        ans = max(ans, 4);
    }
    for (int i = 0; i < N; i++) {
        ans = max({ans, tate1(i), tate2(i), yoko1(i), yoko2(i)});
    }
    cout << ans << endl;

    return 0;
}
0