結果
問題 | No.2734 Addition and Multiplication in yukicoder (Hard) |
ユーザー |
![]() |
提出日時 | 2024-03-18 14:14:50 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 998 ms / 5,000 ms |
コード長 | 818 bytes |
コンパイル時間 | 1,289 ms |
コンパイル使用メモリ | 87,112 KB |
最終ジャッジ日時 | 2025-02-20 07:16:08 |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 36 |
ソースコード
#include <algorithm> #include <iostream> #include <string> #include <vector> using namespace std; using ll = long long; bool comp(string a, string b) { return a + b < b + a; } ll mod = 998244353; int main() { ll N; cin >> N; vector<ll> A(N); for (ll i = 0; i < N; i++) { cin >> A[i]; } vector<string> As(N); for (ll i = 0; i < N; i++) { As[i] = to_string(A[i]); } sort(As.begin(), As.end(), comp); vector<ll> pow_10(19); pow_10[0] = 1; for (ll i = 0; i < 18; i++) { pow_10[i + 1] = (pow_10[i] * 10LL) % mod; } ll ans = 0; for (ll i = 0; i < N; i++) { ll as_val = stoll(As[i]); ll len = As[i].size(); ans = (ans * pow_10[len]) % mod; ans = (ans + as_val % mod) % mod; } cout << ans << endl; }