結果
問題 | No.2734 Addition and Multiplication in yukicoder (Hard) |
ユーザー |
|
提出日時 | 2024-04-19 22:50:32 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,931 bytes |
コンパイル時間 | 5,608 ms |
コンパイル使用メモリ | 316,744 KB |
実行使用メモリ | 32,896 KB |
最終ジャッジ日時 | 2024-10-11 16:44:41 |
合計ジャッジ時間 | 13,047 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 1 WA * 13 TLE * 1 -- * 21 |
ソースコード
#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();}