結果
| 問題 | 
                            No.1028 闇討ち
                             | 
                    
| コンテスト | |
| ユーザー | 
                             Rho
                         | 
                    
| 提出日時 | 2020-04-16 19:38:39 | 
| 言語 | C++14  (gcc 13.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 114 ms / 2,000 ms | 
| コード長 | 878 bytes | 
| コンパイル時間 | 1,976 ms | 
| コンパイル使用メモリ | 172,916 KB | 
| 実行使用メモリ | 20,992 KB | 
| 最終ジャッジ日時 | 2024-10-02 07:18:34 | 
| 合計ジャッジ時間 | 4,867 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge4 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 2 | 
| other | AC * 20 | 
コンパイルメッセージ
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;
      |                               ^~
            
            ソースコード
#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;
}
            
            
            
        
            
Rho