提出 #38018504


ソースコード 拡げる

#include <bits/stdc++.h>
using namespace std;
//#define OPENIOBUF

namespace FastIO
{

class FastIOBase
{
 protected:
#ifdef OPENIOBUF
	static const int BUFSIZE=1<<22;
	char buf[BUFSIZE+1];
	int buf_p=0;
#endif
	FILE *target;
 public:
#ifdef OPENIOBUF
	virtual void flush()=0;
#endif
	FastIOBase(FILE *f): target(f){}
	~FastIOBase()=default;
};

class FastOutput: public FastIOBase
{
#ifdef OPENIOBUF
 public:
	inline void flush()
		{ fwrite(buf,1,buf_p,target),buf_p=0; }
#endif
 protected:
	inline void __putc(char x)
	{
#ifdef OPENIOBUF
		if(buf[buf_p++]=x,buf_p==BUFSIZE)flush();
#else
		putc(x,target);
#endif
	}
	template<typename T>
	inline void __write(T x)
	{
		static char stk[64],*top;top=stk;
		if(x<0) return __putc('-'),__write(-x);
		do *(top++)=x%10,x/=10; while(x);
		for(;top!=stk;__putc(*(--top)+'0'));
	}
 public:
	FastOutput(FILE *f=stdout): FastIOBase(f){}
#ifdef OPENIOBUF
	~FastOutput(){ flush(); }
#endif
	template<typename ...T>
	inline void writesp(const T &...x)
		{ initializer_list<int>{(this->operator<<(x),__putc(' '),0)...}; }
	template<typename ...T>
	inline void writeln(const T &...x)
		{ initializer_list<int>{(this->operator<<(x),__putc('\n'),0)...}; }
	inline FastOutput &operator <<(char x)
		{ return __putc(x),*this; }
	inline FastOutput &operator <<(const char *s)
		{ for(;*s;__putc(*(s++)));return *this; }
	inline FastOutput &operator <<(const string &s)
		{ return (*this)<<s.c_str(); }
	template<typename T,typename=typename enable_if<is_integral<T>::value>::type>
	inline FastOutput &operator <<(const T &x)
		{ return __write(x),*this; }
}qout;

class FastInput: public FastIOBase
{
#ifdef OPENIOBUF
 public:
	inline void flush()
		{ buf[fread(buf,1,BUFSIZE,target)]='\0',buf_p=0; }
#endif
 protected:
	inline char __getc()
	{
#ifdef OPENIOBUF
		if(buf_p==BUFSIZE) flush();
		return buf[buf_p++];
#else
		return getc(target);
#endif
	}
 public:
#ifdef OPENIOBUF
	FastInput(FILE *f=stdin): FastIOBase(f){ buf_p=BUFSIZE; }
#else
	FastInput(FILE *f=stdin): FastIOBase(f){}
#endif
	inline char getchar() { return __getc(); }
	template<typename ...T>
	inline void read(T &...x)
		{ initializer_list<int>{(this->operator>>(x),0)...}; }
	inline FastInput &operator >>(char &x)
		{ while(isspace(x=__getc()));return *this; }
	template<typename T,typename=typename enable_if<is_integral<T>::value>::type>
	inline FastInput &operator >>(T &x)
	{
		static char ch,sym;x=sym=0;
		while(isspace(ch=__getc()));
		if(ch=='-') sym=1,ch=__getc();
		for(;isdigit(ch);x=(x<<1)+(x<<3)+(ch^48),ch=__getc());
		return sym?x=-x:x,*this;
	}
	inline FastInput &operator >>(char *s)
	{
		while(isspace(*s=__getc()));
		for(;!isspace(*s) && *s && ~*s;*(++s)=__getc());
		return *s='\0',*this;
	}
	inline FastInput &operator >>(string &s)
	{
		char str_buf[(1<<8)+1],*p=str_buf;
		char *const buf_end=str_buf+(1<<8);
		while(isspace(*p=__getc()));
		for(s.clear(),p++;;p=str_buf)
		{
			for(;p!=buf_end && !isspace(*p=__getc()) && *p && ~*p;p++);
			*p='\0',s.append(str_buf);
			if(p!=buf_end) break;
		}
		return *this;
	}
}qin;

} // namespace FastIO
using namespace FastIO;

