結果
| 問題 |
No.1028 闇討ち
|
| コンテスト | |
| ユーザー |
ngtkana
|
| 提出日時 | 2020-04-17 21:56:15 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 150 ms / 2,000 ms |
| コード長 | 953 bytes |
| コンパイル時間 | 2,508 ms |
| コンパイル使用メモリ | 201,640 KB |
| 最終ジャッジ日時 | 2025-01-09 19:58:12 |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 20 |
ソースコード
#include<bits/stdc++.h>
#define ALL(v) std::begin(v),std::end(v)
using lint=long long;
using ld=long double;
template<class T>using numr=std::numeric_limits<T>;
int main(){
std::cin.tie(nullptr);std::ios_base::sync_with_stdio(false);
std::cout.setf(std::ios_base::fixed);std::cout.precision(15);
lint n;std::cin>>n;
std::vector<std::vector<std::pair<lint,lint>>>a(n);
for(lint i=0;i<n;i++)for(lint j=0;j<n;j++){
lint x;std::cin>>x;x--;
a.at(x).emplace_back(i,j);
}
lint ans=0;
for(auto&&v:a){
std::vector<lint>b(2*n);
for(auto[i,j]:v){
for(lint k:{n+i-j+1,n+i+j+1})if(k<2*n)b.at(k)++;
}
b.at(0)=-n;
std::partial_sum(ALL(b),b.begin());
b.at(0)=0;
for(auto[i,j]:v){
b.at(0)+=n+i;
}
std::partial_sum(ALL(b),b.begin());
ans+=*std::min_element(b.begin()+n,b.begin()+2*n);
}
std::cout<<ans<<'\n';
}
ngtkana