結果

問題 No.2734 Addition and Multiplication in yukicoder (Hard)
ユーザー kaichou243kaichou243
提出日時 2024-04-19 21:39:13
言語 C++17(gcc12)
(gcc 12.3.0 + boost 1.87.0)
結果
AC  
実行時間 630 ms / 5,000 ms
コード長 750 bytes
コンパイル時間 2,623 ms
コンパイル使用メモリ 210,512 KB
実行使用メモリ 8,648 KB
最終ジャッジ日時 2024-10-11 14:24:23
合計ジャッジ時間 11,989 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 36
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using ll=long long;
void mpl(ll& x,ll y){
	x+=y;
	if(x>998244353) x-=998244353;
}
int digit(ll x){
	int ret=0;
	while(x) x/=10,ret++;
	return ret;
}
int main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int n;
	cin>>n;
	vector<ll> a(n);
	for(int i=0;i<n;i++) cin>>a[i];
	sort(a.begin(),a.end(),[](ll x,ll y)->bool{
		__int128_t X=x,Y=y;
		int dx=digit(x),dy=digit(y);
		for(int i=0;i<dy;i++) X*=10;
		for(int i=0;i<dx;i++) Y*=10;
		X+=y;
		Y+=x;
		return X<Y;
	});
	string s;
	for(int i=0;i<n;i++){
		string t=to_string(a[i]);
		s+=t;
	}
	reverse(s.begin(),s.end());
	ll ans=0,pw=1;
	for(int i=0;i<s.size();i++){
		mpl(ans,(pw*(s[i]-'0'))%998244353);
		pw=(pw*10)%998244353;
	}
	cout<<ans<<endl;
}
0