結果
| 問題 | No.1028 闇討ち |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-04-16 20:15:12 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 124 ms / 2,000 ms |
| コード長 | 1,151 bytes |
| 記録 | |
| コンパイル時間 | 1,637 ms |
| コンパイル使用メモリ | 166,932 KB |
| 実行使用メモリ | 15,360 KB |
| 最終ジャッジ日時 | 2024-10-02 08:13:47 |
| 合計ジャッジ時間 | 4,806 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 20 |
ソースコード
#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;
}