結果

問題 No.133 カードゲーム
ユーザー sansaquasansaqua
提出日時 2019-05-05 13:55:43
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 1,044 bytes
コンパイル時間 841 ms
コンパイル使用メモリ 73,924 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-07 03:00:40
合計ジャッジ時間 2,048 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <vector>
#include <numeric>

int main() {
  int n;
  std::cin >> n;
  
  std::vector<int> indices1(n);
  std::vector<int> indices2(n);
  std::iota(indices1.begin(), indices1.end(), 0);

  std::vector<int> cardsA(n);
  std::vector<int> cardsB(n);
  for (auto& e : cardsA) {
    std::cin >> e;
  }
  for (auto& e : cardsB) {
    std::cin >> e;
  }
  
  int fact = 1;
  for (int i = 1; i <= n; i++) {
    fact *= i;
  }

  int total = fact * fact;
  int win = 0;
  do {
    std::iota(indices2.begin(), indices2.end(), 0);
    do {
      int a = 0;
      int b = 0;
      for (int i = 0; i < n; i++) {
	if (cardsA[indices1[i]] > cardsB[indices2[i]]) {
	  a++;
	} else if (cardsA[indices1[i]] < cardsB[indices2[i]]) {
	  b++;
	}
      }
      if (a > b) {
	win++;
      }
    } while (std::next_permutation(indices2.begin(), indices2.end()));
  } while (std::next_permutation(indices1.begin(), indices1.end()));

  float ans = (float) win / total;
  
  std::cout << ans << std::endl;

  return 0;
}
0