結果

問題 No.1028 闇討ち
ユーザー kotatsugamekotatsugame
提出日時 2020-04-22 03:28:12
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 289 ms / 2,000 ms
コード長 549 bytes
コンパイル時間 728 ms
コンパイル使用メモリ 67,696 KB
実行使用メモリ 11,520 KB
最終ジャッジ日時 2024-04-18 06:03:51
合計ジャッジ時間 5,189 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 10 ms
5,376 KB
testcase_10 AC 13 ms
5,376 KB
testcase_11 AC 54 ms
7,296 KB
testcase_12 AC 226 ms
11,136 KB
testcase_13 AC 250 ms
11,008 KB
testcase_14 AC 138 ms
9,344 KB
testcase_15 AC 38 ms
6,656 KB
testcase_16 AC 289 ms
11,360 KB
testcase_17 AC 243 ms
11,472 KB
testcase_18 AC 260 ms
11,520 KB
testcase_19 AC 274 ms
11,392 KB
testcase_20 AC 240 ms
11,392 KB
testcase_21 AC 266 ms
11,348 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:6:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
    6 | main()
      | ^~~~

ソースコード

diff #

#include<iostream>
#include<algorithm>
using namespace std;
int N;
int s[2][1000][1001];
main()
{
	cin>>N;
	for(int i=0;i<N;i++)for(int j=0;j<N;j++)
	{
		int A;cin>>A;A--;
		s[1][A][0]+=j;
		if(j<i)
		{
			s[1][A][0]+=i-j;
			s[0][A][1]--;
			s[0][A][i-j+1]++;
		}
		if(i+j<N)
		{
			s[0][A][i+j+1]++;
		}
	}
	int ans=0;
	for(int A=0;A<N;A++)
	{
		int now=1e9;
		for(int i=0;i<N;i++)
		{
			s[1][A][i]+=s[0][A][i];
			if(now>s[1][A][i])now=s[1][A][i];
			s[0][A][i+1]+=s[0][A][i];
			s[1][A][i+1]+=s[1][A][i];
		}
		ans+=now;
	}
	cout<<ans<<endl;
}
0