結果

問題 No.435 占い(Extra)
ユーザー titiatitia
提出日時 2023-04-26 02:51:11
言語 Rust
(1.77.0)
結果
AC  
実行時間 297 ms / 2,000 ms
コード長 1,938 bytes
コンパイル時間 13,448 ms
コンパイル使用メモリ 389,512 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-27 10:20:12
合計ジャッジ時間 16,919 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,812 KB
testcase_01 AC 1 ms
6,940 KB
testcase_02 AC 1 ms
6,940 KB
testcase_03 AC 1 ms
6,944 KB
testcase_04 AC 0 ms
6,940 KB
testcase_05 AC 1 ms
6,944 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 1 ms
6,944 KB
testcase_08 AC 1 ms
6,940 KB
testcase_09 AC 2 ms
6,944 KB
testcase_10 AC 2 ms
6,940 KB
testcase_11 AC 2 ms
6,940 KB
testcase_12 AC 15 ms
6,940 KB
testcase_13 AC 14 ms
6,940 KB
testcase_14 AC 14 ms
6,944 KB
testcase_15 AC 16 ms
6,940 KB
testcase_16 AC 31 ms
6,944 KB
testcase_17 AC 178 ms
6,940 KB
testcase_18 AC 14 ms
6,948 KB
testcase_19 AC 14 ms
6,944 KB
testcase_20 AC 132 ms
6,944 KB
testcase_21 AC 134 ms
6,944 KB
testcase_22 AC 133 ms
6,944 KB
testcase_23 AC 134 ms
6,940 KB
testcase_24 AC 150 ms
6,944 KB
testcase_25 AC 297 ms
6,940 KB
testcase_26 AC 132 ms
6,944 KB
testcase_27 AC 136 ms
6,940 KB
testcase_28 AC 1 ms
6,944 KB
testcase_29 AC 134 ms
6,940 KB
testcase_30 AC 134 ms
6,940 KB
testcase_31 AC 109 ms
6,940 KB
testcase_32 AC 117 ms
6,944 KB
testcase_33 AC 142 ms
6,940 KB
testcase_34 AC 205 ms
6,944 KB
testcase_35 AC 134 ms
6,944 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
warning: unnecessary parentheses around `while` condition
  --> src/main.rs:51:19
   |
51 |             while (x%3==0){
   |                   ^      ^
   |
   = note: `#[warn(unused_parens)]` on by default
help: remove these parentheses
   |
51 -             while (x%3==0){
51 +             while x%3==0 {
   |

warning: unnecessary parentheses around `while` condition
  --> src/main.rs:60:19
   |
60 |             while (x%3==0){
   |                   ^      ^
   |
help: remove these parentheses
   |
60 -             while (x%3==0){
60 +             while x%3==0 {
   |

warning: unused variable: `tests`
  --> src/main.rs:10:9
   |
10 |     for tests in 0..t{
   |         ^^^^^ help: if this is intentional, prefix it with an underscore: `_tests`
   |
   = note: `#[warn(unused_variables)]` on by default

warning: variable `INV` should have a snake case name
 --> src/main.rs:8:9
  |
8 |     let INV=vec![0,1,5,0,7,2,0,4,8];
  |         ^^^ help: convert the identifier to snake case: `inv`
  |
  = note: `#[warn(non_snake_case)]` on by default

ソースコード

diff #

fn main() {
    let t: usize = {
        let mut line: String = String::new();
        std::io::stdin().read_line(&mut line).unwrap();
        line.trim().parse().unwrap()
    };

    let INV=vec![0,1,5,0,7,2,0,4,8];

    for tests in 0..t{
        let (n,x,a,b,m): (usize, i32,  i32,  i32, i32) = {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                iter.next().unwrap().parse().unwrap(),
                iter.next().unwrap().parse().unwrap(),
                iter.next().unwrap().parse().unwrap(),
                iter.next().unwrap().parse().unwrap(),
                iter.next().unwrap().parse().unwrap()
            )
        };

        let mut now=x;
        let mut flag0=0;
        if now%10==0{
            flag0=1;
        }
        let mut ans=0;
        let mut two: i32=1;
        let mut three=0;

        for i in 0..n{
            if i==0{
                ans=(ans+now%10)%9;
                continue;
            }

            now=((now^a)+b)%m;

            if (now%10)!=0{
                flag0=0;
            }

            if i==n-1{
                ans=(ans+now%10)%9;
                continue;
            }

            let mut x:i32=i as i32;
            while (x%3==0){
                x/=3;
                three-=1;
            }

            two=two*INV[(x%9) as usize]%9;

            x=(n-i) as i32;

            while (x%3==0){
                x/=3;
                three+=1;
            }

            two=two*x%9;

            if three==0{
                ans=(ans+(now%10)*two)%9;
            }
            else if three==1{
                ans=(ans+(now%10)*two*3)%9;
            }
        }

        if flag0==1{
            println!("0");
            continue;
        }

        if ans==0{
            ans=9;
        }
        println!("{}", ans);
    }
}
0