結果
問題 | No.1028 闇討ち |
ユーザー | WarToks |
提出日時 | 2020-04-17 23:27:04 |
言語 | C++17(clang) (17.0.6 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 122 ms / 2,000 ms |
コード長 | 1,314 bytes |
コンパイル時間 | 496 ms |
コンパイル使用メモリ | 67,472 KB |
実行使用メモリ | 22,628 KB |
最終ジャッジ日時 | 2023-08-20 14:47:40 |
合計ジャッジ時間 | 3,123 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge14 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
4,376 KB |
testcase_01 | AC | 3 ms
7,236 KB |
testcase_02 | AC | 3 ms
7,180 KB |
testcase_03 | AC | 3 ms
7,120 KB |
testcase_04 | AC | 3 ms
7,120 KB |
testcase_05 | AC | 3 ms
7,304 KB |
testcase_06 | AC | 3 ms
7,408 KB |
testcase_07 | AC | 3 ms
7,208 KB |
testcase_08 | AC | 3 ms
7,260 KB |
testcase_09 | AC | 9 ms
9,936 KB |
testcase_10 | AC | 11 ms
10,140 KB |
testcase_11 | AC | 31 ms
17,188 KB |
testcase_12 | AC | 113 ms
22,352 KB |
testcase_13 | AC | 113 ms
22,316 KB |
testcase_14 | AC | 64 ms
21,568 KB |
testcase_15 | AC | 23 ms
14,620 KB |
testcase_16 | AC | 120 ms
22,628 KB |
testcase_17 | AC | 121 ms
22,540 KB |
testcase_18 | AC | 120 ms
22,604 KB |
testcase_19 | AC | 121 ms
22,560 KB |
testcase_20 | AC | 122 ms
22,588 KB |
testcase_21 | AC | 122 ms
22,628 KB |
ソースコード
#include <stdio.h> constexpr unsigned int MAX_N = 1000; unsigned int A[MAX_N][MAX_N]; unsigned long long int P[MAX_N][MAX_N]; unsigned long long int Q[MAX_N][MAX_N]; unsigned long long int S[MAX_N]; int main(void){ unsigned int n; scanf("%u", &n); for(unsigned int i = 0; i < n; ++i) for(unsigned int j = 0; j < n; ++j){ scanf("%u", A[i] + j); --A[i][j]; } for(unsigned int i = 0; i < n; ++i) for(unsigned int j = 0; j < n; ++j){ S[A[i][j]] += j; if(i + j + 1 < n) ++P[A[i][j]][i + j + 1]; if(i >= (j + 1)) ++Q[A[i][j]][i - (j + 1)]; } for(unsigned int i = 0; i < n; ++i){ for(unsigned int j = 0; j + 1 < n; ++j) P[i][j + 1] += P[i][j]; for(unsigned int j = 0; j + 1 < n; ++j) P[i][j + 1] += P[i][j]; } for(unsigned int i = 0; i < n; ++i){ for(unsigned int j = n - 1; j ; --j) Q[i][j - 1] += Q[i][j]; for(unsigned int j = n - 1; j ; --j) Q[i][j - 1] += Q[i][j]; } unsigned long long int res = 0; for(unsigned int i = 0; i < n; ++i){ unsigned long long int s = P[i][0] + Q[i][0]; for(unsigned int j = 1; j < n; ++j){ const unsigned long long int&& tmp = P[i][j] + Q[i][j]; if(tmp < s) s = tmp; } res += S[i] + s; } printf("%llu\n", res); return 0; }