結果
問題 | No.1028 闇討ち |
ユーザー | leaf_1415 |
提出日時 | 2020-04-17 21:54:57 |
言語 | C++11 (gcc 11.4.0) |
結果 |
AC
|
実行時間 | 479 ms / 2,000 ms |
コード長 | 2,223 bytes |
コンパイル時間 | 830 ms |
コンパイル使用メモリ | 79,832 KB |
実行使用メモリ | 71,304 KB |
最終ジャッジ日時 | 2023-07-27 00:38:00 |
合計ジャッジ時間 | 6,387 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge11 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 12 ms
31,968 KB |
testcase_01 | AC | 12 ms
32,048 KB |
testcase_02 | AC | 11 ms
31,984 KB |
testcase_03 | AC | 11 ms
32,000 KB |
testcase_04 | AC | 12 ms
31,984 KB |
testcase_05 | AC | 12 ms
32,332 KB |
testcase_06 | AC | 12 ms
34,340 KB |
testcase_07 | AC | 11 ms
32,100 KB |
testcase_08 | AC | 12 ms
32,116 KB |
testcase_09 | AC | 22 ms
38,160 KB |
testcase_10 | AC | 26 ms
38,760 KB |
testcase_11 | AC | 74 ms
48,916 KB |
testcase_12 | AC | 437 ms
69,652 KB |
testcase_13 | AC | 437 ms
69,540 KB |
testcase_14 | AC | 195 ms
60,944 KB |
testcase_15 | AC | 55 ms
45,704 KB |
testcase_16 | AC | 477 ms
71,244 KB |
testcase_17 | AC | 479 ms
71,108 KB |
testcase_18 | AC | 464 ms
71,304 KB |
testcase_19 | AC | 457 ms
71,172 KB |
testcase_20 | AC | 459 ms
71,224 KB |
testcase_21 | AC | 466 ms
71,236 KB |
ソースコード
#include <iostream> #include <cstdio> #include <cmath> #include <ctime> #include <cstdlib> #include <cassert> #include <vector> #include <list> #include <stack> #include <queue> #include <deque> #include <map> #include <set> #include <bitset> #include <string> #include <algorithm> #include <utility> #define llint long long #define inf 1e18 #define rep(x, s, t) for(llint (x) = (s); (x) < (t); (x)++) #define Rep(x, s, t) for(llint (x) = (s); (x) <= (t); (x)++) #define chmin(x, y) (x) = min((x), (y)) #define chmax(x, y) (x) = max((x), (y)) using namespace std; typedef pair<llint, llint> P; llint n; llint a[1005][1005]; vector<llint> vec[1005][1005]; llint d[1005][1005]; llint s[1005][1005]; int main(void) { ios::sync_with_stdio(0); cin.tie(0); cin >> n; for(int y = 1; y <= n; y++){ for(int x = 1; x <= n; x++){ cin >> a[x][y]; } } for(int y = 1; y <= n; y++){ for(int x = 1; x <= n; x++){ if(y+x-1 <= n) vec[a[x][y]][y+x-1].push_back(x-1); } } for(int i = 1; i <= n; i++){ llint sum = 0, cnt = 0; for(int y = 1; y <= n; y++){ s[i][y] += sum; for(int j = 0; j < vec[i][y].size(); j++){ llint x = vec[i][y][j]; sum += x; cnt++; } sum += cnt; } } for(int y = 1; y <= n; y++){ for(int x = 1; x <= n; x++){ vec[x][y].clear(); } } for(int y = 1; y <= n; y++){ for(int x = 1; x <= n; x++){ if(y-(x-1) >= 1) vec[a[x][y]][y-(x-1)].push_back(x-1); } } for(int i = 1; i <= n; i++){ llint sum = 0, cnt = 0; for(int y = n; y >= 1; y--){ s[i][y] += sum; for(int j = 0; j < vec[i][y].size(); j++){ llint x = vec[i][y][j]; sum += x; cnt++; } sum += cnt; } } for(llint y = 1; y <= n; y++){ for(llint x = 1; x <= n; x++){ llint id = a[x][y]; llint l = max(1LL, y-(x-1)), r = min(n, y+(x-1)); if(l > r) continue; d[id][l] += x-1, d[id][r+1] -= x-1; } } for(int i = 1; i <= n; i++){ for(int y = 1; y <= n; y++) d[i][y] += d[i][y-1]; } for(int i = 1; i <= n; i++){ for(int y = 1; y <= n; y++) s[i][y] += d[i][y]; } llint ans = 0; for(int i = 1; i <= n; i++){ llint mn = inf; for(int y = 1; y <= n; y++) mn = min(mn, s[i][y]); ans += mn; } cout << ans << endl; return 0; }