結果

問題 No.1630 Sorting Integers (Greater than K)
ユーザー akakimidoriakakimidori
提出日時 2021-07-30 21:13:59
言語 Rust
(1.77.0 + proconio)
結果
WA  
実行時間 -
コード長 3,218 bytes
コンパイル時間 16,073 ms
コンパイル使用メモリ 390,320 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-09-15 22:23:41
合計ジャッジ時間 15,976 ms
ジャッジサーバーID
(参考情報)
judge5 / judge6
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
testcase_26 RE -
権限があれば一括ダウンロードができます
コンパイルメッセージ
warning: unused import: `std::io::Write`
  --> src/main.rs:70:5
   |
70 | use std::io::Write;
   |     ^^^^^^^^^^^^^^
   |
   = note: `#[warn(unused_imports)]` on by default

warning: unused variable: `n`
   --> src/main.rs:103:9
    |
103 |         n: u64,
    |         ^
    |
help: `n` is captured in macro and introduced a unused variable
   --> src/main.rs:43:13
    |
43  |           let $var = read_value!($iter, $t);
    |               ^^^^
...
102 | /     input! {
103 | |         n: u64,
104 | |         c: [u64; 9],
105 | |     }
    | |_____- in this macro invocation
    = note: `#[warn(unused_variables)]` on by default
    = note: this warning originates in the macro `input_inner` which comes from the expansion of the macro `input` (in Nightly builds, run with -Z macro-backtrace for more info)

warning: type alias `Map` is never used
  --> src/main.rs:73:6
   |
73 | type Map<K, V> = BTreeMap<K, V>;
   |      ^^^
   |
   = note: `#[warn(dead_code)]` on by default

warning: type alias `Set` is never used
  --> src/main.rs:74:6
   |
74 | type Set<T> = BTreeSet<T>;
   |      ^^^

warning: type alias `Deque` is never used
  --> src/main.rs:75:6
   |
75 | type Deque<T> = VecDeque<T>;
   |      ^^^^^

ソースコード

diff #

// ---------- begin binary_gcd ----------
pub fn binary_gcd(a: u64, b: u64) -> u64 {
    if a == 0 || b == 0 {
        return a + b;
    }
    let x = a.trailing_zeros();
    let y = b.trailing_zeros();
    let mut a = a >> x;
    let mut b = b >> y;
    while a != b {
        let x = (a ^ b).trailing_zeros();
        if a < b {
            std::mem::swap(&mut a, &mut b);
        }
        a = (a - b) >> x;
    }
    a << x.min(y)
}
// ---------- end binary_gcd ----------
// ---------- begin input macro ----------
// reference: https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

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

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, bytes) => {
        read_value!($iter, String).bytes().collect::<Vec<u8>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}
// ---------- end input macro ----------

use std::io::Write;
use std::collections::*;

type Map<K, V> = BTreeMap<K, V>;
type Set<T> = BTreeSet<T>;
type Deque<T> = VecDeque<T>;

const MOD: u64 = 1_000_000_007;

fn calc(r: u64, n: u64, m: u64) -> u64 {
    if n == 1 {
        1 % m
    } else if n % 2 == 0 {
        (1 + r) * calc(r * r % m, n / 2, m) % m
    } else {
        (1 + r * calc(r, n - 1, m)) % m
    }
}

fn pow_mod(mut r: u64, mut n: u64, m: u64) -> u64 {
    let mut t = 1 % m;
    while n > 0 {
        if n & 1 == 1 {
            t = t * r % m;
        }
        r = r * r % m;
        n >>= 1;
    }
    t
}

fn run() {
    input! {
        n: u64,
        c: [u64; 9],
    }
    let mut g = 0;
    for (i, a) in c.iter().enumerate() {
        for (j, b) in c.iter().enumerate().take(i) {
            if *a > 0 && *b > 0 {
                g = binary_gcd(g, 9 * (i - j) as u64);
            }
        }
    }
    let ans = if g == 0 {
        let x = c.iter().position(|c| *c > 0).unwrap();
        (x + 1) as u64 * calc(10, c[x], MOD) % MOD
    } else {
        let mut val = 0;
        for (i, c) in c.iter().enumerate() {
            if *c > 0 {
                val = (val * pow_mod(10, *c, g) + calc(10, *c, g) * (i + 1) as u64) % g;
            }
        }
        binary_gcd(val, g)
    };
    println!("{}", ans);
}

fn main() {
    run();
}
0