結果

問題 No.2734 Addition and Multiplication in yukicoder (Hard)
ユーザー butsurizuki
提出日時 2024-04-19 21:38:41
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 1,040 ms / 5,000 ms
コード長 642 bytes
コンパイル時間 3,884 ms
コンパイル使用メモリ 252,892 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-10-11 14:24:07
合計ジャッジ時間 19,196 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 36
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#define mod 998244353

using namespace std;

bool comp(const long long a,const long long b){
  string sa=to_string(a);
  string sb=to_string(b);
  string ab=sa+sb;
  string ba=sb+sa;
  return (ab<ba);
}

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  vector<long long> p10(20);
  p10[0]=1;
  for(int i=1;i<20;i++){
    p10[i]=(p10[i-1]*10)%mod;
  }

  int n;
  cin >> n;
  vector<long long> a(n);
  for(auto &nx : a){cin >> nx;}
  sort(a.begin(),a.end(),comp);
  long long x=0;
  for(auto &nx : a){
    x*=p10[to_string(nx).size()]; x%=mod;
    x+=nx; x%=mod;
  }
  cout << x << "\n";
  return 0;
}
0