結果

問題 No.488 四角関係
ユーザー はむ吉🐹はむ吉🐹
提出日時 2017-02-26 13:39:22
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 204 ms / 5,000 ms
コード長 879 bytes
コンパイル時間 231 ms
コンパイル使用メモリ 10,876 KB
実行使用メモリ 8,276 KB
最終ジャッジ日時 2023-09-02 09:51:11
合計ジャッジ時間 4,377 ms
ジャッジサーバーID
(参考情報)
judge16 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 93 ms
8,156 KB
testcase_01 AC 65 ms
8,172 KB
testcase_02 AC 89 ms
8,144 KB
testcase_03 AC 39 ms
8,228 KB
testcase_04 AC 54 ms
8,160 KB
testcase_05 AC 104 ms
8,080 KB
testcase_06 AC 174 ms
8,244 KB
testcase_07 AC 179 ms
8,228 KB
testcase_08 AC 204 ms
8,268 KB
testcase_09 AC 15 ms
8,140 KB
testcase_10 AC 31 ms
8,220 KB
testcase_11 AC 16 ms
8,276 KB
testcase_12 AC 23 ms
8,136 KB
testcase_13 AC 28 ms
8,148 KB
testcase_14 AC 18 ms
8,140 KB
testcase_15 AC 17 ms
8,148 KB
testcase_16 AC 16 ms
8,132 KB
testcase_17 AC 16 ms
8,152 KB
testcase_18 AC 15 ms
8,220 KB
testcase_19 AC 16 ms
8,164 KB
testcase_20 AC 17 ms
8,088 KB
testcase_21 AC 16 ms
8,212 KB
testcase_22 AC 15 ms
8,084 KB
testcase_23 AC 17 ms
8,220 KB
testcase_24 AC 16 ms
8,096 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env python3

import itertools


def count_squares(n, x):
    def is_quad(a, b, c, d):
        if not all((x[a][b], x[b][c], x[c][d], x[d][a])):
            return False
        elif x[a][c] or x[b][d]:
            return False
        else:
            return True
    res = 0
    for v1, v2, v3, v4 in itertools.combinations(range(n), 4):
        if is_quad(v1, v2, v3, v4):
            res += 1
        elif is_quad(v1, v3, v2, v4):
            res += 1
        elif is_quad(v1, v3, v4, v2):
            res += 1
    return res


def main():
    n, m = (int(x) for x in input().split())
    adj_matrix = [[False for _ in range(n)] for _ in range(n)]
    for _ in range(m):
        a, b = (int(x) for x in input().split())
        adj_matrix[a][b] = True
        adj_matrix[b][a] = True
    print(count_squares(n, adj_matrix))


if __name__ == '__main__':
    main()
0