結果

問題 No.359 門松行列
ユーザー LeonardoneLeonardone
提出日時 2016-04-18 01:12:26
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 2,612 bytes
コンパイル時間 425 ms
コンパイル使用メモリ 56,216 KB
実行使用メモリ 13,760 KB
最終ジャッジ日時 2024-04-15 03:13:23
合計ジャッジ時間 4,899 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
13,760 KB
testcase_01 AC 1 ms
6,944 KB
testcase_02 AC 1 ms
6,940 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 1 ms
6,940 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 1 ms
6,940 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 11 ms
6,944 KB
testcase_09 AC 82 ms
6,944 KB
testcase_10 AC 879 ms
6,944 KB
testcase_11 TLE -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

// yukicoder My Practice
// author: Leonardone @ NEETSDKASU

#include <iostream>

using namespace std;

int isKadomatsuRetsu(int a1, int a2, int a3) {
    return a1 != a3 && ((a2 > a1 && a2 > a3) || (a2 < a1 && a2 < a3));
}

int checkNotKadomatsuRetsu(int a1, int a2, int a3) {
    if (a1 > 0 && a2 > 0 && a1 == a2) return !0;
    if (a1 > 0 && a3 > 0 && a1 == a3) return !0;
    if (a2 > 0 && a3 > 0 && a2 == a3) return !0;
    if (a1 * a2 * a3 == 0) return 0;
    return !isKadomatsuRetsu(a1, a2, a3);
}

int checkNotKadomatuGyoretsu(int a[3][3]) {
    if (checkNotKadomatsuRetsu(a[0][0], a[0][1], a[0][2])) return 1;
    if (checkNotKadomatsuRetsu(a[1][0], a[1][1], a[1][2])) return 1;
    if (checkNotKadomatsuRetsu(a[2][0], a[2][1], a[2][2])) return 1;
    if (checkNotKadomatsuRetsu(a[0][0], a[1][0], a[2][0])) return 1;
    if (checkNotKadomatsuRetsu(a[0][1], a[1][1], a[2][1])) return 1;
    if (checkNotKadomatsuRetsu(a[0][2], a[1][2], a[2][2])) return 1;
    if (checkNotKadomatsuRetsu(a[0][0], a[1][1], a[2][2])) return 1;
    if (checkNotKadomatsuRetsu(a[0][2], a[1][1], a[2][0])) return 1;
    return 0;
}

int isKadomatsuGyoretsu(int a[3][3]) {
    if (!isKadomatsuRetsu(a[0][0], a[0][1], a[0][2])) return 0;
    if (!isKadomatsuRetsu(a[1][0], a[1][1], a[1][2])) return 0;
    if (!isKadomatsuRetsu(a[2][0], a[2][1], a[2][2])) return 0;
    if (!isKadomatsuRetsu(a[0][0], a[1][0], a[2][0])) return 0;
    if (!isKadomatsuRetsu(a[0][1], a[1][1], a[2][1])) return 0;
    if (!isKadomatsuRetsu(a[0][2], a[1][2], a[2][2])) return 0;
    if (!isKadomatsuRetsu(a[0][0], a[1][1], a[2][2])) return 0;
    if (!isKadomatsuRetsu(a[0][2], a[1][1], a[2][0])) return 0;
    return !0;
}


int main() {
    
    int t;
    
    cin >> t;
    
    for (int i = 0; i < t; i++) {
        int l, k;
        int a[3][3];
        int xy[2][2];
        
        k = 0;
        cin >> l;
        for (int y = 0; y < 3; y++)
            for (int x = 0; x < 3; x++) {
                cin >> a[y][x];
                if (a[y][x] == 0) {
                    xy[k][0] = y;
                    xy[k][1] = x;
                    k++;
                }
            }
        
        if (checkNotKadomatuGyoretsu(a)) {
            cout << "0" << endl;
            continue;
        }
        
        int ans = 0;
        int i1 = xy[0][0], j1 = xy[0][1];
        int i2 = xy[1][0], j2 = xy[1][1];
        
        for (int j = l - 1; j > 0; j--) {
            a[i1][j1] = j;
            a[i2][j2] = l - j;
            if (isKadomatsuGyoretsu(a)) ans++;
        }
        
        cout << ans << endl;
    }
    
    return 0;
}
0