結果

問題 No.1028 闇討ち
ユーザー carrot46carrot46
提出日時 2020-04-17 21:48:31
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 250 ms / 2,000 ms
コード長 1,156 bytes
コンパイル時間 3,457 ms
コンパイル使用メモリ 170,148 KB
実行使用メモリ 26,592 KB
最終ジャッジ日時 2023-07-27 00:04:45
合計ジャッジ時間 5,267 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,384 KB
testcase_01 AC 1 ms
4,384 KB
testcase_02 AC 2 ms
4,384 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,384 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,384 KB
testcase_08 AC 2 ms
4,384 KB
testcase_09 AC 10 ms
4,380 KB
testcase_10 AC 14 ms
4,780 KB
testcase_11 AC 52 ms
8,740 KB
testcase_12 AC 230 ms
25,316 KB
testcase_13 AC 229 ms
24,932 KB
testcase_14 AC 114 ms
15,188 KB
testcase_15 AC 36 ms
7,552 KB
testcase_16 AC 244 ms
26,492 KB
testcase_17 AC 247 ms
26,592 KB
testcase_18 AC 247 ms
26,468 KB
testcase_19 AC 250 ms
26,532 KB
testcase_20 AC 247 ms
26,484 KB
testcase_21 AC 248 ms
26,524 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,K,Q,A,B;
string S;
const ll MOD = 998244353;
//const ll MOD = (1e+9) + 7;
const ll INF = 1LL<<60;
typedef pair<ll, ll> P;

int main() {
    cin>>N;
    mat a(N, vec(N));
    rep(i,N) rep(j,N) {
        cin>>a[i][j];
        --a[i][j];
    }
    mat sumu(N + 2, vec(N, 0)), sumd(N + 2, vec(N, 0));
    rep(i,N){
        rep(j,N){
            ++sumu[min(N + 1, i + 2LL + j)][a[i][j]];
            ++sumd[max(0, i - j)][a[i][j]];
        }
    }
    rep(rp, 2) {
        rep(i, N) rep(j, N) sumu[i + 1][j] += sumu[i][j];
        Rreps(i, N + 1, 1) rep(j, N) sumd[i][j] += sumd[i + 1][j];
    }
    ll ans = N * N * (N - 1) / 2;
    rep(j,N){
        ll temp = INF;
        reps(i,1,N + 1) temp = min(temp, sumu[i][j] + sumd[i][j]);
        ans += temp;
    }
    cout<<ans<<endl;
}
0