提出 #74277169


ソースコード 拡げる

#include<bits/stdc++.h>
#define int long long
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
bool st;
using namespace std;
/*Ctrl+Alt+G F*/
namespace AC{
namespace Fread{const int SIZE=1<<16;char buf[SIZE],*S,*T;inline char getchar(){if(S==T){T=(S=buf)+fread(buf,1,SIZE,stdin);if(S==T)return'\n';}return *S++;}}namespace Fwrite{const int SIZE=1<<16;char buf[SIZE],*S=buf,*T=buf+SIZE;inline void flush(){fwrite(buf,1,S-buf,stdout);S=buf;}inline void putchar(char c){*S++=c;if(S==T)flush();}struct NTR{~NTR(){flush();}}ztr;}
#define getchar Fread::getchar
#define putchar Fwrite::putchar
#define Setprecision 15
#define between ' '
template<typename T>struct is_char{static constexpr bool value=(std::is_same<T,char>::value||std::is_same<T,signed char>::value||std::is_same<T,unsigned char>::value);};template<typename T>struct is_integral_ex{static constexpr bool value=(std::is_integral<T>::value||std::is_same<T,__int128>::value)&&!is_char<T>::value;};template<typename T>struct is_floating_point_ex{static constexpr bool value=std::is_floating_point<T>::value||std::is_same<T,__float128>::value;};namespace Fastio{struct Reader{template<typename T>typename std::enable_if_t<std::is_class<T>::value,Reader&>operator>>(T&x){for(auto &y:x)*this>>y;return *this;}template<typename T>typename std::enable_if_t<is_integral_ex<T>::value,Reader&>operator>>(T&x){char c=getchar();short f=1;while(c<'0'||c>'9'){if(c=='-')f*=-1;c=getchar();}x=0;while(c>='0'&&c<='9'){x=(x<<1)+(x<<3)+(c^48);c=getchar();}x*=f;return *this;}template<typename T>typename std::enable_if_t<is_floating_point_ex<T>::value,Reader&>operator>>(T&x){char c=getchar();short f=1,s=0;x=0;T t=0;while((c<'0'||c>'9')&&c!='.'){if(c=='-')f*=-1;c=getchar();}while(c>='0'&&c<='9'&&c!='.')x=x*10+(c^48),c=getchar();if(c=='.')c=getchar();else return x*=f,*this;while(c>='0'&&c<='9')t=t*10+(c^48),s++,c=getchar();while(s--)t/=10.0;x=(x+t)*f;return*this;}template<typename T>typename std::enable_if_t<is_char<T>::value,Reader&>operator>>(T&c){c=getchar();while(c=='\n'||c==' '||c=='\r')c=getchar();return *this;}Reader&operator>>(char*str){int len=0;char c=getchar();while(c=='\n'||c==' '||c=='\r')c=getchar();while(c!='\n'&&c!=' '&&c!='\r')str[len++]=c,c=getchar();str[len]='\0';return*this;}Reader&operator>>(std::string&str){str.clear();char c=getchar();while(c=='\n'||c==' '||c=='\r')c=getchar();while(c!='\n'&&c!=' '&&c!='\r')str.push_back(c),c=getchar();return*this;}Reader(){}}cin;const char endl='\n';struct Writer{typedef __int128 mxdouble;template<typename T>typename std::enable_if_t<std::is_class<T>::value,Writer&>operator<<(T x){for(auto &y:x)*this<<y<<between;*this<<'\n';return *this;}template<typename T>typename std::enable_if_t<is_integral_ex<T>::value,Writer&>operator<<(T x){if(x==0)return putchar('0'),*this;if(x<0)putchar('-'),x=-x;static int sta[45];int top=0;while(x)sta[++top]=x%10,x/=10;while(top)putchar(sta[top]+'0'),--top;return*this;}template<typename T>typename std::enable_if_t<is_floating_point_ex<T>::value,Writer&>operator<<(T x){if(x<0)putchar('-'),x=-x;x+=pow(10,-Setprecision)/2;mxdouble _=x;x-=(T)_;static int sta[45];int top=0;while(_)sta[++top]=_%10,_/=10;if(!top)putchar('0');while(top)putchar(sta[top]+'0'),--top;putchar('.');for(int i=0;i<Setprecision;i++)x*=10;_=x;while(_)sta[++top]=_%10,_/=10;for(int i=0;i<Setprecision-top;i++)putchar('0');while(top)putchar(sta[top]+'0'),--top;return*this;}template<typename T>typename std::enable_if_t<is_char<T>::value,Writer&>operator<<(T c){putchar(c);return*this;}Writer&operator<<(char*str){int cur=0;while(str[cur])putchar(str[cur++]);return *this;}Writer&operator<<(const char*str){int cur=0;while(str[cur])putchar(str[cur++]);return*this;}Writer&operator<<(std::string str){int st=0,ed=str.size();while(st<ed)putchar(str[st++]);return*this;}Writer(){}void flush(){Fwrite::flush();}}cout;}
#undef Setprecision
using Fastio::cin;
using Fastio::cout;
using Fastio::endl;
using istream=Fastio::Reader;
using ostream=Fastio::Writer;
void solve(){
	int N,K;
	cin>>N>>K;
	vector<int>A(N);
	for(int i=0;i<N;++i)cin>>A[i];
	vector<int>r(N);
	for(int i=0;i<N;++i)r[i]=A[i]%K;
	sort(r.begin(),r.end());
	int ans=r.back()-r[0];
	for(int i=0;i<N-1;++i)ans=min(ans,r[i]+K-r[i+1]);
	cout<<ans<<endl;
}
}
bool ed;
signed main(){
#ifdef debug
	cerr<<"----------------------------------- START -----------------------------------\n";
#endif
	int t=1;
	//cin>>t;
	while(t--)AC::solve();
#ifdef debug
	cerr<<"\n--------------------------------- INPUT END ---------------------------------\n";
	AC::cout.flush();
	cerr<<"\n------------------------------------ END ------------------------------------\n";
	cerr<<setprecision(3)<<fixed<<"Total Memory : "<<left<<setw(10)<<(&ed-&st)/1048576.0<<" \tMB\n"<<"               "<<left<<setw(10)<<(&ed-&st)/1024.0<<" \tKB\n"<<"               "<<left<<setw(10)<<(&ed-&st)<<" \tByte\n";
#endif
}

