結果
| 問題 | No.1028 闇討ち |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-04-18 23:46:14 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,344 bytes |
| コンパイル時間 | 2,050 ms |
| コンパイル使用メモリ | 185,436 KB |
| 実行使用メモリ | 11,520 KB |
| 最終ジャッジ日時 | 2024-10-04 00:32:53 |
| 合計ジャッジ時間 | 12,049 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | WA * 2 |
| other | AC * 3 WA * 17 |
ソースコード
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(int)(n); i++)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
int n; cin >> n;
int INFTY = 100100100;
vector<vector<int>> A(n, vector<int>(n));
rep(i,n) rep(j,n) {
int a; cin >> a;
A[i][j] = --a;
}
vector<int> dx = {-1, 0, 1, -1, 1, -1, 0, 1};
vector<int> dy = {-1, -1, -1, 0, 0, 1, 1, 1};
map<int,int> sp;
ll ans = 0;
rep(i, n) sp[i] = INFTY;
int d = INFTY;
vector<vector<int>> dist(n, vector<int>(n, INFTY));
rep(i,n) {
queue<P> q;
q.push(make_pair(i,0));
map<int,int> d;
dist[i][0] = 0;
while (!q.empty()) {
P p = q.front(); q.pop();
int x = p.first;
int y = p.second;
//cout << x << " " << y << endl;
d[A[x][y]] += dist[x][y];
rep(j, 8) {
int nx = x + dx[j];
int ny = y + dy[j];
if (0 <= nx && nx < n && 0 <= ny && ny < n) {
if (dist[nx][ny] == INFTY) {
q.push(make_pair(nx,ny));
dist[nx][ny] = dist[x][y] + 1;
}
}
}
}
rep(l,n) rep(m,3) dist[l][m] = INFTY;
for (auto m : d) {
sp[m.first] = min(sp[m.first], m.second);
}
}
for (auto s: sp) {
ans += s.second;
}
cout << ans << endl;
}