結果

問題 No.1028 闇討ち
コンテスト
ユーザー Thistle
提出日時 2020-03-28 18:26:01
言語 C++14
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=c++14 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
CE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,080 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 395 ms
コンパイル使用メモリ 63,472 KB
最終ジャッジ日時 2026-03-24 07:56:00
合計ジャッジ時間 1,782 ms
ジャッジサーバーID
(参考情報)
judge3_1 / judge2_0
このコードへのチャレンジ
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。

コンパイルメッセージ
main.cpp:6:12: error: 'int_fast64_t' does not name a type
    6 | using ll = int_fast64_t;
      |            ^~~~~~~~~~~~
main.cpp:12:1: error: 'll' does not name a type
   12 | ll read() { ll u, k = scanf("%lld", &u); return u; }
      | ^~
main.cpp:7:13: error: 'll' does not name a type
    7 | #define int ll
      |             ^~
main.cpp:14:1: note: in expansion of macro 'int'
   14 | int n;
      | ^~~
main.cpp:7:13: error: 'll' does not name a type
    7 | #define int ll
      |             ^~
main.cpp:15:1: note: in expansion of macro 'int'
   15 | int a[2000][2000];
      | ^~~
main.cpp:7:13: error: 'll' does not name a type
    7 | #define int ll
      |             ^~
main.cpp:16:1: note: in expansion of macro 'int'
   16 | int b[2000];//現在のコスト
      | ^~~
main.cpp:7:13: error: 'll' does not name a type
    7 | #define int ll
      |             ^~
main.cpp:17:1: note: in expansion of macro 'int'
   17 | int ans[2000];//答えのコスト
      | ^~~
main.cpp:7:13: error: 'll' does not name a type
    7 | #define int ll
      |             ^~
main.cpp:18:1: note: in expansion of macro 'int'
   18 | int c[2000][2];
      | ^~~
main.cpp: In function 'void solve()':
main.cpp:20:16: error: 'n' was not declared in this scope
   20 |         cin >> n;
      |                ^
main.cpp:21:13: error: 'i' was not declared in this scope
   21 |         rep(i, n)rep(j, n) {
      |             ^
main.cpp:8:27: note: in definition of macro 'rep'
    8 | #define rep(i,n) for(int (i) = 0 ; (i) < (n) ; (i)++)
      |                           ^
main.cpp:7:13: error: 'll' was not declared in this scope
    7 | #define int ll
      |             ^~
main.cpp:8:22: note: in expansion of macro 'int'
    8 | #define rep(i,n) for(int (i) = 0 ; (i) < (n) ; (i)++)
      |                      ^~~
main.cpp:21:9: note: in expansion of macro 'rep'
   21 |         rep(i, n)rep(j, n) {
      |         ^~~
main.cpp:21:22: error: 'j' was not declared in this scope
   21 | 

ソースコード

diff #
raw source code

#include<iostream>
#include<string>
#include<algorithm>

using namespace std;
using ll = int_fast64_t;
#define int ll
#define rep(i,n) for(int (i) = 0 ; (i) < (n) ; (i)++)
#define rng(i,s,n) for(int (i) = (s) ; (i) < (n) ; (i)++)
template<class T>bool chmax(T & a, const T & b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T & a, const T & b) { if (b < a) { a = b; return 1; } return 0; }
ll read() { ll u, k = scanf("%lld", &u); return u; }

int n;
int a[2000][2000];
int b[2000];//現在のコスト
int ans[2000];//答えのコスト
int c[2000][2];
void solve() {
	cin >> n;
	rep(i, n)rep(j, n) {
		a[i][j] = read() - 1;
		b[a[i][j]] += i + j - min(i, j);
		if (j < i) c[a[i][j]][1]++;
	}
	rep(i, n) {
		ans[i] = b[i];
	}
	rep(i, n) {
		for (int j = 0; i - j >= 0; j++) {
			c[a[i - j][j]][0]++;
		}
		rep(j, n) {
			b[j] += c[j][0] - c[j][1];
		}
		rep(j, n) chmin(ans[j], b[j]);
		for (int j = 0; i + j + 1 < n; j++) {
			c[a[i + j + 1][j]][1]--;
		}
	}
	int sum = 0;
	rep(i, n) sum += ans[i];
	cout << sum << endl;
}
signed main() {
	solve();
}
0