結果

問題 No.1028 闇討ち
ユーザー imoni_kawaiiimoni_kawaii
提出日時 2020-06-09 23:02:05
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,291 bytes
コンパイル時間 2,043 ms
コンパイル使用メモリ 206,932 KB
実行使用メモリ 19,296 KB
最終ジャッジ日時 2023-08-31 01:25:06
合計ジャッジ時間 5,946 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
#define REP(i, m, n) for(int i = (int)(m); i < (int)(n); ++i)
#define rep(i, n) REP(i, 0, n)
using namespace std;
using ll = long long;
using ld = long double;
template<class T, class U> inline bool chmax(T &a, const U &b) { if(a < b) { a = b; return true; } return false; }
template<class T, class U> inline bool chmin(T &a, const U &b) { if(a > b) { a = b; return true; } return false; }

using pint = pair<int, int>;
int n, a[1000][1000];

int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  cin >> n;
  vector<vector<pint>> pos(n);
  rep(i, n) rep(j, n) cin >> a[i][j], a[i][j]--;
  rep(i, n) {
    rep(j, n) {
      pos[a[i][j]].push_back({i, j});
    }
  }
  vector<vector<int>> s(n, vector<int>(n+1, 0));
  ll ans = 0;
  rep(i, n) {
    rep(j, n) {
      int l = max(0, pos[i][j].first-pos[i][j].second);
      int r = min(n-1, pos[i][j].first+pos[i][j].second);
      s[i][l]++;
      s[i][r+1]--;
    }
    rep(j, n+1) {
      if(j-1 < 0) continue;
      s[i][j] += s[i][j-1];
    }
    int mx = -1, p = -1;
    rep(j, n) {
      if(chmax(mx, s[i][j])) {
        p = j;
      }
    }
    ll d = 0;
    rep(j, n) {
      d += pos[i][j].second+max(0, abs(pos[i][j].first-p)-pos[i][j].second);
    }
    ans += d;
  }
  cout << ans << '\n';
  return 0;
}
0