using LL=long long;
using LD=long double;
using UI=unsigned int;
using ULL=unsigned long long;

#ifndef DADALZY
#define FILEIO(file) freopen(file".in","r",stdin),freopen(file".out","w",stdout)
#else
#define FILEIO(file)
#endif

constexpr int B=15;
LL n,ans=4e18,sum,a[200005],pw[25];
vector<LL> vec[25];
inline LL f(LL x)
{
	int res=0;
	while(x) res+=x%10,x/=10;
	return res;
}
inline LL calc(LL x)
{
	LL res=0;
	for(int j=1;j<=B;j++)
	{
		LL lim=pw[j]-x%pw[j];
		auto it=lower_bound(vec[j].begin(),vec[j].end(),lim);
		res+=vec[j].end()-it;
	}
	return res;
}
int main()
{
	qin>>n,pw[0]=1;
	for(int i=1;i<=B;i++) pw[i]=pw[i-1]*10;
	for(int i=1;i<=n;i++) qin>>a[i],sum+=f(a[i]);
	for(int i=1;i<=n;i++) for(int j=1;j<=B;j++) vec[j].push_back(a[i]%pw[j]);
	for(int j=1;j<=B;j++) sort(vec[j].begin(),vec[j].end());
	ans=sum;
	for(int i=1;i<=n;i++) for(int j=1;j<=B;j++)
	{
		LL x=pw[j]-a[i]%pw[j];
		ans=min(ans,sum+f(x)*n-9*calc(x));
		assert(ans>=0);
	}
	qout<<ans;
	return 0;
}

提出情報

