結果

問題 No.1028 闇討ち
ユーザー ricoriser32ricoriser32
提出日時 2020-04-17 21:47:45
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 1,291 ms / 2,000 ms
コード長 675 bytes
コンパイル時間 2,241 ms
コンパイル使用メモリ 199,128 KB
実行使用メモリ 12,160 KB
最終ジャッジ日時 2024-04-14 13:27:10
合計ジャッジ時間 14,373 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 2 ms
6,944 KB
testcase_08 AC 2 ms
6,940 KB
testcase_09 AC 18 ms
6,940 KB
testcase_10 AC 29 ms
6,940 KB
testcase_11 AC 167 ms
6,940 KB
testcase_12 AC 1,175 ms
11,904 KB
testcase_13 AC 1,159 ms
11,776 KB
testcase_14 AC 507 ms
9,600 KB
testcase_15 AC 112 ms
6,940 KB
testcase_16 AC 1,274 ms
12,032 KB
testcase_17 AC 1,273 ms
12,032 KB
testcase_18 AC 1,287 ms
12,032 KB
testcase_19 AC 1,278 ms
12,032 KB
testcase_20 AC 1,291 ms
12,160 KB
testcase_21 AC 1,275 ms
12,032 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long double ld;
int main()
{
  int n;
  cin >> n;
  vector<pair<int, int>> mem[n];
  REP(i,n) REP(j,n){
    int a;
    cin >> a;
    a--;
    mem[a].emplace_back(i,j);
  }
  int ans = 0;
  REP(a,n){
    int tmp = 1e9;
    REP(x,n){
      int sum = 0;
      for(auto p: mem[a]){
        sum += max(abs(p.first-x), p.second);
      }
      tmp = min(tmp, sum);
    }
    ans += tmp;
  }
  cout << ans << '\n';
  return 0;
}
0