結果

問題 No.1028 闇討ち
ユーザー ThistleThistle
提出日時 2020-04-16 20:15:12
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 116 ms / 2,000 ms
コード長 1,151 bytes
コンパイル時間 1,705 ms
コンパイル使用メモリ 163,452 KB
実行使用メモリ 20,844 KB
最終ジャッジ日時 2024-04-10 06:33:35
合計ジャッジ時間 4,523 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 3 ms
6,944 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 1 ms
6,944 KB
testcase_08 AC 2 ms
6,944 KB
testcase_09 AC 7 ms
7,824 KB
testcase_10 AC 8 ms
6,940 KB
testcase_11 AC 27 ms
11,944 KB
testcase_12 AC 108 ms
19,300 KB
testcase_13 AC 106 ms
19,020 KB
testcase_14 AC 59 ms
15,960 KB
testcase_15 AC 20 ms
10,120 KB
testcase_16 AC 111 ms
20,844 KB
testcase_17 AC 113 ms
19,484 KB
testcase_18 AC 113 ms
20,148 KB
testcase_19 AC 110 ms
19,044 KB
testcase_20 AC 107 ms
20,312 KB
testcase_21 AC 116 ms
19,132 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define int long long
#define rng(i,s,n) for(int i = (s) ; i < (n) ; i++)
#define rep(i,n) rng(i, 0, (n))
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
ll read() { ll u, k = scanf("%lld", &u); return u; }
int n;
int a[2000][2000];
int b[2000], c[2000];
int d[2000][2];
signed main() {
    cin >> n;
    rep(i, n) rep(j, n) {
        a[i][j] = read() - 1;
        b[a[i][j]] += i + j - min(i, j);
        if (j - i < 0) d[a[i][j]][1]++;
    }
    rep(i, n) c[i] = b[i];//(0,0)で全て発射するときのコスト
    rep(i, n) {
        //(i+1,0)から発射する
        for (int j = 0; i - j >= 0; j++) {
            d[a[i - j][j]][0]++;
        }
        rep(j, n) {
            b[j] += d[j][0] - d[j][1];
            chmin(c[j], b[j]);
        }
        for (int j = 0; i + j + 1 < n; j++) {
            d[a[i + j + 1][j]][1]--;
        }
    }
    int ans = 0;
    rep(i, n) ans += c[i];
    cout << ans << endl;
}
0