Submission #65257984


Source Code Expand

#include<bits/stdc++.h>
#define ll long long
#define mid ((l+r)>>1)
using namespace std;
const int N=5e5+5;
int n,m,ans;
int a[N],f[N],g[N],cnt[N<<1];
signed main(){
	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	cin>>n>>m;
	for(int i=1;i<=n;i++){cin>>a[i];cnt[a[i]]++;}
	sort(a+1,a+n+1);
	int nn=(int)(unique(a+1,a+n+1)-a-1);
	if(m==0){
		cout<<n-nn;
		return 0;
	}
	sort(a+1,a+nn+1,[](int A,int B){return (A%m==B%m?A<B:A%m<B%m);});
	a[0]=-1e9;
	for(int i=1;i<=nn;i++){
		if(a[i]-a[i-1]==m)f[i]=g[i-2]+cnt[a[i]];
		else f[i]=g[i-1]+cnt[a[i]];
		g[i]=max(f[i],g[i-1]);
		ans=max(ans,f[i]);
	}
	cout<<n-ans;
	return 0;
}

Submission Info

Submission Time
Task D - Forbidden Difference
User catluo
Language C++ 17 (gcc 12.2)
Score 425
Code Size 651 Byte
Status AC
Exec Time 51 ms
Memory 9736 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 425 / 425
Status
AC × 3
AC × 40
Set Name Test Cases
Sample 00_sample_01.txt, 00_sample_02.txt, 00_sample_03.txt
All 00_sample_01.txt, 00_sample_02.txt, 00_sample_03.txt, 01_random_01.txt, 01_random_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 01_random_10.txt, 01_random_11.txt, 01_random_12.txt, 01_random_13.txt, 01_random_14.txt, 01_random_15.txt, 01_random_16.txt, 01_random_17.txt, 01_random_18.txt, 01_random_19.txt, 01_random_20.txt, 01_random_21.txt, 01_random_22.txt, 01_random_23.txt, 01_random_24.txt, 01_random_25.txt, 01_random_26.txt, 01_random_27.txt, 01_random_28.txt, 01_random_29.txt, 01_random_30.txt, 01_random_31.txt, 01_random_32.txt, 02_handmade_01.txt, 02_handmade_02.txt, 02_handmade_03.txt, 02_handmade_04.txt, 02_handmade_05.txt
Case Name Status Exec Time Memory
00_sample_01.txt AC 1 ms 3580 KiB
00_sample_02.txt AC 1 ms 3516 KiB
00_sample_03.txt AC 1 ms 3416 KiB
01_random_01.txt AC 11 ms 4280 KiB
01_random_02.txt AC 2 ms 3648 KiB
01_random_03.txt AC 11 ms 4296 KiB
01_random_04.txt AC 4 ms 3864 KiB
01_random_05.txt AC 11 ms 4284 KiB
01_random_06.txt AC 9 ms 4188 KiB
01_random_07.txt AC 11 ms 4220 KiB
01_random_08.txt AC 7 ms 3960 KiB
01_random_09.txt AC 14 ms 4356 KiB
01_random_10.txt AC 12 ms 4080 KiB
01_random_11.txt AC 13 ms 4300 KiB
01_random_12.txt AC 10 ms 4104 KiB
01_random_13.txt AC 14 ms 4232 KiB
01_random_14.txt AC 6 ms 3908 KiB
01_random_15.txt AC 14 ms 4412 KiB
01_random_16.txt AC 4 ms 3616 KiB
01_random_17.txt AC 19 ms 4476 KiB
01_random_18.txt AC 16 ms 4236 KiB
01_random_19.txt AC 21 ms 4412 KiB
01_random_20.txt AC 13 ms 4096 KiB
01_random_21.txt AC 20 ms 4308 KiB
01_random_22.txt AC 19 ms 4364 KiB
01_random_23.txt AC 19 ms 4288 KiB
01_random_24.txt AC 11 ms 4072 KiB
01_random_25.txt AC 49 ms 9680 KiB
01_random_26.txt AC 10 ms 7760 KiB
01_random_27.txt AC 51 ms 9736 KiB
01_random_28.txt AC 12 ms 7888 KiB
01_random_29.txt AC 51 ms 9476 KiB
01_random_30.txt AC 45 ms 9372 KiB
01_random_31.txt AC 27 ms 8192 KiB
01_random_32.txt AC 11 ms 7980 KiB
02_handmade_01.txt AC 11 ms 4208 KiB
02_handmade_02.txt AC 11 ms 4276 KiB
02_handmade_03.txt AC 1 ms 3492 KiB
02_handmade_04.txt AC 1 ms 3416 KiB
02_handmade_05.txt AC 1 ms 3424 KiB