結果

問題 No.2375 watasou and hibit's baseball
ユーザー tnakao0123tnakao0123
提出日時 2023-07-11 11:21:21
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 79 ms / 2,000 ms
コード長 1,303 bytes
コンパイル時間 378 ms
コンパイル使用メモリ 42,904 KB
実行使用メモリ 15,520 KB
最終ジャッジ日時 2023-10-11 02:46:30
合計ジャッジ時間 4,464 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,352 KB
testcase_01 AC 1 ms
4,356 KB
testcase_02 AC 1 ms
4,356 KB
testcase_03 AC 13 ms
8,384 KB
testcase_04 AC 1 ms
4,356 KB
testcase_05 AC 2 ms
4,360 KB
testcase_06 AC 79 ms
15,520 KB
testcase_07 AC 2 ms
4,356 KB
testcase_08 AC 3 ms
4,352 KB
testcase_09 AC 2 ms
4,356 KB
testcase_10 AC 1 ms
4,356 KB
testcase_11 AC 2 ms
4,356 KB
testcase_12 AC 12 ms
8,620 KB
testcase_13 AC 5 ms
4,352 KB
testcase_14 AC 2 ms
4,352 KB
testcase_15 AC 7 ms
4,604 KB
testcase_16 AC 5 ms
4,356 KB
testcase_17 AC 6 ms
5,608 KB
testcase_18 AC 1 ms
4,352 KB
testcase_19 AC 2 ms
4,352 KB
testcase_20 AC 1 ms
4,352 KB
testcase_21 AC 6 ms
5,504 KB
testcase_22 AC 1 ms
4,356 KB
testcase_23 AC 5 ms
4,356 KB
testcase_24 AC 5 ms
4,356 KB
testcase_25 AC 1 ms
4,356 KB
testcase_26 AC 21 ms
13,964 KB
testcase_27 AC 28 ms
13,236 KB
testcase_28 AC 29 ms
13,828 KB
testcase_29 AC 34 ms
14,900 KB
testcase_30 AC 40 ms
15,284 KB
testcase_31 AC 34 ms
9,248 KB
testcase_32 AC 42 ms
10,400 KB
testcase_33 AC 30 ms
13,340 KB
testcase_34 AC 24 ms
12,992 KB
testcase_35 AC 40 ms
14,700 KB
testcase_36 AC 35 ms
14,048 KB
testcase_37 AC 23 ms
11,904 KB
testcase_38 AC 6 ms
7,408 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 2375.cc:  No.2375 watasou and hibit's baseball - yukicoder
 */

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

/* constant */

const int MAX_N = 14;
const int NBITS = 1 << MAX_N;

/* typedef */

/* global variables */

int xs[MAX_N], ys[MAX_N], ks[MAX_N];
int dp[NBITS][MAX_N][MAX_N];

/* subroutines */

inline int mdist(int i, int j) {
  return abs(xs[j] - xs[i]) + abs(ys[j] - ys[i]);
}

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

/* main */

int main() {
  int n, a, b;
  scanf("%d%d%d", &n, &a, &b);
  for (int i = 0; i < n; i++) scanf("%d%d%d", xs + i, ys + i, ks + i);

  for (int i = 0, bi = 1; i < n; i++, bi <<= 1)
    for (int j = 0, bj = 1; j < n; j++, bj <<= 1)
      if (i != j && (mdist(j, i) >= a || abs(ks[j] - ks[i]) >= b))
	dp[bi | bj][i][j] = 2;

  int nbits = 1 << n, maxd = 1;
  for (int bits = 0; bits < nbits; bits++)
    for (int i = 0, bi = 1; i < n; i++, bi <<= 1)
      for (int j = 0, bj = 1; j < n; j++, bj <<= 1)
	if (dp[bits][i][j] > 0) {
	  setmax(maxd, dp[bits][i][j]);
	  for (int k = 0, bk = 1; k < n; k++, bk <<= 1)
	    if (! (bits & bk) &&
		(mdist(k, j) + mdist(k, i) >= a || abs(ks[k] - ks[j]) >= b))
	      setmax(dp[bits | bk][j][k], dp[bits][i][j] + 1);
	}

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