結果

問題 No.1792 科学の甲子園
ユーザー KudeKude
提出日時 2021-12-21 09:43:27
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 3 ms / 4,000 ms
コード長 1,366 bytes
コンパイル時間 2,115 ms
コンパイル使用メモリ 199,808 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-17 18:41:37
合計ジャッジ時間 3,225 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < int(n); ++i)

int a[6][10000];
int mx1[6], mx2[6][6], mx3[6][6][6];

int main() {
  int n;
  cin >> n;
  rep(i, n) rep(s, 6) cin >> a[s][i];
  rep(s1, 6) {
    int mx = 0;
    rep(i, n) {
      int tmp = a[s1][i];
      if (tmp > mx) mx = tmp;
    }
    mx1[s1] = mx;
  }
  rep(s1, 6) rep(s2, s1) {
    int mx = 0;
    rep(i, n) {
      int tmp = a[s1][i] * a[s2][i];
      if (tmp > mx) mx = tmp;
    }
    mx2[s1][s2] = mx;
  }
  rep(s1, 6) rep(s2, s1) rep(s3, s2) {
    int mx = 0;
    rep(i, n) {
      int tmp = a[s1][i] * a[s2][i] * a[s3][i];
      if (tmp > mx) mx = tmp;
    }
    mx3[s1][s2][s3] = mx;
  }
  long long ans = 0;
  rep(s1, 6) rep(s2, s1) rep(s3, s2) rep(s4, s3) {
    long long mx = max({(long long)mx2[s1][s2] * mx2[s3][s4], (long long)mx2[s1][s3] * mx2[s2][s4], (long long)mx2[s1][s4] * mx2[s2][s3]});
    int b = 63 ^ (1 << s1) ^ (1 << s2) ^ (1 << s3) ^ (1 << s4);
    while(b) {
      int k = __builtin_ctz(b);
      mx *= mx1[k];
      b ^= 1 << k;
    }
    ans = max(ans, mx);
  }
  rep(s1, 6) rep(s2, s1) rep(s3, s2) {
    long long mx = mx3[s1][s2][s3];
    int b = 63 ^ (1 << s1) ^ (1 << s2) ^ (1 << s3);
    while(b) {
      int k = __builtin_ctz(b);
      mx *= mx1[k];
      b ^= 1 << k;
    }
    ans = max(ans, mx);
  }
  cout << ans << endl;
}
0