結果

問題 No.2509 Beam Shateki
ユーザー Astral__Astral__
提出日時 2023-10-20 21:55:23
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,964 ms / 2,000 ms
コード長 8,138 bytes
コンパイル時間 2,729 ms
コンパイル使用メモリ 219,016 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-20 21:56:43
合計ジャッジ時間 56,597 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 277 ms
4,348 KB
testcase_04 AC 277 ms
4,348 KB
testcase_05 AC 276 ms
4,348 KB
testcase_06 AC 303 ms
4,348 KB
testcase_07 AC 276 ms
4,348 KB
testcase_08 AC 277 ms
4,348 KB
testcase_09 AC 303 ms
4,348 KB
testcase_10 AC 277 ms
4,348 KB
testcase_11 AC 276 ms
4,348 KB
testcase_12 AC 287 ms
4,348 KB
testcase_13 AC 1,925 ms
4,348 KB
testcase_14 AC 1,934 ms
4,348 KB
testcase_15 AC 1,964 ms
4,348 KB
testcase_16 AC 1,957 ms
4,348 KB
testcase_17 AC 1,952 ms
4,348 KB
testcase_18 AC 1,953 ms
4,348 KB
testcase_19 AC 1,938 ms
4,348 KB
testcase_20 AC 1,918 ms
4,348 KB
testcase_21 AC 1,915 ms
4,348 KB
testcase_22 AC 1,912 ms
4,348 KB
testcase_23 AC 1,916 ms
4,348 KB
testcase_24 AC 1,918 ms
4,348 KB
testcase_25 AC 1,926 ms
4,348 KB
testcase_26 AC 1,908 ms
4,348 KB
testcase_27 AC 1,914 ms
4,348 KB
testcase_28 AC 1,914 ms
4,348 KB
testcase_29 AC 1,897 ms
4,348 KB
testcase_30 AC 1,917 ms
4,348 KB
testcase_31 AC 1,920 ms
4,348 KB
testcase_32 AC 1,919 ms
4,348 KB
testcase_33 AC 47 ms
4,348 KB
testcase_34 AC 491 ms
4,348 KB
testcase_35 AC 954 ms
4,348 KB
testcase_36 AC 257 ms
4,348 KB
testcase_37 AC 34 ms
4,348 KB
testcase_38 AC 174 ms
4,348 KB
testcase_39 AC 260 ms
4,348 KB
testcase_40 AC 545 ms
4,348 KB
testcase_41 AC 9 ms
4,348 KB
testcase_42 AC 345 ms
4,348 KB
testcase_43 AC 1,266 ms
4,348 KB
testcase_44 AC 1,506 ms
4,348 KB
testcase_45 AC 226 ms
4,348 KB
testcase_46 AC 457 ms
4,348 KB
testcase_47 AC 1,368 ms
4,348 KB
testcase_48 AC 353 ms
4,348 KB
testcase_49 AC 776 ms
4,348 KB
testcase_50 AC 817 ms
4,348 KB
testcase_51 AC 64 ms
4,348 KB
testcase_52 AC 591 ms
4,348 KB
testcase_53 AC 3 ms
4,348 KB
testcase_54 AC 3 ms
4,348 KB
testcase_55 AC 3 ms
4,348 KB
testcase_56 AC 3 ms
4,348 KB
testcase_57 AC 3 ms
4,348 KB
testcase_58 AC 3 ms
4,348 KB
testcase_59 AC 3 ms
4,348 KB
testcase_60 AC 3 ms
4,348 KB
testcase_61 AC 3 ms
4,348 KB
testcase_62 AC 3 ms
4,348 KB
testcase_63 AC 3 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#define PPque priority_queue<tuple<ll, ll, ll>, vector<tuple<ll, ll, ll>>, greater<tuple<ll, ll, ll>>>
#define Pque  priority_queue<pair<ll, ll>, vector<pair<ll, ll>>, greater<pair<ll, ll>>>
#define pque priority_queue<ll, vector<ll>, greater<ll>>
#define umap unordered_map
#define uset unordered_set
#define rep(i, s, f) for(ll i = s; i <= f; i++)
#define per(i, s, f) for(ll i = s; i >= f; i--)
#define all0(x) (x).begin() ,(x).end()
#define all(x) (x).begin() + 1, (x).end()
#define vvvvl vector<vvvl>
#define vvvi vector<vector<vector<int>>>
#define vvvl vector<vector<vector<ll>>>
#define vvvc vector<vector<vector<char>>>
#define vvvd vector<vector<vector<double>>>
#define vvvm vector<vector<vector<mint>>>
#define vvi vector<vector<int>>
#define vvl vector<vector<ll>>
#define vvs vector<vector<string>>
#define vvc vector<vector<char>>
#define vvp vector<vector<pair<ll, ll>>>
#define vvb vector<vector<bool>>
#define vvd vector<vector<double>>
#define vvm vector<vector<mint>>
#define vp vector<pair<ll, ll>>
#define vi vector<int>
#define vl vector<ll>
#define vs vector<string>
#define vc vector<char>
#define vb vector<bool>
#define vd vector<double>
#define vm vector<mint>
#define P pair<ll, ll>
#define TU tuple<ll, ll, ll>
#define rrr(l, r) mt()%(r-l+1)+l
#define ENDL '\n'

