結果

問題 No.488 四角関係
ユーザー くれちーくれちー
提出日時 2017-02-25 10:31:56
言語 C90
(gcc 11.4.0)
結果
AC  
実行時間 136 ms / 5,000 ms
コード長 1,419 bytes
コンパイル時間 236 ms
コンパイル使用メモリ 26,724 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-02 07:58:32
合計ジャッジ時間 2,427 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 64 ms
4,376 KB
testcase_01 AC 40 ms
4,376 KB
testcase_02 AC 58 ms
4,380 KB
testcase_03 AC 20 ms
4,376 KB
testcase_04 AC 31 ms
4,376 KB
testcase_05 AC 72 ms
4,380 KB
testcase_06 AC 129 ms
4,380 KB
testcase_07 AC 136 ms
4,380 KB
testcase_08 AC 128 ms
4,376 KB
testcase_09 AC 0 ms
4,376 KB
testcase_10 AC 13 ms
4,380 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 6 ms
4,380 KB
testcase_13 AC 11 ms
4,376 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 0 ms
4,380 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 1 ms
4,380 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 1 ms
4,376 KB
testcase_22 AC 1 ms
4,376 KB
testcase_23 AC 1 ms
4,376 KB
testcase_24 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#include <math.h>
#define rep(i, n) for (i = 0; i < n; i++)
#define rrep(i, n) for (i = n; i >= 0; i--)
#define max(a, b) (a > b ? a : b)
#define min(a, b) (a < b ? a : b)
typedef long long ll;

bool graph[50][50];

int cntEdge(int a, int b, int c, int d, int x) {
    int i, cnt = 0;
    if (a != x && graph[a][x]) cnt++;
    if (b != x && graph[b][x]) cnt++;
    if (c != x && graph[c][x]) cnt++;
    if (d != x && graph[d][x]) cnt++;
    return cnt;
}

bool isSquare(int a, int b, int c, int d) {
    int ae = cntEdge(a, b, c, d, a);
    int be = cntEdge(a, b, c, d, b);
    int ce = cntEdge(a, b, c, d, c);
    int de = cntEdge(a, b, c, d, d);
    return ae == 2 && be == 2 && ce == 2 && de == 2;
}

int main() {
    int n, m;
    scanf("%d %d", &n, &m);

    int i, j, k, l;
    rep(i, m) {
        int a, b;
        scanf("%d %d", &a, &b);
        graph[a][b] = true;
        graph[b][a] = true;
    }

    int ans = 0;
    rep(i, n) rep(j, n) {
        while (i == j) j++;
        if (j >= n) break;
        rep(k, n) {
            while (i == k || j == k) k++;
            if (k >= n) break;
            rep(l, n) {
                while (i == l || j == l || k == l) l++;
                if (l >= n) break;
                if (isSquare(i, j, k, l)) ans++;
            }
        }
    }
    printf("%d\n", ans / 24);
    return 0;
}
0