結果

問題 No.2627 Unnatural Pitch
ユーザー 👑 kmjpkmjp
提出日時 2024-02-10 00:17:51
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,673 bytes
コンパイル時間 2,264 ms
コンパイル使用メモリ 206,384 KB
実行使用メモリ 9,812 KB
最終ジャッジ日時 2024-02-10 00:17:56
合計ジャッジ時間 4,275 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 5 ms
8,288 KB
testcase_03 AC 2 ms
6,676 KB
testcase_04 AC 31 ms
9,804 KB
testcase_05 AC 32 ms
9,804 KB
testcase_06 WA -
testcase_07 AC 27 ms
7,008 KB
testcase_08 AC 36 ms
7,008 KB
testcase_09 AC 34 ms
9,804 KB
testcase_10 AC 34 ms
9,804 KB
testcase_11 WA -
testcase_12 AC 2 ms
6,676 KB
testcase_13 WA -
testcase_14 AC 2 ms
6,676 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 23 ms
8,880 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 28 ms
9,072 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define FORR2(x,y,arr) for(auto& [x,y]:arr)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
template<class T> bool chmax(T &a, const T &b) { if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a, const T &b) { if(a>b){a=b;return 1;}return 0;}
//-------------------------------------------------------

ll N,K;
ll L,U;
ll A[202020];

ll sum[604040];

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>K>>L>>U;
	ll D=U-L;
	FOR(i,N) cin>>A[i];
	sort(A,A+N);
	L=0;
	for(i=50;i>=0;i--) {
		ll TL=L+(1LL<<i);
		ll L1=lower_bound(A,A+N,TL)-A;
		ll R1=A+N-lower_bound(A,A+N,TL+D+1);
		if(L1<=R1) L=TL;
	}
	ll SL=max(0LL,L-K);
	ll SR=L+K;
	
	FOR(i,N) {
		if(A[i]<SL) {
			ll pat=(SL-A[i]+K-1)/K;
			sum[0]+=pat;
			int dif=K-(SL-A[i])%K;
			sum[dif]++;
			sum[dif+K]++;
			sum[dif+2*K]++;
		}
		else if(A[i]<=SL+D) {
			sum[min(2*K+2,A[i]-SL+1)]++;
			sum[min(2*K+2,A[i]-SL+1+K)]++;
			sum[min(2*K+2,A[i]-SL+1+2*K)]++;
		}
		else {
			int d=(A[i]-(SL+D))%K;
			if(d==0) d+=K;
			sum[0]+=(A[i]-(SL+D)+K-1)/K;
			sum[d]--;
			if((A[i]-(SL+D)+K-1)/K>1) sum[d+K]--;
		}
		
	}
	ll mi=1LL<<60;
	FOR(i,SR-SL+1) {
		if(i) sum[i]+=sum[i-1];
		mi=min(mi,sum[i]);
	}
	cout<<mi<<endl;
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}
0