結果

問題 No.528 10^9と10^9+7と回文
ユーザー snteasntea
提出日時 2017-09-14 18:36:55
言語 Rust
(1.77.0)
結果
AC  
実行時間 2 ms / 1,000 ms
コード長 5,827 bytes
コンパイル時間 695 ms
コンパイル使用メモリ 157,140 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-10-01 01:00:14
合計ジャッジ時間 1,899 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 2 ms
4,384 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 1 ms
4,376 KB
testcase_22 AC 1 ms
4,380 KB
testcase_23 AC 1 ms
4,380 KB
testcase_24 AC 1 ms
4,376 KB
testcase_25 AC 1 ms
4,380 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
warning: unused macro definition: `parse`
  --> Main.rs:19:14
   |
19 | macro_rules! parse {
   |              ^^^^^
   |
   = note: `#[warn(unused_macros)]` on by default

warning: unused macro definition: `rvec`
  --> Main.rs:44:14
   |
44 | macro_rules! rvec {
   |              ^^^^

warning: unused macro definition: `readlvec`
  --> Main.rs:50:14
   |
50 | macro_rules! readlvec {
   |              ^^^^^^^^

warning: unused macro definition: `debug`
  --> Main.rs:60:14
   |
60 | macro_rules! debug {
   |              ^^^^^

warning: function `printvec` is never used
  --> Main.rs:66:4
   |
66 | fn printvec<T>(v: &Vec<T>) where T: std::fmt::Display {
   |    ^^^^^^^^
   |
   = note: `#[warn(dead_code)]` on by default

warning: 5 warnings emitted

ソースコード

diff #

// use std::ops::{Index, IndexMut};
// use std::cmp::{Ordering, min, max};
// use std::collections::{BinaryHeap, BTreeMap};
// use std::collections::btree_map::Entry::{Occupied, Vacant};
// use std::clone::Clone;

fn getline() -> String{
    let mut res = String::new();
    std::io::stdin().read_line(&mut res).ok();
    res
}

macro_rules! split {
    ($x: expr) => {
        ($x).trim().split(' ').collect()
    }
}

macro_rules! parse {
    ($x: expr) => {
        ($x).parse().unwrap()
    }
}

macro_rules! readl {
    ($t: ty) => {
        {
            let s = getline();
            let iv: Vec<_> = split!(s);
            let mut iter = iv.into_iter();
            iter.next().unwrap().parse::<$t>().unwrap()
        }
    };
    ($( $t: ty),+ ) => {
        {
            let s = getline();
            let iv: Vec<_> = split!(s);
            let mut iter = iv.into_iter();
            ($(iter.next().unwrap().parse::<$t>().unwrap(),)*)
        }
    };
}

macro_rules! rvec {
    ($x: expr) => {
        ($x).into_iter().map(|x| parse!(x)).collect()
    }
}

macro_rules! readlvec {
    ($t: ty) => {
        {
            let s = getline();
            let iv: Vec<_> = split!(s);
            iv.into_iter().map(|x| x.parse().unwrap()).collect::<Vec<$t>>()
        }
    }
}

macro_rules! debug {
    ($x: expr) => {
        println!("{}: {}", stringify!($x), $x)
    }
}

fn printvec<T>(v: &Vec<T>) where T: std::fmt::Display {
    for (i,e) in v.into_iter().enumerate() {
        if i != 0 {
            print!(" ");
        }
        print!("{}", e);
    }
    println!("");
}

macro_rules! make_modint {
    ($MOD: expr, $name: ident) => {
        struct $name {
            val: i64,
        }

        impl $name {
            fn new(x: i64) -> $name {
                let x = x%$MOD;
                $name{val: if x < 0 { x+$MOD } else { x }}
            }

            fn pow(&self, x: i64) -> $name {
                let mut res = $name::new(1);
                let mut tmp = x;
                let mut p = *self;
                while tmp != 0 {
                    if tmp&1 == 1 {
                        res *= p;
                    }
                    tmp = tmp>>1;
                    p = p*p;
                }
                res
            }

            fn inv(&self) -> $name {
                assert!(self.val != 0);
                let mut a = self.val;
                let mut b = $MOD;
                let mut u = 1;
                let mut v = 0;
                use std::mem::swap;
                while b != 0 {
                    let t = a/b;
                    a -= t*b;
                    swap(&mut a, &mut b);
                    u -= t*v;
                    swap(&mut u, &mut v);
                }
                $name::new(u)
            }
        }

        impl std::clone::Clone for $name {
            fn clone(&self) -> $name {
                $name{ val: self.val }
            }
        }

        impl std::marker::Copy for $name { }

        impl std::ops::Add for $name {
            type Output = $name;
            fn add(self, y: $name) -> $name {
                let tmp = self.val+y.val;
                $name{val: if tmp >= $MOD {tmp-$MOD} else {tmp}}
            }
        }

        impl std::ops::Sub for $name {
            type Output = $name;
            fn sub(self, other: $name) -> $name{
                let tmp = self.val-other.val;
                $name{val: if tmp < 0 {tmp+$MOD} else {tmp}}
            }
        }

        impl std::ops::Mul for $name {
            type Output = $name;
            fn mul(self, y: $name) -> $name {
                $name{val: (self.val*y.val)%$MOD}
            }
        }

        impl std::ops::Div for $name {
            type Output = $name;
            fn div(self, other: $name) -> $name {
                self*other.inv()
            }
        }

        impl std::fmt::Display for $name {
            fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
                write!(f, "{}", self.val)
            }
        }

        impl std::ops::AddAssign for $name {
        fn add_assign(&mut self, other: $name) {
            *self = *self+other;
        }
        }

        impl std::ops::SubAssign for $name {
            fn sub_assign(&mut self, other: $name) {
                *self = *self-other;
            }
        }

        impl std::ops::MulAssign for $name {
            fn mul_assign(&mut self, other: $name) {
                *self = *self*other;
            }
        }

        impl std::ops::DivAssign for $name {
            fn div_assign(&mut self, other: $name) {
                *self = *self*other.inv();
            }
        }
    }
}

make_modint!(1000000007, ModInt);
make_modint!(1000000000, ModInt2);

macro_rules! solve {
    ($bv: expr, $ModInt: ident) => {{
        let n = $bv.len();
        let mut dp = $ModInt::new(0);
        for i in 0..(n+1)/2 {
            let num = $bv[i] - '0' as u8;
            if i == 0 {
                dp = $ModInt::new(num as i64-1) + dp*$ModInt::new(10);
            } else {
                dp = $ModInt::new(num as i64) + dp*$ModInt::new(10);
            }
        }
        let add = $ModInt::new(10).pow((n as i64)/2) + $ModInt::new(10).pow((n as i64-1)/2) - $ModInt::new(2);
        let mut f = 1;
        for i in 0..n/2 {
            let r = (n+1)/2+i;
            let l = n/2-1-i;
            if $bv[r] > $bv[l] {
                f = 1;
                break;
            } else if $bv[r] < $bv[l] {
                f = 0;
                break;
            }
        }
        dp + add + $ModInt::new(f)
    }}
}



fn main() {
    let s = readl!(String);
    let bv = s.into_bytes();
    let ans1 = solve!(bv, ModInt);
    let ans2 = solve!(bv, ModInt2);
    println!("{}", ans2);
    println!("{}", ans1);
}
0