結果

問題 No.2603 Tone Correction
ユーザー inksamuraiinksamurai
提出日時 2024-01-13 02:29:51
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 99 ms / 2,000 ms
コード長 1,162 bytes
コンパイル時間 3,526 ms
コンパイル使用メモリ 218,688 KB
実行使用メモリ 11,212 KB
最終ジャッジ日時 2024-01-13 02:29:59
合計ジャッジ時間 7,199 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 2 ms
6,676 KB
testcase_03 AC 3 ms
6,676 KB
testcase_04 AC 3 ms
6,676 KB
testcase_05 AC 4 ms
6,676 KB
testcase_06 AC 3 ms
6,676 KB
testcase_07 AC 3 ms
6,676 KB
testcase_08 AC 4 ms
6,676 KB
testcase_09 AC 3 ms
6,676 KB
testcase_10 AC 3 ms
6,676 KB
testcase_11 AC 3 ms
6,676 KB
testcase_12 AC 3 ms
6,676 KB
testcase_13 AC 78 ms
11,212 KB
testcase_14 AC 77 ms
11,212 KB
testcase_15 AC 79 ms
11,212 KB
testcase_16 AC 78 ms
11,212 KB
testcase_17 AC 77 ms
11,212 KB
testcase_18 AC 78 ms
11,212 KB
testcase_19 AC 99 ms
11,212 KB
testcase_20 AC 79 ms
11,212 KB
testcase_21 AC 81 ms
11,212 KB
testcase_22 AC 81 ms
11,212 KB
testcase_23 AC 68 ms
11,212 KB
testcase_24 AC 68 ms
11,212 KB
testcase_25 AC 67 ms
11,212 KB
testcase_26 AC 66 ms
11,212 KB
testcase_27 AC 67 ms
11,212 KB
testcase_28 AC 67 ms
11,212 KB
testcase_29 AC 67 ms
11,212 KB
testcase_30 AC 67 ms
11,212 KB
testcase_31 AC 68 ms
11,212 KB
testcase_32 AC 67 ms
11,212 KB
testcase_33 AC 3 ms
6,676 KB
testcase_34 AC 61 ms
11,212 KB
testcase_35 AC 61 ms
11,212 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define int ll
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define rng(i,c,n) for(int i=c;i<n;i++)
#define fi first
#define se second
#define pb push_back
#define sz(a) (int)a.size()
#define vec(...) vector<__VA_ARGS__>
#define _4aNWZeC ios::sync_with_stdio(0),cin.tie(0)
using ll=long long;
using pii=pair<int,int>;
using vi=vector<int>;
void print(){cout<<'\n';}
template<class h,class...t>
void print(const h&v,const t&...u){cout<<v<<' ',print(u...);}

void slv(){
	int n,m;
	cin>>n>>m;
	vi a(n);
	rep(i,n){
		cin>>a[i];
	}
	vi b(n);
	rep(i,n){
		cin>>b[i];
	}
	vi d(n);
	rep(i,n){
		d[i]=(a[i]-b[i]+m)%m;
	}
	vi nd;
	nd.pb(d[0]);
	rng(i,1,n){
		nd.pb((d[i]-d[i-1]+m)%m);
	}
	nd.pb((2*m-d.back())%m);
	d=nd;
	n+=1;
	int ans=0;
	deque<int> dq(d.begin(), d.end());
	sort(dq.begin(), dq.end());
	while(1){
		while(sz(dq) and dq.front()==0) dq.pop_front();
		while(sz(dq) and dq.back()==m) dq.pop_back();
		if(!sz(dq)) break;
		assert(sz(dq)>1);
		int val=min(dq[0],m-dq.back());
		dq[0]-=val;
		dq.back()+=val;
		ans+=val;
	}
	cout<<ans<<"\n";
}

signed main(){
_4aNWZeC;
	slv();
}
0