#define ull unsigned long long
typedef long long ll;
using namespace std;

////////////////////////////////////////////////////////////////////////////////////////////////////////////
//これが本当の組み込み関数ってね(笑)

template <typename T>
T or_less(vector<T> &A, T x) { //x以下で最大要素の添字 前提: sort済み 存在しない: -1
  return distance(A.begin(), upper_bound(A.begin(), A.end(), x)-1);
}
template <typename T>
T under(vector<T> &A, T x) { //x未満の最大要素の添字 前提: sort済み 存在しない: -1
  return distance(A.begin(), lower_bound(A.begin(), A.end(), x)-1);
}
template <typename T>
T or_more(vector<T> &A, T x) { //x以上で最小要素の添字  前提: sort済み 存在しない: N .   //distanceのA.beginは添字を出すために常にA.begin() NG: A.begin() + 1
  return distance(A.begin(), lower_bound(A.begin(), A.end(), x));
}
template <typename T>
T over(vector<T> &A, T x) { //xより大きい最小要素の添字前提: sort済み 存在しない: N
  return distance(A.begin(), upper_bound(A.begin(), A.end(), x));
}
template <typename T>
vector<T> vec_shift_right(vector<T> A, ll step, ll dir = 1, ll indexed = 1) {//dir = 1 : 右シフト  dir = -1 : 左シフト
  ll N = A.size() - indexed;
  vector<T> res(N+1);
  rep(i, indexed, N) {
    ll idx = i - step * dir;
    if(idx < indexed) idx += N;
    if(idx > N) idx -= N;
    res.at(i) = A.at(idx);
  }
  return res;
}
template <typename T>
void UNIQUE(vector<T> &A) {
    sort(all0(A));
  return A.erase(unique(A.begin(), A.end()), A.end());
}
template <typename T>
void rev90(vector<vector<T>> &A, int indexed = 1) {
  reverse(A.begin() + indexed, A.end());
  int n = A.size();
  rep(i, indexed, n-1) {
   rep(j, i+1, n-1) {
      swap(A.at(i).at(j), A.at(j).at(i));
    }
  }
}
void chmin(ll &a, ll b) {
  a = min(a, b);
}
void chmax(ll &a, ll b) {
  a = max(a, b);
}
//////////////////////////////////////////////////////////////////////
//数学系
///////////////////////////////////////////////////////////////////////
ll round(ll x, ll i) {return ll(x + 5 * pow(10, i-1))/ll(pow(10, i)) * ll(pow(10, i));}
vp insu_bunkai(ll N) {
  vp res;
  for (ll i = 2; i * i <= N; i++) {
    ll cnt = 0;
    while(N % i == 0) {
      cnt++;
      N /= i;
    }
    if(cnt != 0) res.push_back(P(i, cnt));
  }
  if(N != 1) res.push_back(P(N, 1));
  return res;
}
ll extgcd (ll a, ll b,  ll &x, ll &y) {
  if(b == 0) { x = 1;y = 0;return a;}
  ll d = extgcd(b, a%b, y, x);
  y -= a/b * x;
  return d;
}
template <typename T>
T ceil(T a, T b) {
  assert(b != 0);
  if(a % b == 0) return a / b;
  if((a <= 0 && b < 0) || (a >= 0 && b > 0)) return a/b + 1;
  else return a / b;
}
template <typename T>
T floor(T a, T b) {
  assert(b != 0);
  if(a % b == 0) return a / b;
  if((a <= 0 && b < 0) || (a >= 0 && b > 0)) return a/b;
  else return a/b - 1;
}
ll modpow(ll x, ll y, ll mod) {
  if(x > mod) x %= mod;
  if(y == 0) return 1;
  ll res = modpow(x, y >> 1, mod);
  res = res * res % mod;
  if(y & 1) res *= x, res %= mod;
  return res;
}
ll sqrt_(ll a) {
    ll l = 0;
    ll r = 3000000000LL;
    while(l < r) {
        ll mid = (l + r + 1) / 2;
        if(mid * mid <= a) l = mid;
        else r = mid - 1;
    }
    return l;
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//グローバル変数を置くところ(情報工学意識高め)
#pragma GCC optimize("O3")

const ll int_max = 1001001001;
const ll ll_max = 1001001001001001001LL;
const double pi = 3.141592653589793;
vl dx{0, 1, 0, -1, 0, 1, 1, -1, -1};  // (番兵) → ↓ ← ↑  ※ 右から時計回り 
vl dy{0, 0, -1, 0, 1, 1, -1, -1, 1};
//const ll mod = 1000000007;
//const ll mod = 998244353;


//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/*
外側のマスはせいぜい200選べばよう
マスごとに9通り
(200 * 10) * (200 * 10) = 4 * 10^6
処理に10^4かけるとNGなんだが、使うマスはせいぜい200マス程度なので気を使ってやる。

*/
void solve() {
  ll H, W;
  cin >> H >> W;
  vvl A(H+1, vl(W+1, 0));
  rep(i,1,H)rep(j,1,W) cin >> A.at(i).at(j);
  vvb used(H+1, vb(W+1, false));
  

  ll sub = -ll_max;
  rep(i1, 0, H+1) {
    rep(j1, 0, W+1) {
      if(j1 >= 1 && (i1 != H+1 && i1 != 0)) break;
      rep(i2, i1, H+1) {//高さのみi1以下として良い、横には制約入れらんないはず。
         ll s = 0;
         if(i2 == i1) s = j1;
        rep(j2, s, W+1) {
          if(j2 >= 1 && (i2 != H+1 && i2 != 0)) break;
          rep(dx1, -1, 1) rep(dy1, -1, 1) {
            if(dx1 == 0 && dy1 == 0) continue;
            rep(dx2, -1, 1) rep(dy2, -1, 1) {
              if(dx2 == 0 && dy2 == 0) continue;
              ll ans = 0;
              vp cnt;
              //1つ目のをまずたしあげる。
              ll y1 = i1;
              ll x1 = j1;
              ll y2 = i2;
              ll x2 = j2;
              while(0 < y1 + dy1 && y1 + dy1 <= H && x1 + dx1 <= W &&0 < x1 + dx1) {
                y1 += dy1;
                x1 += dx1;
                if(!used[y1][x1]) ans += A[y1][x1], used[y1][x1] = true, cnt.emplace_back(y1, x1);
              }
              while(0 < y2 + dy2 && y2 + dy2 <= H && x2 + dx2 <= W &&0 < x2 + dx2) {
                y2 += dy2;
                x2 += dx2;
                if(!used[y2][x2]) ans += A[y2][x2], used[y2][x2] = true, cnt.emplace_back(y2, x2);
              }

              for(auto [y, x] : cnt) used[y][x] = false;
              chmax(sub, ans);
            }
          }
        }
      }
    }
  }
  cout << sub << endl;

 

    

}
//無断で0を平方数にカウントする人もいる
//”部分文字列”と”連続部分文字列”は違うので確認すること
//一般のグラフと、有向辺かつその貼り方に制約がある(多くの場合:番号がで解放に伸びる)はだいぶ違うので確認すること
//座標を2で割った時の”切り捨て側(左側)”を求めるには 誤:(x / 2) マイナスの時!!! 正:floor<ll>(x, 2);
//stringでの数字の下から1桁目は 正:S.at(N-1)  誤:S.at(0)
//if(S.at(i) == 1) ← charなのに1...?
// modは取りましたか...?(´・ω・`)
//sortの比較関数は、 a == b ならば falseを返す必要がある(そうで無いとRE(発生しない場合もある))



int main() {
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  cout << fixed << setprecision(15);
    ll T = 1;
    //cin >> T;
    rep(i, 1, T) {
        solve();
    }
  return 0;
}
0