結果

問題 No.1792 科学の甲子園
ユーザー tnakao0123tnakao0123
提出日時 2021-12-24 14:13:37
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 21 ms / 4,000 ms
コード長 1,398 bytes
コンパイル時間 286 ms
コンパイル使用メモリ 44,368 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-17 18:42:09
合計ジャッジ時間 1,622 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 1792.cc:  No.1792 科学の甲子園 - yukicoder
 */

#include<cstdio>
#include<cstring>
#include<algorithm>
 
using namespace std;

/* constant */

const int MAX_N = 10000;
const int M = 6;
const int MBITS = 1 << M;
const int MMSK = MBITS - 1;
const int K = 4;

/* typedef */

typedef long long ll;

/* global variables */

int ps[MAX_N][M];
ll sps[MBITS], dp[2][K + 1][MBITS];

/* subroutines */

inline void setmax(ll &a, ll b) { if (a < b) a = b; }

/* main */

int main() {
  int n;
  scanf("%d", &n);

  for (int i = 0; i < n; i++)
    for (int j = 0; j < M; j++) scanf("%d", ps[i] + j);

  dp[0][0][0] = 1;
  int cur = 0, nxt = 1;

  for (int i = 0; i < n; i++) {
    for (int bits = 0; bits < MBITS; bits++) {
      ll mp = 1;
      for (int j = 0, bj = 1; j < M; j++, bj <<= 1)
	if (bits & bj) mp *= ps[i][j];
      sps[bits] = mp;
    }

    memset(dp[nxt], 0, sizeof(dp[nxt]));

    for (int k = 0; k <= K; k++)
      for (int bits = 0; bits < MBITS; bits++)
	if (dp[cur][k][bits] > 0) {
	  setmax(dp[nxt][k][bits], dp[cur][k][bits]);

	  if (k < K)
	    for (int bits1 = 1; bits1 < MBITS; bits1++)
	      if (! (bits & bits1))
		setmax(dp[nxt][k + 1][bits | bits1],
		       dp[cur][k][bits] * sps[bits1]);
	}

    swap(cur, nxt);
  }

  ll maxd = 0;
  for (int k = 0; k <= K; k++) setmax(maxd, dp[cur][k][MMSK]);

  printf("%lld\n", maxd);
  return 0;
}
0