結果
問題 | No.1028 闇討ち |
ユーザー |
![]() |
提出日時 | 2020-04-17 22:27:35 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 1,552 ms / 2,000 ms |
コード長 | 1,375 bytes |
コンパイル時間 | 1,156 ms |
コンパイル使用メモリ | 99,816 KB |
実行使用メモリ | 16,172 KB |
最終ジャッジ日時 | 2024-10-03 13:59:53 |
合計ジャッジ時間 | 15,244 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 20 |
ソースコード
//#include <bits/stdc++.h>#include <iostream>#include <fstream>#include <vector>#include <string>#include <cmath>#include <algorithm>#include <map>#include <iomanip>#include <stdlib.h>#include <stdio.h>#include <queue>#include <deque>#include <set>#include <stack>#include <time.h>using namespace std;typedef long long ll;typedef long double ld;typedef pair<int, int> Pii;typedef pair<int, ll> Pil;typedef pair<ll, ll> Pll;typedef pair<ll, int> Pli;const ll MOD = 1e9 + 7;const ll MOD2 = 998244353;const ll INF = 1ll << 60;const double PI = 2 * asin(1);int N, A[1005][1005], start[1005];vector <Pii> P[1005];int Dist(int i1, int j1, int i2, int j2){int now = abs(i2 - i1);if (j1 - now <= j2 && j2 <= j1 + now){return now;}if (j2 < j1 - now){return now + (j1 - now - j2);}else{return now + (j2 - j1 - now);}}int main(){scanf("%d", &N);for (int i = 0; i < N; i++){for (int j = 0; j < N; j++){scanf("%d", &A[i][j]);P[A[i][j]].push_back(make_pair(i, j));}}int ans = 0;for (int i = 1; i <= N; i++){int now = 1e9;for (int k = 0; k < N; k++){int sum = 0;for (int j = 0; j < N; j++){sum += Dist(k, 0, P[i][j].first, P[i][j].second);}now = min(now, sum);}ans += now;}cout << ans << endl;return 0;}