結果
| 問題 |
No.1028 闇討ち
|
| コンテスト | |
| ユーザー |
imoni_kawaii
|
| 提出日時 | 2020-06-09 23:05:48 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,285 bytes |
| コンパイル時間 | 2,100 ms |
| コンパイル使用メモリ | 203,256 KB |
| 最終ジャッジ日時 | 2025-01-11 00:35:01 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 2 WA * 18 |
ソースコード
#include <bits/stdc++.h>
#define REP(i, m, n) for(int i = (int)(m); i < (int)(n); ++i)
#define rep(i, n) REP(i, 0, n)
using namespace std;
using ll = long long;
using ld = long double;
template<class T, class U> inline bool chmax(T &a, const U &b) { if(a < b) { a = b; return true; } return false; }
template<class T, class U> inline bool chmin(T &a, const U &b) { if(a > b) { a = b; return true; } return false; }
using pll = pair<ll, ll>;
ll n, a[1000][1000];
int main() {
cin.tie(0); ios::sync_with_stdio(false);
cin >> n;
vector<vector<pll>> pos(n);
rep(i, n) rep(j, n) cin >> a[i][j], a[i][j]--;
rep(i, n) {
rep(j, n) {
pos[a[i][j]].push_back({i, j});
}
}
vector<vector<ll>> s(n, vector<ll>(n+1, 0));
ll ans = 0;
rep(i, n) {
rep(j, n) {
ll l = max(0LL, pos[i][j].first-pos[i][j].second);
ll r = min(n-1, pos[i][j].first+pos[i][j].second);
s[i][l]++;
s[i][r+1]--;
}
rep(j, n+1) {
if(j-1 < 0) continue;
s[i][j] += s[i][j-1];
}
ll mx = -1, p = -1;
rep(j, n) {
if(chmax(mx, s[i][j])) {
p = j;
}
}
ll d = 0;
rep(j, n) {
d += pos[i][j].second+max(0LL, abs(pos[i][j].first-p)-pos[i][j].second);
}
ans += d;
}
cout << ans << '\n';
return 0;
}
imoni_kawaii