結果

問題 No.1028 闇討ち
ユーザー RhoRho
提出日時 2020-04-16 19:38:39
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 108 ms / 2,000 ms
コード長 878 bytes
コンパイル時間 1,692 ms
コンパイル使用メモリ 169,304 KB
実行使用メモリ 20,992 KB
最終ジャッジ日時 2024-04-10 05:42:51
合計ジャッジ時間 4,532 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 1 ms
6,944 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 2 ms
6,944 KB
testcase_06 AC 2 ms
6,944 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 2 ms
6,944 KB
testcase_09 AC 6 ms
6,940 KB
testcase_10 AC 8 ms
6,944 KB
testcase_11 AC 26 ms
7,552 KB
testcase_12 AC 100 ms
20,352 KB
testcase_13 AC 99 ms
20,224 KB
testcase_14 AC 56 ms
15,744 KB
testcase_15 AC 19 ms
7,040 KB
testcase_16 AC 108 ms
20,992 KB
testcase_17 AC 107 ms
20,992 KB
testcase_18 AC 106 ms
20,736 KB
testcase_19 AC 104 ms
20,864 KB
testcase_20 AC 105 ms
20,864 KB
testcase_21 AC 107 ms
20,864 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:45:55: warning: 'id' may be used uninitialized [-Wmaybe-uninitialized]
   45 |                         ans += max(G[i][j].second, abs(G[i][j].first - id));
      |                                                    ~~~^~~~~~~~~~~~~~~~~~~~
main.cpp:37:31: note: 'id' was declared here
   37 |                 int mn = 1e9, id;
      |                               ^~

ソースコード

diff #

#include"bits/stdc++.h"
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
typedef pair<int, int> P;
vector<P>G[1005];
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	int n; cin >> n;
	rep(i, n) {
		rep(j, n) {
			int a; cin >> a; a--;
			G[a].push_back(P(i, j));
		}
	}

	int ans = 0;

	rep(i, n) {
		vector<int>p1(n), p2(n);
		rep(j, n) {
			p1[0]++;
			p1[max(0ll, G[i][j].first - G[i][j].second)]--;
			p2[min(n - 1, G[i][j].second + G[i][j].first+1)]++;
			p2[n - 1]--;
		}
		rep(j, n - 1) {
			p1[j + 1] += p1[j];
			p2[j + 1] += p2[j];
		}
		rep(j, n - 1) {
			p2[j + 1] += p2[j];
			p1[n - 2 - j] += p1[n - 1 - j];
		}
		int mn = 1e9, id;
		rep(j, n) {
			if (mn > p1[j] + p2[j]) {
				mn = p1[j] + p2[j];
				id = j;
			}
		}
		rep(j, n) {
			ans += max(G[i][j].second, abs(G[i][j].first - id));
		}
	}
	cout << ans << endl;
}
0