結果

問題 No.1028 闇討ち
ユーザー 👑 zeronosu77108zeronosu77108
提出日時 2020-04-17 22:48:10
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
AC  
実行時間 1,386 ms / 2,000 ms
コード長 866 bytes
コンパイル時間 882 ms
コンパイル使用メモリ 91,940 KB
実行使用メモリ 12,224 KB
最終ジャッジ日時 2023-08-20 14:48:13
合計ジャッジ時間 13,994 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 16 ms
4,380 KB
testcase_10 AC 26 ms
4,380 KB
testcase_11 AC 164 ms
5,504 KB
testcase_12 AC 1,191 ms
11,944 KB
testcase_13 AC 1,176 ms
11,848 KB
testcase_14 AC 504 ms
9,552 KB
testcase_15 AC 109 ms
4,952 KB
testcase_16 AC 1,292 ms
12,176 KB
testcase_17 AC 1,297 ms
12,076 KB
testcase_18 AC 1,386 ms
12,224 KB
testcase_19 AC 1,332 ms
12,072 KB
testcase_20 AC 1,299 ms
12,160 KB
testcase_21 AC 1,295 ms
12,076 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <queue>
#include <numeric>
#include <tuple>
#include <climits>

using namespace std;
using P = pair<int,int>;
using TP = tuple<int,int,int>;

const vector dx = {+0,+1,+1,+0,+1};
const vector dy = {+1,+1,+0,-1,-1};

queue<TP> q;

int main() {
    int n;
    cin >> n;

    vector<vector<P>> a(n);
    for (int i=0; i<n; i++) {
       for (int j=0; j<n; j++) {
           int ai;
           cin >> ai;
           a[ai-1].emplace_back(i,j);
       }
    }


    vector<int> ans(n, INT_MAX);
    for (int i=0; i<n; i++) {
        vector<int> tmp(n, 0);
        for (int j=0; j<n; j++) {
            for (auto [y,x] : a[j]) {
                tmp[j] += max(x, abs(y-i));
            }
        }
        for (int j=0; j<n; j++) ans[j] = min(ans[j], tmp[j]);
    }

    cout << accumulate(ans.begin(), ans.end(), 0) << endl;
}
0