結果

問題 No.1838 Modulo Straight
ユーザー publfl2publfl2
提出日時 2022-02-11 23:15:55
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 891 bytes
コンパイル時間 608 ms
コンパイル使用メモリ 49,028 KB
実行使用メモリ 35,232 KB
最終ジャッジ日時 2023-09-10 06:06:19
合計ジャッジ時間 5,504 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
22,356 KB
testcase_01 AC 5 ms
15,304 KB
testcase_02 AC 5 ms
15,228 KB
testcase_03 AC 5 ms
15,288 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 TLE -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <vector>

int x[400010];
std::vector<int> V[400010];

int sum1[400010],sum2[400010],check[400010];
int main()
{
	int a,b;
	scanf("%d%d",&a,&b);
	for(int i=1;i<=a*b;i++) scanf("%d",&x[i]);
	
	for(int i=1;i<=a*b;i++) V[x[i]].push_back(i);
	
	for(int j=0;j<a;j++)
	{
		for(int i=0;i<=a;i++) sum1[i] = sum2[i] = 0;
		
		for(int i=0;i<V[j].size();i++)
		{
			int t = V[j][i]-i*a;
			if(t<0)
			{
				sum1[1]+=1;
				sum2[1]-=t;
			}
			else
			{
				sum1[1]-=1;
				sum2[1]+=t;
				if(t<=a)
				{
					sum1[t]+=2;
					sum2[t]-=2*t;
				}
			}
		}
		
		for(int i=1;i<=a;i++) sum1[i] += sum1[i-1];
		for(int i=1;i<=a;i++) sum2[i] += sum2[i-1];
		
		int s1 = 0, s2 = 0;
		for(int i=1;i<=a;i++)
		{
			s1 += sum1[i], s2 += sum2[i];
			check[(i-j+a)%a] += s1*i+s2;
		}
	}
	
	int min = check[0];
	for(int i=0;i<a;i++) min = min<check[i]?min:check[i];
	printf("%d",min/3);
}
0