結果

問題 No.1028 闇討ち
ユーザー knshnbknshnb
提出日時 2020-04-17 21:46:40
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 406 ms / 2,000 ms
コード長 1,742 bytes
コンパイル時間 2,279 ms
コンパイル使用メモリ 204,080 KB
実行使用メモリ 58,368 KB
最終ジャッジ日時 2024-04-14 13:26:22
合計ジャッジ時間 7,112 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 1 ms
6,944 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 2 ms
6,940 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,940 KB
testcase_09 AC 9 ms
6,940 KB
testcase_10 AC 13 ms
6,944 KB
testcase_11 AC 74 ms
15,872 KB
testcase_12 AC 378 ms
55,040 KB
testcase_13 AC 374 ms
54,656 KB
testcase_14 AC 199 ms
31,360 KB
testcase_15 AC 53 ms
12,544 KB
testcase_16 AC 402 ms
57,984 KB
testcase_17 AC 394 ms
58,112 KB
testcase_18 AC 406 ms
58,240 KB
testcase_19 AC 406 ms
58,368 KB
testcase_20 AC 394 ms
58,368 KB
testcase_21 AC 396 ms
58,240 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>  // clang-format off
using Int = long long;
#define REP_(i, a_, b_, a, b, ...) for (Int i = (a), lim##i = (b); i < lim##i; i++)
#define REP(i, ...) REP_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
struct SetupIO { SetupIO() { std::cin.tie(nullptr), std::ios::sync_with_stdio(false), std::cout << std::fixed << std::setprecision(13); } } setup_io;
#ifndef _MY_DEBUG
#define dump(...)
#endif  // clang-format on

/**
 *    author:  knshnb
 *    created: Fri Apr 17 21:39:42 JST 2020
 **/

template <class T, class S> T make_vec(S x) { return x; }
template <class T, class... Ts> auto make_vec(size_t n, Ts... ts) {
    return std::vector<decltype(make_vec<T>(ts...))>(n, make_vec<T>(ts...));
}

template <class T> inline bool chmin(T& a, const T& b) {
    if (a <= b) return false;
    a = b;
    return true;
}
template <class T> inline bool chmax(T& a, const T& b) {
    if (a >= b) return false;
    a = b;
    return true;
}

signed main() {
    Int n;
    std::cin >> n;
    std::vector<Int> offset(n);
    auto t = make_vec<Int>(n, n, 2, 0);
    REP(i, n) {
        REP(j, n) {
            Int x;
            std::cin >> x, x--;
            offset[x] += j;
            if (i - j - 1 >= 0) t[x][i - j - 1][0]++;
            if (i + j + 1 < n) t[x][i + j + 1][1]++;
        }
    }
    Int ans = 0;
    REP(i, n) {
        REP(_, 2) {
            for (Int j = n - 2; j >= 0; j--) {
                t[i][j][0] += t[i][j + 1][0];
            }
            REP(j, n - 1) {
                t[i][j + 1][1] += t[i][j][1];
            }
        }
        Int mi = 1e9;
        REP(j, n) {
            chmin(mi, offset[i] + t[i][j][0] + t[i][j][1]);
        }
        ans += mi;
    }
    std::cout << ans << std::endl;
}
0