結果

問題 No.1028 闇討ち
ユーザー chocopuuchocopuu
提出日時 2020-04-19 14:30:12
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 288 ms / 2,000 ms
コード長 1,417 bytes
コンパイル時間 2,399 ms
コンパイル使用メモリ 206,156 KB
実行使用メモリ 28,928 KB
最終ジャッジ日時 2024-04-15 12:47:02
合計ジャッジ時間 6,917 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 3 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 11 ms
5,376 KB
testcase_10 AC 16 ms
5,376 KB
testcase_11 AC 61 ms
9,472 KB
testcase_12 AC 280 ms
27,776 KB
testcase_13 AC 259 ms
27,520 KB
testcase_14 AC 143 ms
19,712 KB
testcase_15 AC 45 ms
8,192 KB
testcase_16 AC 279 ms
28,800 KB
testcase_17 AC 280 ms
28,928 KB
testcase_18 AC 281 ms
28,544 KB
testcase_19 AC 285 ms
28,800 KB
testcase_20 AC 288 ms
28,800 KB
testcase_21 AC 282 ms
28,800 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;
#define int long long
#define REP(i, n) for (int i = 0; i < (int)n; ++i)
#define RREP(i, n) for (int i = (int)n - 1; i >= 0; --i)
#define FOR(i, s, n) for (int i = s; i < (int)n; ++i)
#define RFOR(i, s, n) for (int i = (int)n - 1; i >= s; --i)
#define ALL(a) a.begin(), a.end()
#define IN(a, x, b) (a <= x && x < b)
template<class T>inline void out(T t){cout << t << "\n";}
template<class T,class... Ts>inline void out(T t,Ts... ts){cout << t << " ";out(ts...);}
template<class T>inline bool CHMIN(T&a,T b){if(a > b){a = b;return true;}return false;}
template<class T>inline bool CHMAX(T&a,T b){if(a < b){a = b;return true;}return false;}
constexpr int INF = 1e18;



signed main(){
	int N;
	cin >> N;
	vector<vector<int>>a(N,vector<int>(N));
	vector<vector<pair<int,int>>>pos(N);
	REP(i,N){
		REP(j,N){
			cin >> a[i][j];
			--a[i][j];
			pos[a[i][j]].emplace_back(i,j);
		}
	}
	int ans = 0;
	REP(i,N){
		vector<int>imos1(N + 1),imos2(N + 1);
		for(auto[x,y]:pos[i]){
			++imos1[min(N,x + y + 1)];
			--imos1[N];
			++imos2[0];
			--imos2[max(0ll,x - y)];
		}
		REP(j,N){
			imos1[j + 1] += imos1[j];
			imos2[j + 1] += imos2[j];
		}
		REP(j,N)imos1[j + 1] += imos1[j];
		RREP(j,N)imos2[j] += imos2[j + 1];
		int mi = INF,idx = -1;
		REP(j,N)if(CHMIN(mi,imos1[j] + imos2[j]))idx = j;
		REP(j,N){
			auto[x,y] = pos[i][j];
			ans += max(abs(idx-x),y);
		}
	}
	out(ans);
}
0