結果

問題 No.2734 Addition and Multiplication in yukicoder (Hard)
ユーザー koba-e964koba-e964
提出日時 2024-04-19 23:27:44
言語 Rust
(1.77.0)
結果
AC  
実行時間 851 ms / 5,000 ms
コード長 1,634 bytes
コンパイル時間 8,424 ms
コンパイル使用メモリ 153,232 KB
実行使用メモリ 29,872 KB
最終ジャッジ日時 2024-04-19 23:28:08
合計ジャッジ時間 19,686 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 0 ms
5,248 KB
testcase_01 AC 1 ms
5,248 KB
testcase_02 AC 1 ms
5,248 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 1 ms
5,376 KB
testcase_09 AC 0 ms
5,376 KB
testcase_10 AC 0 ms
5,376 KB
testcase_11 AC 1 ms
5,376 KB
testcase_12 AC 1 ms
5,376 KB
testcase_13 AC 1 ms
5,376 KB
testcase_14 AC 1 ms
5,376 KB
testcase_15 AC 0 ms
5,376 KB
testcase_16 AC 1 ms
5,376 KB
testcase_17 AC 605 ms
17,708 KB
testcase_18 AC 609 ms
17,920 KB
testcase_19 AC 1 ms
6,944 KB
testcase_20 AC 1 ms
6,940 KB
testcase_21 AC 1 ms
6,940 KB
testcase_22 AC 790 ms
29,700 KB
testcase_23 AC 808 ms
29,820 KB
testcase_24 AC 830 ms
29,872 KB
testcase_25 AC 832 ms
29,748 KB
testcase_26 AC 833 ms
29,700 KB
testcase_27 AC 744 ms
26,000 KB
testcase_28 AC 783 ms
28,612 KB
testcase_29 AC 776 ms
28,340 KB
testcase_30 AC 741 ms
23,292 KB
testcase_31 AC 851 ms
29,308 KB
testcase_32 AC 826 ms
26,520 KB
testcase_33 AC 560 ms
17,392 KB
testcase_34 AC 648 ms
22,068 KB
testcase_35 AC 359 ms
11,392 KB
testcase_36 AC 359 ms
11,904 KB
testcase_37 AC 531 ms
19,696 KB
testcase_38 AC 516 ms
18,324 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes.by_ref().map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr,) => {};
    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };
    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };
    ($next:expr, $t:ty) => ($next().parse::<$t>().expect("Parse error"));
}

const MOD: i64 = 998_244_353;

// https://yukicoder.me/problems/no/2734 (3)
// Tags: lexicographically-smallest-concatenation
fn main() {
    input! {
        n: usize,
        a: [chars; n],
    }
    let mut a = a;
    a.sort_by(|s, t| {
        let mut ss = s.clone();
        let mut tt = t.clone();
        ss.extend_from_slice(t);
        tt.extend_from_slice(s);
        ss.cmp(&tt)
    });
    let mut ans = 0;
    for s in a {
        for &c in &s {
            let dig = (c as u8 - b'0') as i64;
            ans = (ans * 10 + dig) % MOD;
        }
    }
    println!("{}", ans);
}
0