結果
問題 | No.488 四角関係 |
ユーザー |
![]() |
提出日時 | 2017-06-22 11:17:25 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 255 ms / 5,000 ms |
コード長 | 1,089 bytes |
コンパイル時間 | 2,264 ms |
コンパイル使用メモリ | 77,364 KB |
実行使用メモリ | 46,360 KB |
最終ジャッジ日時 | 2024-10-02 10:19:45 |
合計ジャッジ時間 | 7,132 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 22 |
ソースコード
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; } }