結果

問題 No.1028 闇討ち
ユーザー 沙耶花沙耶花
提出日時 2020-04-17 21:52:03
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 252 ms / 2,000 ms
コード長 951 bytes
コンパイル時間 2,381 ms
コンパイル使用メモリ 202,848 KB
実行使用メモリ 12,160 KB
最終ジャッジ日時 2024-04-14 13:31:09
合計ジャッジ時間 5,897 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 1 ms
6,940 KB
testcase_05 AC 2 ms
6,944 KB
testcase_06 AC 3 ms
6,944 KB
testcase_07 AC 2 ms
6,944 KB
testcase_08 AC 2 ms
6,940 KB
testcase_09 AC 10 ms
6,940 KB
testcase_10 AC 14 ms
6,940 KB
testcase_11 AC 55 ms
6,940 KB
testcase_12 AC 228 ms
12,032 KB
testcase_13 AC 227 ms
11,776 KB
testcase_14 AC 128 ms
9,600 KB
testcase_15 AC 41 ms
6,940 KB
testcase_16 AC 242 ms
12,032 KB
testcase_17 AC 243 ms
12,032 KB
testcase_18 AC 243 ms
12,032 KB
testcase_19 AC 242 ms
12,160 KB
testcase_20 AC 252 ms
12,032 KB
testcase_21 AC 242 ms
12,160 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x)+modulo)%modulo)
#define Inf 1000000000

int get(vector<pair<int,int>> A){
	int now = -(int)A.size();;
	int score = 0;
	vector<int> add(A.size(),0),del(A.size(),0);
	for(int i=0;i<A.size();i++){
		score += max(A[i].first,A[i].second);
		add[max(0,A[i].first-A[i].second)]++;
		del[min((int)A.size()-1,A[i].first+A[i].second)]++;
	}
	now += add[0];
	now += del[0];

	int ret = score;
	for(int i=1;i<A.size();i++){
		score += now;
		now += add[i];
		now += del[i];
		ret = min(ret,score);
	}
	return ret;
}

int main() {
	
	int N;
	cin>>N;
	
	vector<vector<pair<int,int>>> A(N,vector<pair<int,int>>());
	
	for(int i=0;i<N;i++){
		for(int j=0;j<N;j++){
			int a;
			cin>>a;
			a--;
			A[a].emplace_back(i,j);
		}
	}
	
	int ans = 0;
	for(int i=0;i<N;i++){
		//cout<<get(A[i])<<endl;
		ans += get(A[i]);
	}
	
	cout<<ans<<endl;
	
    return 0;
}
0