結果
問題 | No.1028 闇討ち |
ユーザー |
|
提出日時 | 2020-04-17 22:38:18 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 208 ms / 2,000 ms |
コード長 | 1,924 bytes |
コンパイル時間 | 1,256 ms |
コンパイル使用メモリ | 108,856 KB |
実行使用メモリ | 20,276 KB |
最終ジャッジ日時 | 2024-10-03 14:17:50 |
合計ジャッジ時間 | 4,266 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,816 KB |
testcase_01 | AC | 2 ms
6,820 KB |
testcase_02 | AC | 3 ms
6,816 KB |
testcase_03 | AC | 3 ms
6,816 KB |
testcase_04 | AC | 2 ms
6,816 KB |
testcase_05 | AC | 3 ms
6,816 KB |
testcase_06 | AC | 3 ms
6,820 KB |
testcase_07 | AC | 3 ms
6,820 KB |
testcase_08 | AC | 2 ms
6,816 KB |
testcase_09 | AC | 11 ms
7,080 KB |
testcase_10 | AC | 14 ms
7,208 KB |
testcase_11 | AC | 48 ms
11,796 KB |
testcase_12 | AC | 195 ms
19,900 KB |
testcase_13 | AC | 194 ms
19,500 KB |
testcase_14 | AC | 107 ms
16,604 KB |
testcase_15 | AC | 36 ms
10,992 KB |
testcase_16 | AC | 208 ms
20,016 KB |
testcase_17 | AC | 207 ms
20,016 KB |
testcase_18 | AC | 207 ms
20,152 KB |
testcase_19 | AC | 208 ms
20,024 KB |
testcase_20 | AC | 208 ms
20,020 KB |
testcase_21 | AC | 207 ms
20,276 KB |
ソースコード
#include <iostream> #include <vector> #include <algorithm> #include <math.h> #include <set> #include <map> #include <queue> #include <numeric> #include <deque> using namespace std; typedef long long int ll; int a[1001][1001]; int aa[1001][1001]; vector<pair<int,int>> v[1001]; vector<int> l[1001]; vector<int> r[1001]; int rr[1001]; int main(){ cin.tie(nullptr); ios::sync_with_stdio(false); int n; cin >> n; ll res=0; for(int i=0;i<n;i++){ for(int j=0;j<n;j++){ cin >> aa[i][j]; aa[i][j]--; a[n-1-j][n-1-i]=aa[i][j]; } } for(int i=0;i<n;i++){ for(int j=0;j<n;j++){ //cin >> a[i][j]; //a[i][j]--; int ii=n-1-i; res+=ii; l[a[i][j]].push_back(j-ii); r[a[i][j]].push_back(j+ii); rr[a[i][j]]+=max(0,j-ii); } } for(int i=0;i<n;i++){ sort(l[i].begin(),l[i].end()); sort(r[i].begin(),r[i].end()); } for(int i=0;i<n;i++){ int mi=rr[i]; int nowl=0; int nowr=0; int leftnow=0; int rightnow=n; int leftcost=0; int rightcost=rr[i]; while(nowl<n&&l[i][nowl]<=0){ nowl++; rightnow--; } while(nowr<n&&r[i][nowr]<=0){ nowr++; leftnow++; } for(int j=1;j<n;j++){ //printf("%d %d %d\n",mi,leftcost,rightcost ); leftcost+=leftnow; rightcost-=rightnow; while(nowl<n&&l[i][nowl]<=j){ nowl++; rightnow--; } while(nowr<n&&r[i][nowr]<=j){ leftnow++; nowr++; } mi=min(mi,leftcost+rightcost); } //printf("%d %d %d\n",mi,leftcost,rightcost); //printf("\n"); res+=mi; } printf("%lld\n",res); }