結果

問題 No.1028 闇討ち
ユーザー queeequeee
提出日時 2020-04-17 23:08:58
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 1,278 ms / 2,000 ms
コード長 742 bytes
コンパイル時間 855 ms
コンパイル使用メモリ 77,228 KB
実行使用メモリ 16,100 KB
最終ジャッジ日時 2024-04-14 15:26:22
合計ジャッジ時間 12,821 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 1 ms
6,944 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 2 ms
6,944 KB
testcase_07 AC 2 ms
6,944 KB
testcase_08 AC 2 ms
6,944 KB
testcase_09 AC 19 ms
6,944 KB
testcase_10 AC 29 ms
6,944 KB
testcase_11 AC 168 ms
6,940 KB
testcase_12 AC 1,169 ms
15,452 KB
testcase_13 AC 1,159 ms
15,360 KB
testcase_14 AC 506 ms
11,648 KB
testcase_15 AC 113 ms
6,940 KB
testcase_16 AC 1,274 ms
16,008 KB
testcase_17 AC 1,268 ms
16,100 KB
testcase_18 AC 1,275 ms
15,996 KB
testcase_19 AC 1,277 ms
16,000 KB
testcase_20 AC 1,278 ms
15,952 KB
testcase_21 AC 1,275 ms
16,032 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <cmath>
#include <vector>
using namespace std; typedef long long ll; const int INF=1e9; using P=pair<int,int>;

int main() {
  int n; cin>>n;
  int a[n][n];
  for(int i=0;i<n;i++) for(int j=0;j<n;j++) cin>>a[i][j];

  vector<P> que[n];
  for(int i=0;i<n;i++) {
    for(int j=0;j<n;j++) {
      a[i][j]--;
      que[a[i][j]].push_back({i,j});
    }
  }

  int an=0;
  for(int i=0;i<n;i++) { // 数字i
    int au=INF;
    for(int j=0;j<n;j++) { // y軸はj
      int sm=0;
      for(P one:que[i]) {
        int x=one.first, y=one.second;
        sm += max(abs(x-j), y);
      }
      au=min(au,sm);
    }
    an+=au;
  }

  cout<<an<<endl;
}

// たのむ
// 通ってください
// O(N^3)ですが通って!!
0