結果
| 問題 |
No.1028 闇討ち
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-04-17 22:27:03 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 167 ms / 2,000 ms |
| コード長 | 935 bytes |
| コンパイル時間 | 2,600 ms |
| コンパイル使用メモリ | 198,572 KB |
| 最終ジャッジ日時 | 2025-01-09 20:18:48 |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 20 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:10:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
10 | scanf("%d", &a);
| ~~~~~^~~~~~~~~~
ソースコード
#include <bits/stdc++.h>
using namespace std;
int main(){
int N;
cin >> N;
vector<pair<int, int>> pos[1000];
for(int i=0; i<N; i++) for(int j=0; j<N; j++){
int a;
scanf("%d", &a);
pos[a-1].emplace_back(i, j);
}
int64_t ans = 0;
for(int a=0; a<N; a++){
vector<int> cost(N);
vector<int> sl(N), sr(N);
for(auto [i, j] : pos[a]){
if(i-j-1>=0) sl[i-j-1]++;
if(i+j+1<N) sr[i+j+1]++;
}
int sum = 0, num = 0;
for(int i=0; i<N; i++){
num += sr[i];
sum += num;
cost[i] += sum;
}
sum = 0, num = 0;
for(int i=N-1; i>=0; i--){
num += sl[i];
sum += num;
cost[i] += sum;
}
ans += *min_element(cost.begin(), cost.end());
}
for(int j=0; j<N; j++) ans += j*N;
cout << ans << endl;
return 0;
}