提出情報

提出日時
問題 D - Minimize Range
ユーザ nut321
言語 C++23 (GCC 15.2.0)
得点 400
コード長 4925 Byte
結果 AC
実行時間 15 ms
メモリ 6536 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 400 / 400
結果
AC × 2
AC × 44
セット名 テストケース
Sample 00_sample_01.txt, 00_sample_02.txt
All 00_sample_01.txt, 00_sample_02.txt, 01_01.txt, 01_02.txt, 01_03.txt, 01_04.txt, 01_05.txt, 01_06.txt, 01_07.txt, 01_08.txt, 01_09.txt, 01_10.txt, 01_11.txt, 01_12.txt, 01_13.txt, 01_14.txt, 01_15.txt, 01_16.txt, 01_17.txt, 01_18.txt, 01_19.txt, 01_20.txt, 02_01.txt, 02_02.txt, 02_03.txt, 02_04.txt, 02_05.txt, 02_06.txt, 02_07.txt, 02_08.txt, 02_09.txt, 02_10.txt, 02_11.txt, 02_12.txt, 03_01.txt, 03_02.txt, 03_03.txt, 03_04.txt, 03_05.txt, 03_06.txt, 03_07.txt, 03_08.txt, 03_09.txt, 03_10.txt
ケース名 結果 実行時間 メモリ
00_sample_01.txt AC 1 ms 3540 KiB
00_sample_02.txt AC 1 ms 3480 KiB
01_01.txt AC 8 ms 4796 KiB
01_02.txt AC 9 ms 4948 KiB
01_03.txt AC 13 ms 5924 KiB
01_04.txt AC 7 ms 4684 KiB
01_05.txt AC 5 ms 4280 KiB
01_06.txt AC 4 ms 3944 KiB
01_07.txt AC 2 ms 3576 KiB
01_08.txt AC 3 ms 3772 KiB
01_09.txt AC 11 ms 5316 KiB
01_10.txt AC 2 ms 3732 KiB
01_11.txt AC 5 ms 4244 KiB
01_12.txt AC 7 ms 4668 KiB
01_13.txt AC 3 ms 3768 KiB
01_14.txt AC 6 ms 4536 KiB
01_15.txt AC 4 ms 4116 KiB
01_16.txt AC 1 ms 3724 KiB
01_17.txt AC 11 ms 5488 KiB
01_18.txt AC 10 ms 5324 KiB
01_19.txt AC 14 ms 6088 KiB
01_20.txt AC 10 ms 5356 KiB
02_01.txt AC 1 ms 3536 KiB
02_02.txt AC 1 ms 3540 KiB
02_03.txt AC 1 ms 3536 KiB
02_04.txt AC 1 ms 3472 KiB
02_05.txt AC 1 ms 3436 KiB
02_06.txt AC 1 ms 3436 KiB
02_07.txt AC 4 ms 6316 KiB
02_08.txt AC 5 ms 6536 KiB
02_09.txt AC 5 ms 6476 KiB
02_10.txt AC 4 ms 6536 KiB
02_11.txt AC 5 ms 6328 KiB
02_12.txt AC 15 ms 6456 KiB
03_01.txt AC 15 ms 6456 KiB
03_02.txt AC 15 ms 6456 KiB
03_03.txt AC 15 ms 6336 KiB
03_04.txt AC 15 ms 6476 KiB
03_05.txt AC 15 ms 6380 KiB
03_06.txt AC 15 ms 6348 KiB
03_07.txt AC 15 ms 6336 KiB
03_08.txt AC 15 ms 6348 KiB
03_09.txt AC 15 ms 6348 KiB
03_10.txt AC 15 ms 6384 KiB