結果

問題 No.983 Convolution
ユーザー akakimidoriakakimidori
提出日時 2020-02-11 13:50:11
言語 Rust
(1.77.0)
結果
WA  
実行時間 -
コード長 1,098 bytes
コンパイル時間 1,724 ms
コンパイル使用メモリ 180,920 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-04-08 14:47:27
合計ジャッジ時間 2,185 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,548 KB
testcase_01 AC 1 ms
6,548 KB
testcase_02 AC 1 ms
6,548 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 7 ms
6,548 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 23 ms
6,548 KB
testcase_18 AC 4 ms
6,548 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 16 ms
6,548 KB
testcase_22 AC 4 ms
6,548 KB
testcase_23 AC 10 ms
6,548 KB
testcase_24 AC 3 ms
6,548 KB
testcase_25 AC 3 ms
6,548 KB
testcase_26 AC 9 ms
6,548 KB
testcase_27 AC 5 ms
6,548 KB
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 AC 0 ms
6,548 KB
testcase_34 AC 0 ms
6,548 KB
testcase_35 AC 1 ms
6,548 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

use std::io::Read;

fn gcd(a: i64, b: i64) -> i64 {
    if b == 0 {
        a
    } else {
        gcd(b, a % b)
    }
}

fn run() {
    let mut s = String::new();
    std::io::stdin().read_to_string(&mut s).unwrap();
    let mut it = s.trim().split_whitespace();
    let n: usize = it.next().unwrap().parse().unwrap();
    let n = n.next_power_of_two();
    let m = n.trailing_zeros() as usize;
    let mut a = vec![0i64; n];
    for (i, s) in it.enumerate() {
        let k: i64 = s.parse().unwrap();
        if k >= 0 {
            a[i] = k;
        }
    }
    for i in 0..m {
        for j in 0..n {
            if (j >> i) & 1 == 1 {
                a[j ^ (1 << i)] += a[j];
            }
        }
    }
    for i in 0..n {
        a[i] *= a[i];
    }
    for i in 0..m {
        for j in 0..n {
            if (j >> i) & 1 == 1 {
                a[j ^ (1 << i)] -= a[j];
            }
        }
    }
    let mut ans = 0;
    for a in a {
        ans = gcd(ans, a);
    }
    if ans == 0 {
        println!("-1");
    } else {
        println!("{}", ans);
    }
}

fn main() {
    run();
}
0