結果

問題 No.2509 Beam Shateki
ユーザー tnakao0123tnakao0123
提出日時 2023-10-20 23:22:01
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 4 ms / 2,000 ms
コード長 2,354 bytes
コンパイル時間 419 ms
コンパイル使用メモリ 45,956 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-20 23:22:05
合計ジャッジ時間 2,173 ms
ジャッジサーバーID
(参考情報)
judge11 / judge10
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 3 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 2 ms
4,348 KB
testcase_13 AC 3 ms
4,348 KB
testcase_14 AC 3 ms
4,348 KB
testcase_15 AC 3 ms
4,348 KB
testcase_16 AC 3 ms
4,348 KB
testcase_17 AC 3 ms
4,348 KB
testcase_18 AC 3 ms
4,348 KB
testcase_19 AC 4 ms
4,348 KB
testcase_20 AC 3 ms
4,348 KB
testcase_21 AC 3 ms
4,348 KB
testcase_22 AC 3 ms
4,348 KB
testcase_23 AC 3 ms
4,348 KB
testcase_24 AC 3 ms
4,348 KB
testcase_25 AC 3 ms
4,348 KB
testcase_26 AC 3 ms
4,348 KB
testcase_27 AC 3 ms
4,348 KB
testcase_28 AC 3 ms
4,348 KB
testcase_29 AC 3 ms
4,348 KB
testcase_30 AC 3 ms
4,348 KB
testcase_31 AC 3 ms
4,348 KB
testcase_32 AC 4 ms
4,348 KB
testcase_33 AC 2 ms
4,348 KB
testcase_34 AC 2 ms
4,348 KB
testcase_35 AC 2 ms
4,348 KB
testcase_36 AC 2 ms
4,348 KB
testcase_37 AC 2 ms
4,348 KB
testcase_38 AC 2 ms
4,348 KB
testcase_39 AC 2 ms
4,348 KB
testcase_40 AC 2 ms
4,348 KB
testcase_41 AC 2 ms
4,348 KB
testcase_42 AC 2 ms
4,348 KB
testcase_43 AC 3 ms
4,348 KB
testcase_44 AC 3 ms
4,348 KB
testcase_45 AC 2 ms
4,348 KB
testcase_46 AC 2 ms
4,348 KB
testcase_47 AC 3 ms
4,348 KB
testcase_48 AC 2 ms
4,348 KB
testcase_49 AC 3 ms
4,348 KB
testcase_50 AC 2 ms
4,348 KB
testcase_51 AC 2 ms
4,348 KB
testcase_52 AC 2 ms
4,348 KB
testcase_53 AC 1 ms
4,348 KB
testcase_54 AC 2 ms
4,348 KB
testcase_55 AC 2 ms
4,348 KB
testcase_56 AC 2 ms
4,348 KB
testcase_57 AC 2 ms
4,348 KB
testcase_58 AC 2 ms
4,348 KB
testcase_59 AC 1 ms
4,348 KB
testcase_60 AC 2 ms
4,348 KB
testcase_61 AC 1 ms
4,348 KB
testcase_62 AC 2 ms
4,348 KB
testcase_63 AC 2 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 2509.cc:  No.2509 Beam Shateki - yukicoder
 */

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

/* constant */

const int MAX_H = 100;
const int MAX_W = 100;

/* typedef */

/* global variables */

int as[MAX_H][MAX_W];
int hs[MAX_H], vs[MAX_W], ps[MAX_H + MAX_W], qs[MAX_H + MAX_W];

/* subroutines */

/* main */

int main() {
  int h, w;
  scanf("%d%d", &h, &w);
  int hw = h + w - 1;

  for (int i = 0; i < h; i++)
    for (int j = 0; j < w; j++) {
      scanf("%d", as[i] + j);
      hs[i] += as[i][j];
      vs[j] += as[i][j];
      ps[i + j] += as[i][j];
      qs[i + (w - 1 - j)] += as[i][j];
    }

  int maxs = 0;

  for (int i = 0; i < h; i++) {
    maxs = max(maxs, hs[i]);
    for (int i1 = i + 1; i1 < h; i1++)
      maxs = max(maxs, hs[i] + hs[i1]);
    for (int j = 0; j < w; j++)
      maxs = max(maxs, hs[i] + vs[j] - as[i][j]);
    for (int d = 0; d < hw; d++) {
      int j = d - i;
      maxs = max(maxs, hs[i] + ps[d] - ((j >= 0 && j < w) ? as[i][j] : 0));
    }
    for (int e = 0; e < hw; e++) {
      int j = i + w - 1 - e;
      maxs = max(maxs, hs[i] + qs[e] - ((j >= 0 && j < w) ? as[i][j] : 0));
    }
  }

  for (int j = 0; j < w; j++) {
    maxs = max(maxs, vs[j]);
    for (int j1 = j + 1; j1 < w; j1++)
      maxs = max(maxs, vs[j] + vs[j1]);
    for (int d = 0; d < hw; d++) {
      int i = d - j;
      maxs = max(maxs, vs[j] + ps[d] - ((i >= 0 && i < h) ? as[i][j] : 0));
    }
    for (int e = 0; e < hw; e++) {
      int i = e - (w - 1 - j);
      maxs = max(maxs, vs[j] + qs[e] - ((i >= 0 && i < h) ? as[i][j] : 0));
    }
  }

  for (int d = 0; d < hw; d++) {
    maxs = max(maxs, ps[d]);
    for (int d1 = d + 1; d1 < hw; d1++)
      maxs = max(maxs, ps[d] + ps[d1]);
    for (int e = 0; e < hw; e++) {
      // i+j=d, i+(w-1-j)=e -> 2i+(w-1)=d+e -> 2i=d+e-(w-1) -> i=(d+e-(w-1))/2
      // j = d-i=d-(d+e-(w-1))/2=(d-e+(w-1))/2
      int i2 = (d + e - (w - 1));
      if (! (i2 & 1)) {
	int i = i2 / 2, j = d - i;
	int aij = (i >= 0 && i < h && j >= 0 && j < w) ? as[i][j] : 0;
	maxs = max(maxs, ps[d] + qs[e] - aij);
      }
      else
	maxs = max(maxs, ps[d] + qs[e]);
    }
  }

  for (int e = 0; e < hw; e++) {
    maxs = max(maxs, qs[e]);
    for (int e1 = e + 1; e1 < hw; e1++)
      maxs = max(maxs, qs[e] + qs[e1]);
  }

  printf("%d\n", maxs);

  return 0;
}
0