結果

問題 No.1028 闇討ち
ユーザー 👑 hitonanodehitonanode
提出日時 2020-04-20 00:16:03
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 100 ms / 2,000 ms
コード長 1,220 bytes
コンパイル時間 2,499 ms
コンパイル使用メモリ 200,036 KB
実行使用メモリ 15,104 KB
最終ジャッジ日時 2024-04-16 00:24:34
合計ジャッジ時間 4,406 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 6 ms
5,376 KB
testcase_10 AC 7 ms
5,376 KB
testcase_11 AC 23 ms
5,888 KB
testcase_12 AC 92 ms
14,336 KB
testcase_13 AC 91 ms
14,080 KB
testcase_14 AC 50 ms
9,344 KB
testcase_15 AC 17 ms
5,376 KB
testcase_16 AC 98 ms
14,848 KB
testcase_17 AC 98 ms
14,976 KB
testcase_18 AC 98 ms
15,104 KB
testcase_19 AC 100 ms
15,104 KB
testcase_20 AC 99 ms
15,104 KB
testcase_21 AC 98 ms
15,104 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
template<typename T> bool chmin(T &m, const T q) { if (m > q) {m = q; return true;} else return false; }
template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }

int main()
{
    int N;
    cin >> N;
    vector A(N, vector<int>(N));
    cin >> A;
    vector i1(N, vector<int>(N)), i2(N, vector<int>(N));
    int ret = 0;
    REP(i, N) REP(j, N)
    {
        int k = A[i][j] - 1;
        ret += j;
        if (i + j + 1 < N) i1[k][i + j + 1]++;
        if (i - j - 1 >= 0) i2[k][i - j - 1]++;
    }
    REP(_, 2) REP(i, N) REP(j, N - 1) i1[i][j + 1] += i1[i][j];
    REP(_, 2) REP(i, N) IREP(j, N - 1) i2[i][j] += i2[i][j + 1];
    REP(i, N)
    {
        int tmp = 1e9;
        REP(j, N) chmin(tmp, i1[i][j] + i2[i][j]);
        ret += tmp;
    }
    cout << ret << '\n';
}
0