結果

問題 No.2627 Unnatural Pitch
ユーザー 👑 kmjpkmjp
提出日時 2024-02-10 10:24:59
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 45 ms / 4,000 ms
コード長 1,855 bytes
コンパイル時間 2,697 ms
コンパイル使用メモリ 206,380 KB
実行使用メモリ 9,808 KB
最終ジャッジ日時 2024-02-10 10:25:04
合計ジャッジ時間 4,505 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
6,548 KB
testcase_01 AC 2 ms
6,548 KB
testcase_02 AC 4 ms
8,288 KB
testcase_03 AC 2 ms
6,548 KB
testcase_04 AC 32 ms
9,804 KB
testcase_05 AC 31 ms
9,804 KB
testcase_06 AC 29 ms
9,804 KB
testcase_07 AC 27 ms
7,008 KB
testcase_08 AC 38 ms
7,008 KB
testcase_09 AC 31 ms
9,804 KB
testcase_10 AC 32 ms
9,804 KB
testcase_11 AC 3 ms
6,548 KB
testcase_12 AC 3 ms
6,548 KB
testcase_13 AC 3 ms
6,548 KB
testcase_14 AC 2 ms
6,548 KB
testcase_15 AC 2 ms
6,548 KB
testcase_16 AC 43 ms
7,648 KB
testcase_17 AC 45 ms
9,804 KB
testcase_18 AC 43 ms
7,264 KB
testcase_19 AC 44 ms
9,808 KB
testcase_20 AC 16 ms
6,548 KB
testcase_21 AC 21 ms
8,880 KB
testcase_22 AC 35 ms
9,388 KB
testcase_23 AC 19 ms
8,836 KB
testcase_24 AC 27 ms
6,880 KB
testcase_25 AC 25 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);
	
	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-1)%K;
			sum[dif]++;
			sum[dif+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)]++;
		}
		else {
			int d=(A[i]-(SL+D))%K;
			//d++;
			if(d==0) d=K;
			assert((A[i]-(SL+D)+K-1)/K>0);
			//cout<<"!"<<k<<" "<<(A[i]-(SL+D)+K-1)/K<<endl;
			//cout<<"!"<<(A[i])<<" "<<(SL+D)<<" "<<d<<" "<<SL+d<<" "<<SL+d+K<<endl;
			sum[0]+=(A[i]-(SL+D)+K-1)/K;
			sum[d]--;
			if((A[i]-(SL+D)+K-1)/K>1) sum[d+K]--;
			if(A[i]<=SL+2*K) {
				sum[A[i]-SL+1]++;
				sum[A[i]-SL+1+K]++;
			}
		}
		
	}
	ll mi=1LL<<60;
	FOR(i,2*K+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