結果

問題 No.488 四角関係
ユーザー mosmos_21mosmos_21
提出日時 2017-06-22 11:17:25
言語 Java21
(openjdk 21)
結果
AC  
実行時間 231 ms / 5,000 ms
コード長 1,089 bytes
コンパイル時間 2,192 ms
コンパイル使用メモリ 76,928 KB
実行使用メモリ 58,068 KB
最終ジャッジ日時 2024-04-10 08:38:17
合計ジャッジ時間 6,663 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 168 ms
57,028 KB
testcase_01 AC 181 ms
56,796 KB
testcase_02 AC 182 ms
57,068 KB
testcase_03 AC 148 ms
56,052 KB
testcase_04 AC 179 ms
56,504 KB
testcase_05 AC 199 ms
57,220 KB
testcase_06 AC 188 ms
56,900 KB
testcase_07 AC 231 ms
57,392 KB
testcase_08 AC 228 ms
58,068 KB
testcase_09 AC 118 ms
54,136 KB
testcase_10 AC 139 ms
54,148 KB
testcase_11 AC 123 ms
54,336 KB
testcase_12 AC 141 ms
54,136 KB
testcase_13 AC 139 ms
54,216 KB
testcase_14 AC 130 ms
54,056 KB
testcase_15 AC 117 ms
54,132 KB
testcase_16 AC 122 ms
54,260 KB
testcase_17 AC 126 ms
53,836 KB
testcase_18 AC 126 ms
54,056 KB
testcase_19 AC 110 ms
52,996 KB
testcase_20 AC 117 ms
53,852 KB
testcase_21 AC 113 ms
54,052 KB
testcase_22 AC 102 ms
52,524 KB
testcase_23 AC 105 ms
52,812 KB
testcase_24 AC 120 ms
53,836 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

class Main {
    static Scanner in = new Scanner(System.in);
    static boolean[][] r;

    public static void main(String[] args) {
        int N = in.nextInt(), M = in.nextInt();
        r = new boolean[N][N];
        for (int i = 0; i < M; i++) {
            int a = in.nextInt(), b = in.nextInt();
            r[a][b] = r[b][a] = true;
        }
        int sum = 0;
        for (int a = 0; a < N - 3; a++) {
            for (int b = a + 1; b < N - 2; b++) {
                for (int c = b + 1; c < N - 1; c++) {
                    for (int d = c + 1; d < N; d++) {
                        sum += f(new int[] { a, b, c, d });
                    }
                }
            }
        }
        System.out.println(sum);
    }

    public static int f(int[] n) {
        boolean b = true;
        for(int i = 0; i < 4; i++){
            int a = 0;
            for(int j = 0; j < 4; j++){
                if(i == j) continue;
                if(r[n[i]][n[j]]) a++;
            }
            if(a != 2) b = false;
        }
        return b ? 1 : 0;
    }
}
0