結果

問題 No.2603 Tone Correction
ユーザー kotatsugamekotatsugame
提出日時 2024-01-12 22:32:36
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 72 ms / 2,000 ms
コード長 714 bytes
コンパイル時間 775 ms
コンパイル使用メモリ 70,260 KB
実行使用メモリ 11,232 KB
最終ジャッジ日時 2024-01-12 22:32:44
合計ジャッジ時間 3,973 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
9,696 KB
testcase_01 AC 3 ms
9,696 KB
testcase_02 AC 3 ms
9,696 KB
testcase_03 AC 4 ms
9,712 KB
testcase_04 AC 4 ms
9,712 KB
testcase_05 AC 4 ms
9,712 KB
testcase_06 AC 4 ms
9,712 KB
testcase_07 AC 5 ms
9,712 KB
testcase_08 AC 4 ms
9,712 KB
testcase_09 AC 4 ms
9,712 KB
testcase_10 AC 4 ms
9,712 KB
testcase_11 AC 4 ms
9,712 KB
testcase_12 AC 4 ms
9,712 KB
testcase_13 AC 71 ms
11,232 KB
testcase_14 AC 71 ms
11,232 KB
testcase_15 AC 72 ms
11,232 KB
testcase_16 AC 71 ms
11,232 KB
testcase_17 AC 71 ms
11,232 KB
testcase_18 AC 71 ms
11,232 KB
testcase_19 AC 70 ms
11,232 KB
testcase_20 AC 71 ms
11,232 KB
testcase_21 AC 72 ms
11,232 KB
testcase_22 AC 71 ms
11,232 KB
testcase_23 AC 57 ms
11,232 KB
testcase_24 AC 57 ms
11,232 KB
testcase_25 AC 58 ms
11,232 KB
testcase_26 AC 57 ms
11,232 KB
testcase_27 AC 58 ms
11,232 KB
testcase_28 AC 57 ms
11,232 KB
testcase_29 AC 58 ms
11,232 KB
testcase_30 AC 57 ms
11,232 KB
testcase_31 AC 57 ms
11,232 KB
testcase_32 AC 57 ms
11,232 KB
testcase_33 AC 3 ms
9,696 KB
testcase_34 AC 57 ms
11,232 KB
testcase_35 AC 57 ms
11,232 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<algorithm>
#include<cassert>
using namespace std;
int N,M;
int A[2<<17],B[2<<17];
long long D[2<<17],UP[2<<17],DOWN[2<<17];
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cin>>N>>M;
	for(int i=0;i<N;i++)cin>>A[i];
	for(int i=0;i<N;i++)cin>>B[i];
	for(int i=0;i<N;i++)
	{
		int d=B[i]-A[i];
		d%=M;
		if(d<0)d+=M;
		D[i+1]=d;
	}
	long long base=0;
	for(int i=1;i<=N+1;i++)
	{
		long long now=abs(D[i]-D[i-1]);
		base+=now;
		UP[i-1]=abs(D[i]+M-D[i-1])-now;
		DOWN[i-1]=abs(D[i]-M-D[i-1])-now;
	}
	sort(UP,UP+N+1);
	sort(DOWN,DOWN+N+1);
	long long ans=base;
	for(int c=1;c<=(N+1)/2;c++)
	{
		base+=UP[c-1];
		base+=DOWN[c-1];
		ans=min(ans,base);
	}
	cout<<ans/2<<endl;
}
0