提出日時
問題 D - Sum of Sum of Digits
ユーザ balalida
言語 C++ (GCC 9.2.1)
得点 0
コード長 4256 Byte
結果 WA
実行時間 2940 ms
メモリ 28608 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 0 / 800
結果
AC × 4
AC × 25
WA × 29
セット名 テストケース
Sample 01_sample_01.txt, 01_sample_02.txt, 01_sample_03.txt, 01_sample_04.txt
All 01_sample_01.txt, 01_sample_02.txt, 01_sample_03.txt, 01_sample_04.txt, 02_small_1_01.txt, 02_small_1_02.txt, 02_small_1_03.txt, 02_small_1_04.txt, 02_small_1_05.txt, 02_small_1_06.txt, 02_small_1_07.txt, 02_small_1_08.txt, 02_small_1_09.txt, 02_small_1_10.txt, 03_small_2_01.txt, 03_small_2_02.txt, 03_small_2_03.txt, 03_small_2_04.txt, 03_small_2_05.txt, 03_small_2_06.txt, 03_small_2_07.txt, 03_small_2_08.txt, 03_small_2_09.txt, 03_small_2_10.txt, 04_max_rand_1_01.txt, 04_max_rand_1_02.txt, 04_max_rand_1_03.txt, 04_max_rand_1_04.txt, 04_max_rand_1_05.txt, 04_max_rand_1_06.txt, 04_max_rand_1_07.txt, 04_max_rand_1_08.txt, 04_max_rand_1_09.txt, 04_max_rand_1_10.txt, 05_max_rand_2_01.txt, 05_max_rand_2_02.txt, 05_max_rand_2_03.txt, 05_max_rand_2_04.txt, 05_max_rand_2_05.txt, 05_max_rand_2_06.txt, 05_max_rand_2_07.txt, 05_max_rand_2_08.txt, 05_max_rand_2_09.txt, 05_max_rand_2_10.txt, 06_max_rand_3_01.txt, 06_max_rand_3_02.txt, 06_max_rand_3_03.txt, 06_max_rand_3_04.txt, 06_max_rand_3_05.txt, 06_max_rand_3_06.txt, 06_max_rand_3_07.txt, 06_max_rand_3_08.txt, 06_max_rand_3_09.txt, 06_max_rand_3_10.txt
ケース名 結果 実行時間 メモリ
01_sample_01.txt AC 17 ms 3480 KiB
01_sample_02.txt AC 2 ms 3624 KiB
01_sample_03.txt AC 2 ms 3484 KiB
01_sample_04.txt AC 2 ms 3368 KiB
02_small_1_01.txt AC 15 ms 3724 KiB
02_small_1_02.txt WA 2 ms 3580 KiB
02_small_1_03.txt AC 12 ms 3712 KiB
02_small_1_04.txt AC 7 ms 3636 KiB
02_small_1_05.txt AC 9 ms 3692 KiB
02_small_1_06.txt AC 15 ms 3556 KiB
02_small_1_07.txt AC 11 ms 3764 KiB
02_small_1_08.txt AC 13 ms 3580 KiB
02_small_1_09.txt WA 9 ms 3504 KiB
02_small_1_10.txt AC 8 ms 3628 KiB
03_small_2_01.txt WA 9 ms 3704 KiB
03_small_2_02.txt WA 11 ms 3560 KiB
03_small_2_03.txt WA 13 ms 3712 KiB
03_small_2_04.txt WA 13 ms 3720 KiB
03_small_2_05.txt WA 11 ms 3716 KiB
03_small_2_06.txt WA 2 ms 3424 KiB
03_small_2_07.txt WA 11 ms 3720 KiB
03_small_2_08.txt WA 15 ms 3724 KiB
03_small_2_09.txt WA 12 ms 3708 KiB
03_small_2_10.txt WA 13 ms 3512 KiB
04_max_rand_1_01.txt AC 2544 ms 28480 KiB
04_max_rand_1_02.txt AC 2558 ms 28544 KiB
04_max_rand_1_03.txt AC 2567 ms 28548 KiB
04_max_rand_1_04.txt AC 2570 ms 28468 KiB
04_max_rand_1_05.txt AC 2560 ms 28548 KiB
04_max_rand_1_06.txt AC 2553 ms 28544 KiB
04_max_rand_1_07.txt AC 2536 ms 28552 KiB
04_max_rand_1_08.txt AC 2532 ms 28376 KiB
04_max_rand_1_09.txt AC 2538 ms 28540 KiB
04_max_rand_1_10.txt AC 2522 ms 28432 KiB
05_max_rand_2_01.txt WA 2936 ms 28516 KiB
05_max_rand_2_02.txt WA 2926 ms 28488 KiB
05_max_rand_2_03.txt AC 2918 ms 28476 KiB
05_max_rand_2_04.txt WA 2931 ms 28516 KiB
05_max_rand_2_05.txt WA 2923 ms 28376 KiB
05_max_rand_2_06.txt WA 2915 ms 28468 KiB
05_max_rand_2_07.txt AC 2922 ms 28544 KiB
05_max_rand_2_08.txt WA 2914 ms 28608 KiB
05_max_rand_2_09.txt WA 2926 ms 28468 KiB
05_max_rand_2_10.txt WA 2918 ms 28432 KiB
06_max_rand_3_01.txt AC 2938 ms 28432 KiB
06_max_rand_3_02.txt WA 2925 ms 28432 KiB
06_max_rand_3_03.txt WA 2923 ms 28484 KiB
06_max_rand_3_04.txt WA 2932 ms 28420 KiB
06_max_rand_3_05.txt WA 2940 ms 28476 KiB
06_max_rand_3_06.txt WA 2932 ms 28432 KiB
06_max_rand_3_07.txt WA 2928 ms 28476 KiB
06_max_rand_3_08.txt WA 2930 ms 28376 KiB
06_max_rand_3_09.txt WA 2933 ms 28380 KiB
06_max_rand_3_10.txt WA 2929 ms 28540 KiB