結果

問題 No.488 四角関係
コンテスト
ユーザー te-sh
提出日時 2017-12-11 17:19:31
言語 D
(dmd 2.112.0)
コンパイル:
dmd -fPIE -m64 -w -wi -O -release -inline -I/opt/dmd/src/druntime/import/ -I/opt/dmd/src/phobos -L-L/opt/dmd/linux/lib64/ -fPIC _filename_
実行:
./Main
結果
AC  
実行時間 589 ms / 5,000 ms
コード長 712 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 590 ms
コンパイル使用メモリ 87,040 KB
実行使用メモリ 7,716 KB
最終ジャッジ日時 2026-03-05 17:58:56
合計ジャッジ時間 4,270 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 22
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

import std.algorithm, std.conv, std.range, std.stdio, std.string;

void main()
{
  auto rd = readln.split.to!(int[]), n = rd[0], m = rd[1];

  auto g = new bool[][](n, n);
  foreach (i; 0..m) {
    auto rd2 = readln.split.to!(int[]), a = rd2[0], b = rd2[1];
    g[a][b] = g[b][a] = true;
  }

  auto isSquare(int[] e)
  {
    do {
      if (g[e[0]][e[1]] && g[e[1]][e[2]] && g[e[2]][e[3]] && g[e[3]][e[0]] &&
          !g[e[0]][e[2]] && !g[e[1]][e[3]])
        return true;
    } while (e.nextPermutation);
    return false;
  }

  auto ans = 0;
  foreach (e1; 0..n)
    foreach (e2; e1+1..n)
      foreach (e3; e2+1..n)
        foreach (e4; e3+1..n)
          ans += isSquare([e1,e2,e3,e4]);

  writeln(ans);
}
0