結果

問題 No.2734 Addition and Multiplication in yukicoder (Hard)
ユーザー 矢澤式WINTER矢澤式WINTER
提出日時 2024-04-19 22:50:32
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,931 bytes
コンパイル時間 7,231 ms
コンパイル使用メモリ 337,080 KB
実行使用メモリ 32,896 KB
最終ジャッジ日時 2024-04-19 22:50:50
合計ジャッジ時間 12,792 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,248 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 TLE -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
//*/
#include <atcoder/all>
using namespace atcoder;
//*/
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=a;i<b;i++)
#define ALL(x) (x).begin(),(x).end()
#define dbgv(x); for(auto now : x) cout << now << " "; cout << endl;
//using P = pair<int,int>;
using ll = long long;
using ull = unsigned long long;
//*/
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<ll> vll;
typedef vector<int> vint;
random_device rnd;
mt19937 rng(rnd());
using mint = modint998244353;

void solve(){
  int n; cin >> n;
  mint ans = 0,ten = 10;
  vll a(n); rep(i,n) cin >> a[i];
  vector<string> s(n),t(n);
  rep(i,n){
    ll x = a[i];
    string now = "";
    while(x){
      char tar = '0'+ x%10;
      x /= 10;
      now = tar + now;
    }
    s[i] = now;
    for(char &c : now) if(c=='0') c -= 1;
    while(now.size() <= 18) now += '0';
    t[i] = now;
  }
  vint id(n); rep(i,n) id[i] = i;
  sort(ALL(id),[&](int i,int j){
    int zeroi = 20,zeroj = 20;
    rep(x,s[i].size()){
      if(s[i][x] == '0'){
        zeroi = x;
        break;
      }
    }
    rep(x,s[j].size()){
      if(s[j][x] == '0'){
        zeroj = x;
        break;
      }
    }
    rep(x,min(s.size(),t.size())){
      if(x < zeroi && x < zeroj && s[i][x] != s[j][x]) return s[i] < s[j];
    }
    if(zeroi != 20 && zeroj == 20) return true;
    if(zeroi == 20 && zeroj != 20) return false;
    if(zeroi < zeroj) return false;
    else if(zeroi > zeroj) return true;
    return t[i] < t[j];
  });
  rep(i,n){
    ans = ans*ten.pow(s[id[i]].size())+a[id[i]];
  }
  cout << ans.val() << endl;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int t = 1; //cin >> t;
  rep(dirc,t) solve();
}
0