結果
問題 | No.1028 闇討ち |
ユーザー | 🍮かんプリン |
提出日時 | 2020-05-15 20:13:25 |
言語 | C++11 (gcc 11.4.0) |
結果 |
AC
|
実行時間 | 463 ms / 2,000 ms |
コード長 | 1,403 bytes |
コンパイル時間 | 2,930 ms |
コンパイル使用メモリ | 168,268 KB |
実行使用メモリ | 16,432 KB |
最終ジャッジ日時 | 2023-10-19 10:30:50 |
合計ジャッジ時間 | 8,463 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge15 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
4,348 KB |
testcase_01 | AC | 2 ms
4,348 KB |
testcase_02 | AC | 2 ms
4,348 KB |
testcase_03 | AC | 2 ms
4,348 KB |
testcase_04 | AC | 2 ms
4,348 KB |
testcase_05 | AC | 2 ms
4,348 KB |
testcase_06 | AC | 2 ms
4,348 KB |
testcase_07 | AC | 2 ms
4,348 KB |
testcase_08 | AC | 2 ms
4,348 KB |
testcase_09 | AC | 16 ms
4,348 KB |
testcase_10 | AC | 22 ms
4,444 KB |
testcase_11 | AC | 90 ms
6,724 KB |
testcase_12 | AC | 424 ms
15,900 KB |
testcase_13 | AC | 416 ms
15,572 KB |
testcase_14 | AC | 213 ms
12,064 KB |
testcase_15 | AC | 66 ms
6,160 KB |
testcase_16 | AC | 451 ms
16,036 KB |
testcase_17 | AC | 449 ms
15,884 KB |
testcase_18 | AC | 448 ms
16,428 KB |
testcase_19 | AC | 463 ms
16,388 KB |
testcase_20 | AC | 450 ms
16,432 KB |
testcase_21 | AC | 448 ms
16,140 KB |
ソースコード
/** * @FileName e.cpp * @Author kanpurin * @Created 2020.05.15 20:13:17 **/ #include "bits/stdc++.h" using namespace std; typedef long long ll; int main() { int n; cin >> n; vector< vector< int > > a1(n),a2(n); vector< vector< int > > ans(n, vector< int >(n)); for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { int b; cin >> b; b--; a1[b].push_back(i - j); a2[b].push_back(i + j); ans[0][b] += max(i,j); } } for (int i = 0; i < n; i++) { sort(a1[i].begin(), a1[i].end()); sort(a2[i].begin(), a2[i].end()); } for (int i = 1; i < n; i++) { for (int j = 0; j < n; j++) { //cout << i << " " << j << " " << (upper_bound(a2[j].begin(), a2[j].end(), i-1) - a2[j].begin()) << endl; //cout << i << " " << j << " " << a1[j].end() - upper_bound(a1[j].begin(), a1[j].end(), i-1) << endl; ans[i][j] = ans[i-1][j] + (upper_bound(a2[j].begin(), a2[j].end(), i-1) - a2[j].begin()) - (a1[j].end() - upper_bound(a1[j].begin(), a1[j].end(), i-1)); } } int res = 0; constexpr int INF = 1e9 + 6; for (int i = 0; i < n; i++) { int m = INF; for (int j = 0; j < n; j++) { m = min(ans[j][i],m); } res += m; } cout << res << endl; return 0; }