結果
| 問題 |
No.1028 闇討ち
|
| コンテスト | |
| ユーザー |
mot
|
| 提出日時 | 2020-04-17 22:45:01 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 257 ms / 2,000 ms |
| コード長 | 2,217 bytes |
| コンパイル時間 | 1,075 ms |
| コンパイル使用メモリ | 88,772 KB |
| 実行使用メモリ | 23,808 KB |
| 最終ジャッジ日時 | 2024-10-03 14:25:55 |
| 合計ジャッジ時間 | 4,317 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 20 |
ソースコード
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
const int inf=1e9+7;
const ll mod=1e9+7;
int main() {
int N;
cin>>N;
vector<vector<pair<int, int> > >arr(N);
int tmp;
for(int i=0;i<N;++i){
for(int j=0;j<N;++j){
cin>>tmp;
tmp--;
arr[tmp].push_back(make_pair(i, j));
}
}
int up[N][N+1];
int down[N][N+1];
int imosu[N][N];
for(int i=0;i<N;++i){
for(int j=0;j<N;++j){
up[i][j] = 0;
down[i][j] = 0;
imosu[i][j] = 0;
}
}
int ans = 0;
for(int i=0;i<N;++i){
for(int j=0;j<N;++j){
ans += arr[i][j].se;
if(arr[i][j].fi+arr[i][j].se>=N){
down[i][N]++;
}
else{
down[i][arr[i][j].fi+arr[i][j].se+1]++;
}
if(arr[i][j].fi-arr[i][j].se<0){
up[i][0]++;
}
else{
up[i][arr[i][j].fi-arr[i][j].se]++;
imosu[i][0] += arr[i][j].fi-arr[i][j].se;
}
}
}
for(int i=0;i<N;++i){
for(int j=1;j<N;++j){
up[i][j] = up[i][j] + up[i][j-1];
down[i][j] = down[i][j] + down[i][j-1];
}
}
/**
//cout<<endl;
for(int i=0;i<N;++i){
for(int j=0;j<N;++j){
cout<<up[i][j]<<" ";
}
cout<<endl;
}
cout<<endl;
for(int i=0;i<N;++i){
for(int j=0;j<N;++j){
cout<<down[i][j]<<" ";
}
cout<<endl;
}
cout<<endl;
**/
for(int i=0;i<N;++i){
for(int j=1;j<N;++j){
imosu[i][j] = imosu[i][j-1] - (N-up[i][j-1]) + down[i][j];
}
}
int maximo;
for(int i=0;i<N;++i){
maximo = N*N;
for(int j=0;j<N;++j){
//cout<<imosu[i][j]<<" ";
if(maximo>imosu[i][j])maximo = imosu[i][j];
}
//cout<<endl;
ans += maximo;
}
//cout<<endl;
cout<<ans<<endl;
}
mot