結果
| 問題 | No.1028 闇討ち |
| コンテスト | |
| ユーザー |
Rho
|
| 提出日時 | 2020-04-16 23:57:13 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 95 ms / 2,000 ms |
| コード長 | 1,041 bytes |
| コンパイル時間 | 1,446 ms |
| コンパイル使用メモリ | 174,304 KB |
| 実行使用メモリ | 20,864 KB |
| 最終ジャッジ日時 | 2024-10-03 04:24:00 |
| 合計ジャッジ時間 | 4,079 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 20 |
コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:51:55: warning: 'id' may be used uninitialized [-Wmaybe-uninitialized]
51 | ans += max(G[i][j].second, abs(G[i][j].first - id));
| ~~~^~~~~~~~~~~~~~~~~~~~
main.cpp:43:31: note: 'id' was declared here
43 | int mn = 1e9, id;
| ^~
ソースコード
#pragma warning(disable:4996)
#include"bits/stdc++.h"
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define RE assert(0);
const long long inf = 1e17;
typedef pair<int, int> P;
vector<P>G[1005];
signed main() {
cin.tie(0);
ios::sync_with_stdio(false);
int n; cin >> n;
if (1 > n || n > 1000)RE;
rep(i, n) {
rep(j, n) {
int a; cin >> a; a--;
if (a < 0 || a >= n)RE;
G[a].push_back(P(i, j));
}
}
int ans = 0;
rep(i, n) {
vector<int>p1(n), p2(n);
if (G[i].size() != n)RE;
rep(j, n) {
p1[0]++;
p1[max(0ll, G[i][j].first - G[i][j].second)]--;
p2[min(n - 1, G[i][j].second + G[i][j].first + 1)]++;
p2[n - 1]--;
}
rep(j, n - 1) {
p1[j + 1] += p1[j];
p2[j + 1] += p2[j];
}
rep(j, n - 1) {
p2[j + 1] += p2[j];
p1[n - 2 - j] += p1[n - 1 - j];
}
int mn = 1e9, id;
rep(j, n) {
if (mn > p1[j] + p2[j]) {
mn = p1[j] + p2[j];
id = j;
}
}
rep(j, n) {
ans += max(G[i][j].second, abs(G[i][j].first - id));
}
}
cout << ans << endl;
}
Rho