結果
| 問題 |
No.1028 闇討ち
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-04-17 21:58:47 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 114 ms / 2,000 ms |
| コード長 | 808 bytes |
| コンパイル時間 | 1,468 ms |
| コンパイル使用メモリ | 170,692 KB |
| 実行使用メモリ | 20,224 KB |
| 最終ジャッジ日時 | 2024-10-03 12:53:13 |
| 合計ジャッジ時間 | 3,624 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 20 |
ソースコード
#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
const int MOD=1000000007;
const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;
int a[2000][2000];
vector<P>v[2000];
int suma[2000],sumb[2000];
int main(){
int n;cin>>n;
rep(i,n)rep(j,n){
scanf("%d",&a[i][j]),a[i][j]--;
v[a[i][j]].push_back(P(i,j));
}
int ans=0;
rep(i,n){
memset(suma,0,sizeof(suma));
memset(sumb,0,sizeof(sumb));
for(auto p:v[i]){
int l=max(0,p.first-p.second),r=min(n,p.first+p.second);
suma[0]--;sumb[0]+=max(p.first,p.second);
suma[l]++;
suma[r]++;
}
int Min=INT_MAX;
int d=0;
rep(j,n){
if(j)suma[j]+=suma[j-1],sumb[j]+=sumb[j-1];
Min=min(Min,d+sumb[j]);
d+=suma[j];
}
ans+=Min;
}
cout<<ans<<endl;
}