結果

問題 No.488 四角関係
ユーザー kentahamakentahama
提出日時 2017-03-04 17:30:50
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,283 bytes
コンパイル時間 1,554 ms
コンパイル使用メモリ 170,436 KB
実行使用メモリ 4,500 KB
最終ジャッジ日時 2023-09-05 05:28:46
合計ジャッジ時間 9,341 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep2(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()

typedef long long ll;
typedef pair<int, int> P;

int N, M;
vector<P> ps;

bool ps_have(int a, int b) {
  for(auto p : ps) {
    if(p.first == a && p.second == b ||
       p.first == b && p.second == a) {
      return true;
    }
  }
  return false;
}

bool loop(int i, int j, int k, int l) {
  return
    ps_have(i, j) &&
    ps_have(j, k) &&
    ps_have(k, l) &&
    ps_have(l, i);
}

bool square(int i, int j, int k, int l) {
  return
    loop(i, j, k, l) &&
    !ps_have(i, k) &&
    !ps_have(j, l);
}

void solve() {
  int cnt = 0;
  cin >> N >> M;
  rep(i, M) {
    int a, b;
    cin >> a >> b;
    ps.push_back(P(a, b));
  }
  rep(i, N) {
    rep2(j, i + 1, N) {
      rep2(k, j + 1, N) {
        rep2(l, k + 1, N) {
          // ls = {(i, j, k, l), (i, j, l, k), (i, k, l, j)}
          if (square(i, j, k, l) ||
              square(i, j, l, k) ||
              square(i, k, l, j)) {
            cnt ++;
          }
        }
      }
    }
  }
  cout << cnt << endl;
}

int main() {
  solve();
  return 0;
}
0