結果

問題 No.2603 Tone Correction
ユーザー 沙耶花沙耶花
提出日時 2024-01-12 21:58:30
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 884 bytes
コンパイル時間 4,366 ms
コンパイル使用メモリ 265,128 KB
実行使用メモリ 13,480 KB
最終ジャッジ日時 2024-01-12 21:59:17
合計ジャッジ時間 25,799 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
13,480 KB
testcase_01 AC 4 ms
6,676 KB
testcase_02 AC 8 ms
6,676 KB
testcase_03 AC 1,670 ms
6,676 KB
testcase_04 AC 1,680 ms
6,676 KB
testcase_05 AC 1,668 ms
6,676 KB
testcase_06 AC 1,677 ms
6,676 KB
testcase_07 AC 1,685 ms
6,676 KB
testcase_08 AC 1,666 ms
6,676 KB
testcase_09 AC 1,668 ms
6,676 KB
testcase_10 AC 1,685 ms
6,676 KB
testcase_11 AC 1,663 ms
6,676 KB
testcase_12 AC 1,667 ms
6,676 KB
testcase_13 TLE -
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 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace atcoder;
using mint = modint998244353;
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf32 1000000001
#define Inf64 1000000000000000001


int main(){
	
	long long n,m;
	cin>>n>>m;
	vector<long long> a(n),b(n);
	rep(i,n)scanf("%lld",&a[i]);
	rep(i,n)scanf("%lld",&b[i]);
	
	rep(i,n){
		a[i] -= b[i];
		a[i] += m;
		a[i] %= m;
	}
	a.insert(a.begin(),0LL);
	a.push_back(0);
	vector<long long> dp(600,Inf64);
	dp[dp.size()/2] = 0;
	for(int i=1;i<a.size();i++){
		vector<long long> ndp(600,Inf64);
		rep(j,dp.size()){
			long long x = a[i-1];
			x -= m;
			x += m*j;
			rep(k,dp.size()){
				long long y = a[i];
				y -= m;
				y += m*k;
				ndp[k] = min(ndp[k],dp[j] + abs(x-y));
			}
		}
		swap(dp,ndp);
	}
	long long ans = dp[dp.size()/2];
	cout<<ans/2<<endl;
	return 0;
}
0